forked from ezsystems/ezautosave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
133 lines (105 loc) · 4.36 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
About eZ Autosave
=================
Project page: http://projects.ez.no/ezautosave
Roadmap feature request:
http://share.ez.no/feature-requests/auto-store-draft-feature
eZ Autosave enables the automatic and transparent saving of the draft
while editing a content in eZ Publish. Based on this, it also provides
an "inline" preview from the content edit in the administration
interface.
This extension is based on QH Autosave by Quoc-Huy NGUYEN DINH
Features
========
- Regularly save the draft (interval defined in
autosave.ini/[AutosaveSettings]/Interval)
- Save the draft when the user leaves a form field (enable/disable
through autosave.ini/[AutosaveSettings]/TrackUserInput)
- Hide the "Store draft" button (enable/disable through
autosave.ini/[AutosaveSettings]/HideStoreDraftButton)
- Try to save the draft if the editor unexpectedly quits the content
edit page (back button, close browser, ...)
Requirements
============
- eZ Publish 2012.01 or 4.7 or newer
- ezjscore
TODO / Known issues
===================
- Add timeout support as soon as the YUI3 bug #2531308 is fixed
http://yuilibrary.com/projects/yui3/ticket/2531308
- When timeout is implemented, add a Retry button in case of timeout
- Use the output of the ezjscore action to update the content edit form:
for instance, after uploading an image, the preview could be updated
or the unvalidated field could be hightlighted.
- Let the editor disable/enable the autosave process
- Let the editor choose the interval between two autosave attempts
Technical notes
===============
This extension provides a JavaScript component called Y.eZ.AutoSubmit.
It's the main part of the extension, it allows to automatically submit a
form at fixed interval or because the user has changed something.
This component extends the EventTarget YUI3 component and then triggers
some events during its life. The available events are (see example below
for details):
- init
- beforesave
- success
- error
- nochange
- abort
It also listens for the event 'autosubmit:forcesave'. When this events
is fired, the Y.eZ.AutoSubmit component will try to submit the form no
matter if its state has changed or not.
Example:
{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
}
as.on('init', function () {
// init event
// triggered when the component is initialized
// "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>