From: Aleksander Ɓukasz Date: Thu, 13 Jun 2013 12:43:10 +0000 (+0200) Subject: Saving dialog, storing change description X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/5fa477181f00d867a51d9f6e4fb1915522d725f5?ds=inline;hp=2a66af7ee0ee2d9943f58db45417b78764a43483 Saving dialog, storing change description --- diff --git a/modules/data.js b/modules/data.js index 33c8df6..9e18512 100644 --- a/modules/data.js +++ b/modules/data.js @@ -1,4 +1,4 @@ -define(function() { +define(['./data/saveDialog'], function(saveDialog) { 'use strict'; @@ -66,14 +66,29 @@ return function(sandbox) { sandbox.publish('documentChanged', doc, reason); }, saveDocument: function() { - sandbox.publish('savingStarted'); - $.ajax({ - method: 'post', - url: '/' + gettext('editor') + '/' + document_id, - data: JSON.stringify({document:doc}), - success: function() {sandbox.publish('savingEnded', 'success'); reloadHistory();}, - error: function() {sandbox.publish('savingEnded', 'error');} + + var dialog = saveDialog.create(); + dialog.on('save', function(event) { + sandbox.publish('savingStarted'); + dialog.toggleButtons(false); + $.ajax({ + method: 'post', + url: '/' + gettext('editor') + '/' + document_id, + data: JSON.stringify({document:doc, description: event.data.description}), + success: function() { + event.success(); + sandbox.publish('savingEnded', 'success'); + reloadHistory(); + }, + error: function() {event.error(); sandbox.publish('savingEnded', 'error');} + }); + console.log('save'); + }); + dialog.on('cancel', function() { }); + dialog.show(); + + }, getHistory: function() { return history; diff --git a/modules/data/data.less b/modules/data/data.less new file mode 100644 index 0000000..1beb090 --- /dev/null +++ b/modules/data/data.less @@ -0,0 +1 @@ +@import 'saveDialog.less'; \ No newline at end of file diff --git a/modules/data/saveDialog.html b/modules/data/saveDialog.html new file mode 100644 index 0000000..496d886 --- /dev/null +++ b/modules/data/saveDialog.html @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/modules/data/saveDialog.js b/modules/data/saveDialog.js new file mode 100644 index 0000000..a772ba6 --- /dev/null +++ b/modules/data/saveDialog.js @@ -0,0 +1,54 @@ +define([ +'libs/text!./saveDialog.html', +'libs/underscore-min', +'libs/backbone-min', +'libs/jquery-1.9.1.min' +], function(saveDialogTemplate, _, Backbone, $) { + + var DialogView = Backbone.View.extend({ + template: _.template(saveDialogTemplate), + events: { + 'click .save-btn': 'onSave', + 'click .cancel-btn': 'close', + 'click .close': 'close' + }, + initialize: function() { + _.bindAll(this); + this.actionsDisabled = false; + }, + show: function() { + this.setElement(this.template()); + this.$el.modal({backdrop: 'static'}); + this.$el.modal('show'); + + }, + onSave: function(e) { + e.preventDefault(); + var view = this; + this.trigger('save', { + data: {description: view.$el.find('textarea').val()}, + success: function() { view.actionsDisabled = false; view.close(); }, + error: function() { view.actionsDisabled = false; view.close(); }, + }) + }, + close: function(e) { + if(e) + e.preventDefault(); + if(!this.actionsDisabled) { + this.$el.modal('hide'); + this.$el.remove(); + } + }, + toggleButtons: function(toggle) { + this.$('.btn, button').toggleClass('disabled', !toggle); + this.actionsDisabled = !toggle; + } + }); + + return { + create: function() { + return new DialogView(); + } + } + +}); \ No newline at end of file diff --git a/modules/data/saveDialog.less b/modules/data/saveDialog.less new file mode 100644 index 0000000..53c7d47 --- /dev/null +++ b/modules/data/saveDialog.less @@ -0,0 +1,19 @@ +.rng-module-data-saveDialog { + textarea { + padding: 3px 3px; + margin: 5px auto; + width: 95%; + display: block; + } + + h1, label { + font-size: 12px; + line-height: 12px; + + } + + h1 { + margin: 2px 5px; + font-weight: bold; + } +} \ No newline at end of file diff --git a/styles/main.less b/styles/main.less index 8a6dd79..3897bdd 100644 --- a/styles/main.less +++ b/styles/main.less @@ -1,6 +1,7 @@ @import 'mixins.less'; @import 'common.less'; +@import '../modules/data/data.less'; @import '../modules/rng/rng.less'; @import '../modules/documentCanvas/documentCanvas.less'; @import '../modules/sourceEditor/sourceEditor.less';