ezsystems / ezautosave-ls

eZ Publish旧版内容编辑自动保存扩展

安装量:413,110

依赖者: 4

建议者: 1

安全: 0

星标: 22

关注者: 32

分支: 16

语言:JavaScript

类型:eZ Publish旧版扩展

v5.4.4 2019-02-18 13:59 UTC

README

项目页面: http://projects.ez.no/ezautosave 路线图特性请求: http://share.ez.no/feature-requests/auto-store-draft-feature

eZ Autosave 允许在编辑eZ Publish内容时自动且透明地保存草稿。基于此,它还在管理界面中提供从内容编辑的“内联”预览。

此扩展基于Quoc-Huy NGUYEN DINH的QH Autosave

特性

  • 定期保存草稿(间隔由autosave.ini/[AutosaveSettings]/Interval定义)
  • 当用户离开表单字段时保存草稿(通过autosave.ini/[AutosaveSettings]/TrackUserInput启用/禁用)
  • 隐藏“存储草稿”按钮(通过autosave.ini/[AutosaveSettings]/HideStoreDraftButton启用/禁用)
  • 如果编辑器意外退出内容编辑页面(后退按钮、关闭浏览器等),则尝试保存草稿

要求

  • eZ Publish 2012.01或4.7或更高版本
  • ezjscore

待办事项/已知问题

  • 在YUI3错误#2531308修复后立即添加超时支持 http://yuilibrary.com/projects/yui3/ticket/2531308
  • 实现超时后,在超时情况下添加重试按钮
  • 使用ezjscore动作的输出更新内容编辑表单:例如,在上传图片后,预览可能被更新或未验证的字段可能被突出显示。
  • 允许编辑器禁用/启用自动保存过程
  • 允许编辑器选择两次自动保存尝试之间的间隔

技术备注

此扩展提供了一个名为Y.eZ.AutoSubmit的JavaScript组件。它是扩展的主要部分,允许在固定间隔或因为用户有所更改时自动提交表单。

该组件扩展了YUI3的EventTarget组件,并在其生命周期中触发一些事件。可用的事件有(以下面的示例为详细信息)

  • init
  • beforesave
  • success
  • error
  • nochange
  • abort

它还监听事件“autosubmit:forcesave”。当此事件被触发时,Y.eZ.AutoSubmit组件将尝试提交表单,无论其状态是否已更改。

示例

{ezscript_require( array( 'ezjsc::yui3', 'ezautosubmit.js' ) )}
<script type="text/javascript">

YUI(YUI3_config).use('ezautosubmit', function (Y) {

    var as = new Y.eZ.AutoSubmit({
        form: '#selectorToTheForm',
        ignoreClass: 'no-autosave', // change in form fields with this class
                                    // will not trigger an auto submit
        action: 'url/to/post/the/form/content', // should answer in JSON
        interval: 30, // number of seconds between two submit attempts
        trackUserInput: true, // boolean, whether the component should try to
                              // submit the form if the user leaves a field
                              // and has made changes
        enabled: function () { return true; } // optional function to
                                              // disable autosave in some circumstances
        });

    as.on('init', function () {
        // init event
        // triggered when the component is initialized
        // if the `enabled` function returns false, this event is not
        // triggered
        // "this" is the Y.eZ.AutoSubmit instance
    });

    as.on('beforesave', function () {
        // beforesave event
        // triggered right before the form is automatically submitted
        // "this" is the Y.eZ.AutoSubmit instance
    });

    as.on('sucess', function (e) {
        // success event
        // triggered if the form was correctly submitted
        // e.json contains the server response in JSON
        // "this" is the Y.eZ.AutoSubmit instance
    });

    as.on('error', function (e) {
        // error event
        // triggered if the form was not correctly submitted
        // e.json contains the server response in JSON if the
        // server response was JSON valid
        // "this" is the Y.eZ.AutoSubmit instance
    });

    as.on('nochange', function () {
        // nochange event
        // triggered if the component tries to submit the form but no
        // change has occurred since the last submit
        // "this" is the Y.eZ.AutoSubmit instance
    });

    as.on('abort', function () {
        // abort event
        // triggered if the component tried to submit the form but the
        // request is aborted for instance because of a call to stop()
        // "this" is the Y.eZ.AutoSubmit instance
    });

    // from anywhere in the application, the following line will make
    // the Y.eZ.AutoSubmit component to submit the form
    Y.fire('autosubmit:forcesave');

});
</script>