- configurable save form
- configurable api urls
var reloadHistory = function() {
$.ajax({
method: 'get',
var reloadHistory = function() {
$.ajax({
method: 'get',
- url: '/' + gettext('editor') + '/' + document_id + '/history',
+ url: sandbox.getConfig().documentHistoryUrl(document_id),
success: function(data) {
history = data;
sandbox.publish('historyItemAdded', data.slice(-1)[0]);
success: function(data) {
history = data;
sandbox.publish('historyItemAdded', data.slice(-1)[0]);
return wlxmlDocument;
},
saveDocument: function() {
return wlxmlDocument;
},
saveDocument: function() {
-
- var dialog = saveDialog.create();
+ var documentSaveForm = $.extend({
+ fields: [],
+ content_field_name: 'text',
+ version_field_name: 'version'
+ },
+ sandbox.getConfig().documentSaveForm
+ ),
+ dialog = saveDialog.create({fields: documentSaveForm.fields});
+
dialog.on('save', function(event) {
sandbox.publish('savingStarted');
dialog.on('save', function(event) {
sandbox.publish('savingStarted');
+
+ var formData = event.formData;
+ formData[documentSaveForm.content_field_name] = wlxmlDocument.toXML();
+ formData[documentSaveForm.version_field_name] = document_version;
+ if(sandbox.getConfig().jsonifySentData) {
+ formData = JSON.stringify(formData);
+ }
+
dialog.toggleButtons(false);
$.ajax({
method: 'post',
dialog.toggleButtons(false);
$.ajax({
method: 'post',
- url: '/' + gettext('editor') + '/' + document_id,
- data: JSON.stringify({document:wlxmlDocument.toXML(), description: event.data.description}),
- success: function() {
+ url: sandbox.getConfig().documentSaveUrl(document_id),
+ data: formData,
+ success: function(data) {
- sandbox.publish('savingEnded', 'success');
+ sandbox.publish('savingEnded', 'success', data.version);
+ document_version = data.version;
reloadHistory();
},
error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
reloadHistory();
},
error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
fetchDiff: function(ver1, ver2) {
$.ajax({
method: 'get',
fetchDiff: function(ver1, ver2) {
$.ajax({
method: 'get',
- url: '/' + gettext('editor') + '/' + document_id + '/diff',
+ url: '/' + gettext('editor') + '/diff/' + document_id,
data: {from: ver1, to: ver2},
success: function(data) {
sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2});
data: {from: ver1, to: ver2},
success: function(data) {
sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2});
<h1>Zapisz dokument</h1>
</div>
<div class="modal-body">
<h1>Zapisz dokument</h1>
</div>
<div class="modal-body">
- <label>Opisz swoje zmiany</label>
- <textarea rows="5"></textarea>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-info btn-mini save-btn">Zapisz</a>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-info btn-mini save-btn">Zapisz</a>
-define([
-'libs/text!./saveDialog.html',
-'libs/underscore',
-'libs/backbone'
-], function(saveDialogTemplate, _, Backbone) {
+define(function(require) {
+ 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: {
var DialogView = Backbone.View.extend({
template: _.template(saveDialogTemplate),
events: {
},
show: function() {
this.setElement(this.template());
},
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();
this.$el.modal({backdrop: 'static'});
this.$el.modal('show');
this.$('textarea').focus();
},
onSave: function(e) {
e.preventDefault();
},
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();
+ });
+
- data: {description: view.$el.find('textarea').val()},
success: function() { view.actionsDisabled = false; view.close(); },
error: function() { view.actionsDisabled = false; view.close(); },
});
success: function() { view.actionsDisabled = false; view.close(); },
error: function() { view.actionsDisabled = false; view.close(); },
});
- create: function() {
- return new DialogView();
+ create: function(config) {
+ return new DialogView(config);
margin: 2px 5px;
font-weight: bold;
}
margin: 2px 5px;
font-weight: bold;
}
+
+ .description {
+ font-size: .8em;
+ }
+
+ width: 620px;
}
\ No newline at end of file
}
\ No newline at end of file
--- /dev/null
+<p>
+ <div style="float: left; width:100px;"><%= label %>:</div>
+ <input type="checkbox" name="<%= name %>"/>
+ <span class="description"><%= description %></span>
+</p>
\ No newline at end of file
--- /dev/null
+<p>
+ <div style="float: left; width:100px;">
+ <%= label %>:
+ </div>
+ <div>
+ <input type="input" name="<%= name %>"/>
+ <span class="description"><%= description %></span>
+ </div>
+
+</p>
\ No newline at end of file
--- /dev/null
+<p>
+ <div style="float: left; width:100px;"><%= label %>:</div>
+ <select name="<%= name %>">
+ <% options.forEach(function(option) { %>
+ <option value="<%= option.value %>"><%= option.text %></option>
+ <% }); %>
+ </select>
+ <span class="description"><%= description %></span>
+</p>
\ No newline at end of file
--- /dev/null
+<p>
+ <label><%= label %></label>
+ <textarea name="<%= name %>" rows="5"></textarea>
+ <span class="description"><%= description %></span>
+</p>