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) {
},
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');
},
});
},
- 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;
-@import 'saveDialog.less';
\ No newline at end of file
+@import 'dialog.less';
\ No newline at end of file
--- /dev/null
+<div class="rng-dialog modal hide static">
+ <div class="modal-header">
+ <button type="button" class="close">×</button>
+ <h1><%= title %></h1>
+ </div>
+ <div class="modal-body">
+ </div>
+ <div class="modal-footer">
+ <a href="#" class="btn btn-info btn-mini save-btn"><%= submitButtonText %></a>
+ <a href="#" class="btn btn-danger btn-mini cancel-btn">Anuluj</a>
+ </div>
+</div>
\ No newline at end of file
--- /dev/null
+define(function(require) {
+
+ 'use strict';
+
+ var _ = require('libs/underscore'),
+ Backbone = require('libs/backbone'),
+ saveDialogTemplate = require('libs/text!./dialog.html'),
+ fieldTemplates = {};
+ fieldTemplates.checkbox = require('libs/text!./templates/checkbox.html');
+ fieldTemplates.select = require('libs/text!./templates/select.html');
+ fieldTemplates.textarea = require('libs/text!./templates/textarea.html');
+ fieldTemplates.input = require('libs/text!./templates/input.html');
+
+
+
+ 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.options));
+
+ var body = this.$('.modal-body');
+ this.options.fields.forEach(function(field) {
+ var template = fieldTemplates[field.type];
+ if(!template) {
+ throw new Error('Field type {type} not recognized.'.replace('{type}', field.type));
+ }
+ body.append(
+ _.template(template)(_.extend({description: ''}, field))
+ );
+ });
+
+ this.$el.modal({backdrop: 'static'});
+ this.$el.modal('show');
+ this.$('textarea').focus();
+ },
+ onSave: function(e) {
+ e.preventDefault();
+ var view = this,
+ formData = {};
+
+ this.options.fields.forEach(function(field) {
+ var widget = view.$('[name=' + field.name +']');
+ formData[field.name] = widget.val();
+ });
+
+ this.trigger('save', {
+ formData: formData,
+ 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.$('textarea').attr('disabled', !toggle);
+ this.actionsDisabled = !toggle;
+ }
+ });
+
+ return {
+ create: function(config) {
+ return new DialogView(config);
+ }
+ };
+
+});
\ No newline at end of file
--- /dev/null
+.rng-dialog {
+ 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;
+ }
+
+ .description {
+ font-size: .8em;
+ }
+
+ width: 620px;
+}
\ No newline at end of file
+++ /dev/null
-<div class="rng-module-data-saveDialog modal hide static">
- <div class="modal-header">
- <button type="button" class="close">×</button>
- <h1>Zapisz dokument</h1>
- </div>
- <div class="modal-body">
- </div>
- <div class="modal-footer">
- <a href="#" class="btn btn-info btn-mini save-btn">Zapisz</a>
- <a href="#" class="btn btn-danger btn-mini cancel-btn">Anuluj</a>
- </div>
-</div>
\ No newline at end of file
+++ /dev/null
-define(function(require) {
-
- 'use strict';
-
- var _ = require('libs/underscore'),
- Backbone = require('libs/backbone'),
- saveDialogTemplate = require('libs/text!./saveDialog.html'),
- fieldTemplates = {};
- fieldTemplates.checkbox = require('libs/text!./templates/checkbox.html');
- fieldTemplates.select = require('libs/text!./templates/select.html');
- fieldTemplates.textarea = require('libs/text!./templates/textarea.html');
- fieldTemplates.input = require('libs/text!./templates/input.html');
-
-
-
- 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());
-
- var body = this.$('.modal-body');
- this.options.fields.forEach(function(field) {
- var template = fieldTemplates[field.type];
- if(!template) {
- throw new Error('Field type {type} not recognized.'.replace('{type}', field.type));
- }
- body.append(
- _.template(template)(_.extend({description: ''}, field))
- );
- });
-
- this.$el.modal({backdrop: 'static'});
- this.$el.modal('show');
- this.$('textarea').focus();
- },
- onSave: function(e) {
- e.preventDefault();
- var view = this,
- formData = {};
-
- this.options.fields.forEach(function(field) {
- var widget = view.$('[name=' + field.name +']');
- formData[field.name] = widget.val();
- });
-
- this.trigger('save', {
- formData: formData,
- 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.$('textarea').attr('disabled', !toggle);
- this.actionsDisabled = !toggle;
- }
- });
-
- return {
- create: function(config) {
- return new DialogView(config);
- }
- };
-
-});
\ No newline at end of file
+++ /dev/null
-.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;
- }
-
- .description {
- font-size: .8em;
- }
-
- width: 620px;
-}
\ No newline at end of file
define([
'libs/jquery',
'libs/underscore',
-'./restoreDialog',
'libs/text!./templates/main.html',
'libs/text!./templates/item.html'
-], function($, _, restoreDialog, mainTemplateSrc, itemTemplateSrc) {
+], function($, _, mainTemplateSrc, itemTemplateSrc) {
'use strict';
});
dom.find('.btn.restore').click(function() {
- var dialog = restoreDialog.create();
- dialog.on('restore', function(event) {
- sandbox.publish('restoreVersion', {version: historyItems.getSelected()[0], description: event.data.description});
- event.success();
- });
- dialog.show();
+ sandbox.publish('restoreVersion', historyItems.getSelected()[0]);
});
dom.find('.btn.display').click(function() {
+++ /dev/null
-define([
-'libs/text!./templates/restoreDialog.html',
-'libs/underscore',
-'libs/backbone'
-], function(restoreDialogTemplate, _, Backbone) {
-
- 'use strict';
-
-
- var DialogView = Backbone.View.extend({
- template: _.template(restoreDialogTemplate),
- events: {
- 'click .restore-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');
- this.$('textarea').focus();
- },
- onSave: function(e) {
- e.preventDefault();
- var view = this;
- this.trigger('restore', {
- 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.$('textarea').attr('disabled', !toggle);
- this.actionsDisabled = !toggle;
- }
- });
-
- return {
- create: function() {
- return new DialogView();
- }
- };
-
-});
\ No newline at end of file
+++ /dev/null
-<div class="rng-module-data-saveDialog modal hide static">
- <div class="modal-header">
- <button type="button" class="close">×</button>
- <h1>Przywróć wersję</h1>
- </div>
- <div class="modal-body">
- <label>Opisz powód przywrócenia</label>
- <textarea rows="5"></textarea>
- </div>
- <div class="modal-footer">
- <a href="#" class="btn btn-info btn-mini restore-btn">Przywróć</a>
- <a href="#" class="btn btn-danger btn-mini cancel-btn">Anuluj</a>
- </div>
-</div>
\ No newline at end of file
diffFetched: function(diff) {
sandbox.getModule('diffViewer').setDiff(diff);
},
- documentReverted: function(event) {
+ documentReverted: function(version) {
sandbox.getModule('mainBar').setCommandEnabled('save', true);
- sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});
- sandbox.getModule('mainBar').setVersion(event.current_version);
+ sandbox.getModule('indicator').clearMessage({message:'Wersja ' + version + ' przywrócona'});
+ sandbox.getModule('mainBar').setVersion(version);
}
};
compare: function(ver1, ver2) {
sandbox.getModule('data').fetchDiff(ver1, ver2);
},
- restoreVersion: function(event) {
- sandbox.getModule('data').restoreVersion(event);
+ restoreVersion: function(version) {
+ sandbox.getModule('data').restoreVersion(version);
},
displayVersion: function(event) {
/* globals window */