se7enxweb/ezautosave-ls

eZ Publish 传统版本的内容编辑自动保存扩展

安装: 65

依赖: 0

建议: 0

安全: 0

星标: 1

关注者: 0

分支: 16

开放问题: 0

语言:JavaScript

类型:ezpublish-legacy-extension

v6.0.0 2024-01-29 04:10 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 bug #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>