From 5fa477181f00d867a51d9f6e4fb1915522d725f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 13 Jun 2013 14:43:10 +0200 Subject: [PATCH 1/1] Saving dialog, storing change description --- modules/data.js | 31 +++++++++++++++------ modules/data/data.less | 1 + modules/data/saveDialog.html | 14 ++++++++++ modules/data/saveDialog.js | 54 ++++++++++++++++++++++++++++++++++++ modules/data/saveDialog.less | 19 +++++++++++++ styles/main.less | 1 + 6 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 modules/data/data.less create mode 100644 modules/data/saveDialog.html create mode 100644 modules/data/saveDialog.js create mode 100644 modules/data/saveDialog.less 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'; -- 2.20.1