se7enxweb / ezautosave
eZ Publish旧版本内容编辑自动保存扩展
v6.0.0
2024-01-29 04:10 UTC
Requires
This package is auto-updated.
Last update: 2024-08-29 05:44:39 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>