better placement of the comment tutorial
[fnpeditor.git] / src / editor / modules / data / data.js
index 0d556a2..0c3b23f 100644 (file)
@@ -127,6 +127,7 @@ return function(sandbox) {
     return {
         start: function() {
             var text;
     return {
         start: function() {
             var text;
+            $('#tuton').remove();
             if(window.localStorage) {
                 text = window.localStorage.getItem(getLocalStorageKey(data.version).content);
 
             if(window.localStorage) {
                 text = window.localStorage.getItem(getLocalStorageKey(data.version).content);
 
@@ -179,6 +180,12 @@ return function(sandbox) {
                     executeButtonText: gettext('Save'),
                     cancelButtonText: gettext('Cancel')
                 });
                     executeButtonText: gettext('Save'),
                     cancelButtonText: gettext('Cancel')
                 });
+            /* Set stage field initial value to current document stage. */
+            for (var i in documentSaveForm.fields) {
+                if (documentSaveForm.fields[i].name == 'textsave-stage') {
+                    documentSaveForm.fields[i].initialValue = data.stage;
+                }
+            }
             
             dialog.on('execute', function(event) {
                 sandbox.publish('savingStarted', 'remote');
             
             dialog.on('execute', function(event) {
                 sandbox.publish('savingStarted', 'remote');
@@ -195,21 +202,35 @@ return function(sandbox) {
                     method: 'post',
                     url: sandbox.getConfig().documentSaveUrl(data.document_id),
                     data: formData,
                     method: 'post',
                     url: sandbox.getConfig().documentSaveUrl(data.document_id),
                     data: formData,
-                    success: function(data) {
+                    success: function(ajax_data) {
                         event.success();
                         event.success();
-                        sandbox.publish('savingEnded', 'success', 'remote', data);
+                        sandbox.publish('savingEnded', 'success', 'remote', ajax_data);
 
 
-                        Object.keys(data)
+                        Object.keys(ajax_data)
                             .filter(function(key) {
                                 return key !== 'text';
                             })
                             .forEach(function(key) {
                             .filter(function(key) {
                                 return key !== 'text';
                             })
                             .forEach(function(key) {
-                                wlxmlDocument.setProperty(key, data[key]);
+                                wlxmlDocument.setProperty(key, ajax_data[key]);
+                                // ugly, but whatever
+                                data[key] = ajax_data[key];
                             });
 
                         reloadHistory();
                     },
                             });
 
                         reloadHistory();
                     },
-                    error: function() {event.error(); sandbox.publish('savingEnded', 'error', 'remote');}
+                    error: function(data) {
+                        event.error();
+                        sandbox.publish('savingEnded', 'error', 'remote');
+                        var dialog = Dialog.create({
+                            title: gettext('Error'),
+                            text: JSON.parse(data.responseText).text.join('\n'),
+                            executeButtonText: gettext('Close')
+                        });
+                        dialog.show();
+                        dialog.on('execute', function(e) {
+                            e.success();
+                        });
+                    }
                 });
             });
             dialog.on('cancel', function() {
                 });
             });
             dialog.on('cancel', function() {
@@ -257,18 +278,56 @@ return function(sandbox) {
                     dataType: 'json',
                     url: sandbox.getConfig().documentRestoreUrl(data.document_id),
                     data: formData,
                     dataType: 'json',
                     url: sandbox.getConfig().documentRestoreUrl(data.document_id),
                     data: formData,
-                    success: function(data) {
-                        Object.keys(data)
+                    success: function(ajax_data) {
+                        Object.keys(ajax_data)
                             .filter(function(key) {
                                 return key !== 'document';
                             })
                             .forEach(function(key) {
                             .filter(function(key) {
                                 return key !== 'document';
                             })
                             .forEach(function(key) {
-                                wlxmlDocument.setProperty(key, data[key]);
+                                wlxmlDocument.setProperty(key, ajax_data[key]);
+                                // ugly, but whatever
+                                data[key] = ajax_data[key];
                             });
                         reloadHistory();
                             });
                         reloadHistory();
-                        wlxmlDocument.loadXML(data.document);
+                        wlxmlDocument.loadXML(ajax_data.document);
                         documentDirty = false;
                         documentDirty = false;
-                        sandbox.publish('documentReverted', data.version);
+                        sandbox.publish('documentReverted', ajax_data.version);
+                        event.success();
+                    },
+                });
+            });
+            dialog.show();
+        },
+        publishVersion: function(revision) {
+            var documentPublishForm = $.extend({
+                        fields: [],
+                        revision_field_name: 'revision'
+                    },
+                    sandbox.getConfig().documentPublishForm
+                ),
+                dialog = Dialog.create({
+                    fields: documentPublishForm.fields,
+                    title: gettext('Publish'),
+                    executeButtonText: gettext('Publish'),
+                    cancelButtonText: gettext('Cancel')
+                });
+
+            dialog.on('execute', function(event) {
+                var formData = event.formData;
+                formData[documentPublishForm.revision_field_name] = revision;
+                sandbox.publish('publishingStarted', {version: revision});
+                if(sandbox.getConfig().jsonifySentData) {
+                    formData = JSON.stringify(formData);
+                }
+                $.ajax({
+                    method: 'post',
+                    //dataType: 'json',
+                    dataType: 'text',
+                    url: sandbox.getConfig().documentPublishUrl,
+                    data: formData,
+                    success: function(data) {
+                        reloadHistory();
+                        sandbox.publish('documentPublished');
                         event.success();
                     },
                 });
                         event.success();
                     },
                 });
@@ -285,4 +344,4 @@ return function(sandbox) {
     };
 };
 
     };
 };
 
-});
\ No newline at end of file
+});