From e68778f27b18c21c23387d7609d825ab3a192af7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 17 Dec 2013 17:09:51 +0100 Subject: [PATCH 1/1] editor: bring back restore dialog after integration Both save and restore dialog are now handled by more generalized dialog object, based on previous dialog object implementation. --- src/editor/modules/data/data.js | 45 ++++++++++---- src/editor/modules/data/data.less | 2 +- .../data/{saveDialog.html => dialog.html} | 6 +- .../modules/data/{saveDialog.js => dialog.js} | 4 +- .../data/{saveDialog.less => dialog.less} | 2 +- .../documentHistory/documentHistory.js | 10 +--- .../modules/documentHistory/restoreDialog.js | 58 ------------------- .../templates/restoreDialog.html | 14 ----- src/editor/modules/rng/rng.js | 10 ++-- 9 files changed, 48 insertions(+), 103 deletions(-) rename src/editor/modules/data/{saveDialog.html => dialog.html} (60%) rename src/editor/modules/data/{saveDialog.js => dialog.js} (95%) rename src/editor/modules/data/{saveDialog.less => dialog.less} (91%) delete mode 100644 src/editor/modules/documentHistory/restoreDialog.js delete mode 100644 src/editor/modules/documentHistory/templates/restoreDialog.html diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index bce9582..4a9bc72 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -1,12 +1,12 @@ define([ 'libs/jquery', - './saveDialog', + './dialog', 'wlxml/wlxml', 'wlxml/extensions/list/list' - -], function($, saveDialog, wlxml, listExtension) { +], function($, Dialog, wlxml, listExtension) { 'use strict'; +/* global gettext */ return function(sandbox) { @@ -75,7 +75,11 @@ return function(sandbox) { }, sandbox.getConfig().documentSaveForm ), - dialog = saveDialog.create({fields: documentSaveForm.fields}); + dialog = Dialog.create({ + fields: documentSaveForm.fields, + title: gettext('Save Document'), + submitButtonText: gettext('Save') + }); dialog.on('save', function(event) { sandbox.publish('savingStarted'); @@ -120,22 +124,41 @@ return function(sandbox) { }, }); }, - restoreVersion: function(options) { - if(options.version && options.description) { - sandbox.publish('restoringStarted', {version: options.version}); + restoreVersion: function(version) { + var documentRestoreForm = $.extend({ + fields: [], + version_field_name: 'version' + }, + sandbox.getConfig().documentRestoreForm + ), + dialog = Dialog.create({ + fields: documentRestoreForm.fields, + title: gettext('Restore Version'), + submitButtonText: gettext('Restore') + }); + + dialog.on('save', function(event) { + var formData = event.formData; + formData[documentRestoreForm.version_field_name] = version; + sandbox.publish('restoringStarted', {version: version}); + if(sandbox.getConfig().jsonifySentData) { + formData = JSON.stringify(formData); + } $.ajax({ method: 'post', dataType: 'json', url: sandbox.getConfig().documentRestoreUrl(document_id), - data: JSON.stringify(options), + data: formData, success: function(data) { - document_version = data.current_version; + document_version = data.version; reloadHistory(); wlxmlDocument.loadXML(data.document); - sandbox.publish('documentReverted', data); + sandbox.publish('documentReverted', data.version); + event.success(); }, }); - } + }); + dialog.show(); }, getDocumentId: function() { return document_id; diff --git a/src/editor/modules/data/data.less b/src/editor/modules/data/data.less index 1beb090..2a21630 100644 --- a/src/editor/modules/data/data.less +++ b/src/editor/modules/data/data.less @@ -1 +1 @@ -@import 'saveDialog.less'; \ No newline at end of file +@import 'dialog.less'; \ No newline at end of file diff --git a/src/editor/modules/data/saveDialog.html b/src/editor/modules/data/dialog.html similarity index 60% rename from src/editor/modules/data/saveDialog.html rename to src/editor/modules/data/dialog.html index d0238e0..844a6ff 100644 --- a/src/editor/modules/data/saveDialog.html +++ b/src/editor/modules/data/dialog.html @@ -1,12 +1,12 @@ -