lib/assets/javascripts/scrivito_editing.js in scrivito_sdk-0.13.0 vs lib/assets/javascripts/scrivito_editing.js in scrivito_sdk-0.14.0

- old
+ new

@@ -9757,30 +9757,43 @@ (function() { this.ScrivitoHandlebarsTemplates || (this.ScrivitoHandlebarsTemplates = {}); this.ScrivitoHandlebarsTemplates["inplace_menu_marker"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { this.compilerInfo = [3,'>= 1.0.0-rc.4']; helpers = helpers || Handlebars.helpers; data = data || {}; - var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression; + var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this; +function program1(depth0,data) { + + var buffer = "", stack1; + buffer += "\n <span class=\"scrivito_editing_marker_title\">"; + if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); } + else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } + buffer += escapeExpression(stack1) + + "</span>\n "; + return buffer; + } buffer += "<span class=\"scrivito_editing_marker "; if (stack1 = helpers.css_classes) { stack1 = stack1.call(depth0, {hash:{},data:data}); } else { stack1 = depth0.css_classes; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } buffer += escapeExpression(stack1) + "\" id=\""; if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); } else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } buffer += escapeExpression(stack1) + "\" title=\""; - if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); } - else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } + if (stack1 = helpers.tooltip) { stack1 = stack1.call(depth0, {hash:{},data:data}); } + else { stack1 = depth0.tooltip; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } buffer += escapeExpression(stack1) + "\">\n <i class=\"scrivito_icon\">"; if (stack1 = helpers.icon) { stack1 = stack1.call(depth0, {hash:{},data:data}); } else { stack1 = depth0.icon; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } buffer += escapeExpression(stack1) - + "</i>\n</span>\n"; + + "</i>\n "; + stack1 = helpers['if'].call(depth0, depth0.description, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data}); + if(stack1 || stack1 === 0) { buffer += stack1; } + buffer += "\n</span>\n"; return buffer; }); return this.ScrivitoHandlebarsTemplates["inplace_menu_marker"]; }).call(this); (function() { @@ -10277,10 +10290,12 @@ 'widget_menus.widget_is_edited_and_dragged_away': 'Widget wurde geändert und von hier weggezogen', 'widget_menus.widget_is_deleted': 'Widget wurde gelöscht', 'widget_menus.widget_is_dragged_here': 'Widget wurde hierher gezogen', 'widget_menus.widget_is_dragged_away': 'Widget wurde von hier weggezogen', + 'child_list_menu.description': 'Elemente von $1', + 'changes_list.menu_item': 'Änderungen von "$1"', 'changes_list.title': 'Änderungen von "$1"', 'changes_list.empty_result': 'In dieser Arbeitskopie wurde nichts geändert.', 'changes_list.more': 'Mehr...', 'changes_list.row.change': 'Änderung', @@ -10424,10 +10439,12 @@ 'widget_menus.widget_is_edited_and_dragged_away': 'Widget has been modified and dragged away from here', 'widget_menus.widget_is_deleted': 'Widget has been deleted', 'widget_menus.widget_is_dragged_here': 'Widget has been dragged here', 'widget_menus.widget_is_dragged_away': 'Widget has been dragged away from here', + 'child_list_menu.description': 'Items of $1', + 'changes_list.menu_item': 'Changes to "$1"', 'changes_list.title': 'Changes to "$1"', 'changes_list.empty_result': 'Nothing was changed in this working copy.', 'changes_list.more': 'More...', 'changes_list.row.change': 'Change', @@ -10549,10 +10566,14 @@ return $.Deferred(function(dfd) { setTimeout(dfd.resolve, seconds * 1000); }); }, + run_new_event: function(method) { + scrivito.wait(0).done(method); + }, + // For testing purpose only. reload_location: function() { window.location.reload(); }, @@ -11005,10 +11026,12 @@ $.extend(scrivito, { ajax: function(type, path, options) { var is_write_request = type === 'PUT' || type === 'POST' || type === 'DELETE'; if (is_write_request) { + options = options || {}; + options.timeout = 15000; // miliseconds scrivito.write_monitor.start_write(); } var ajax_promise = single_ajax(type, path, options).then(function(result) { if (result && result.task && _.size(result) === 1) { @@ -11123,19 +11146,58 @@ is_writing: function() { return counter > 0; }, start_write: function() { - run_callbacks('start_write'); + if (!scrivito.write_monitor.is_writing()) { + run_callbacks('start_write'); + } counter += 1; }, end_write: function() { counter -= 1; - run_callbacks('end_write'); + if (!scrivito.write_monitor.is_writing()) { + scrivito.run_new_event(function() { + if (!scrivito.write_monitor.is_writing()) { + run_callbacks('end_write'); + } + }); + } }, + track_changes: function(fn, on_change_callback) { + var has_changes = false; + var changes_finished = false; + + var start_token = scrivito.write_monitor.on('start_write', function() { + has_changes = true; + changes_finished = false; + }); + var end_token = scrivito.write_monitor.on('end_write', function() { + changes_finished = true; + }); + + return fn().done(function() { + scrivito.write_monitor.off(start_token); + scrivito.write_monitor.off(end_token); + if (has_changes) { + if (changes_finished) { + on_change_callback(); + } else { + var saving_promise = $.Deferred(); + var final_end_token = scrivito.write_monitor.on('end_write', function() { + scrivito.write_monitor.off(final_end_token); + saving_promise.resolve(); + on_change_callback(); + }); + scrivito.with_saving_overlay(saving_promise); + } + } + }); + }, + // For test purpose only. reset_callbacks: function() { callbacks = {}; current_token = 0; }, @@ -11883,16 +11945,23 @@ } else { $.error("Can't save without content"); } } - var changes = {}; - changes[that.field_name()] = content; + var request_promise = $.Deferred(); - var widget = that.widget(); - var promise = widget ? widget.save(changes) : that.obj().save(changes); - return promise.then(function(model_data) { + var to_be_saved = to_be_saved_data() || {}; + to_be_saved.value = content; + to_be_saved.promises = to_be_saved.promises || []; + to_be_saved.promises.push(request_promise); + to_be_saved_data(to_be_saved); + + if (!currently_saving()) { + next_save_request(); + } + + return request_promise.then(function(model_data) { return model_data[that.field_name()]; }); }, original_content: function() { @@ -11918,10 +11987,67 @@ if (that.workspace_id() !== scrivito.editing_context.selected_workspace.id()) { $.error('Tried to edit cms data from wrong workspace!'); } }; + var next_save_request = function() { + currently_saving(true); + var to_be_saved = to_be_saved_data(); + remove_to_be_saved(); + + var changes = {}; + changes[that.field_name()] = to_be_saved.value; + + var widget = that.widget(); + var save_promise = widget ? widget.save(changes) : that.obj().save(changes); + + save_promise.done(function(result) { + _.each(to_be_saved.promises, function(succeeding_promise) { + succeeding_promise.resolve(result); + }); + + if (to_be_saved_data()) { + next_save_request(); + } else { + remove_currently_saving(); + } + }).fail(function(error_message) { + var new_promises = (to_be_saved_data() || {}).promises; + var failing_promises = to_be_saved.promises.concat(new_promises || []); + _.each(failing_promises, function(failing_promise) { + failing_promise.reject(error_message); + }); + + remove_to_be_saved(); + remove_currently_saving(); + }); + }; + + var to_be_saved_data = function(new_to_be_saved) { + if (new_to_be_saved) { + return that.dom_element().data('scrivito-to-be-saved', new_to_be_saved); + } else { + return that.dom_element().data('scrivito-to-be-saved'); + } + }; + + var remove_to_be_saved = function() { + that.dom_element().removeData('scrivito-to-be-saved'); + }; + + var currently_saving = function(new_currently_saving) { + if (new_currently_saving) { + return that.dom_element().data('scrivito-currently-saving', new_currently_saving); + } else { + return that.dom_element().data('scrivito-currently-saving'); + } + }; + + var remove_currently_saving = function() { + that.dom_element().removeData('scrivito-currently-saving'); + }; + return that; } } }); }()); @@ -12100,23 +12226,17 @@ copy_to: function(path) { var post_attr = {data: {parent_path: path}}; var url = 'objs/'+that.id()+'/copy'; return scrivito.ajax('POST', url, post_attr).then(function(new_data) { - return scrivito.obj.create_instance({ - id: new_data.id, - obj_class_name: new_data._obj_class - }); + return scrivito.obj.create_instance_from_server_data(new_data); }); }, duplicate: function() { return scrivito.ajax('POST', 'objs/'+that.id()+'/duplicate').then(function(new_data) { - return scrivito.obj.create_instance({ - id: new_data.id, - obj_class_name: new_data._obj_class - }); + return scrivito.obj.create_instance_from_server_data(new_data); }); } }; var editing_state = function() { @@ -12138,17 +12258,21 @@ }; return that; }, + create_instance_from_server_data: function(create_params) { + return scrivito.obj.create_instance({ + id: (create_params.id || create_params._id), + obj_class_name: create_params._obj_class + }); + }, + create: function(data) { return prepare_attributes(data).then(function(attributes) { return scrivito.ajax('POST', 'objs', {data: {obj: attributes}}).then(function(new_data) { - return scrivito.obj.create_instance({ - id: new_data.id, - obj_class_name: new_data._obj_class - }); + return scrivito.obj.create_instance_from_server_data(new_data); }); }); } } }); @@ -13355,10 +13479,14 @@ set_description: function(dom_element, description) { $(dom_element).attr('data-scrivito-private-menu-description', description); }, + set_tooltip: function(dom_element, tooltip) { + $(dom_element).attr('data-scrivito-private-menu-tooltip', tooltip); + }, + set_css_classes: function(dom_element, css_classes) { $(dom_element).attr('data-scrivito-private-menu-css-classes', css_classes); } }; @@ -13379,17 +13507,19 @@ var menu_id = 'scrivito_private_menu_' + i; var marker_id = 'scrivito_private_menu_marker_' + i; var icon = dom_element.attr('data-scrivito-private-menu-icon') || '\uf000'; var description = dom_element.attr('data-scrivito-private-menu-description'); + var tooltip = dom_element.attr('data-scrivito-private-menu-tooltip'); var css_classes = dom_element.attr('data-scrivito-private-menu-css-classes'); var commands = dom_element.data('scrivito-private-menu-commands'); var marker = $(scrivito.template.render('inplace_menu_marker', { id: marker_id, icon: icon, description: description, + tooltip: tooltip, css_classes: css_classes })); marker.data('scrivito-private-menu-id', marker_id); @@ -13774,24 +13904,19 @@ present: function() { return obj.has_details_view(); }, execute: function() { - var has_changes = false; - var token = scrivito.write_monitor.on('start_write', function() { - has_changes = true; - }); - var title = scrivito.i18n.translate('current_page'); var fetch_markup = function() { return obj.fetch_details_markup(); }; - return scrivito.details_dialog.open(title, fetch_markup, '&#xf03d;').then(function() { - scrivito.write_monitor.off(token); - if (has_changes) { - return scrivito.with_saving_overlay(scrivito.reload()); - } + + return scrivito.write_monitor.track_changes(function() { + return scrivito.details_dialog.open(title, fetch_markup, '&#xf03d;'); + }, function() { + return scrivito.with_saving_overlay(scrivito.reload()); }); } }); } }); @@ -13959,25 +14084,19 @@ return widget_element.has_details_view() && (scrivito.editing_context.is_editing_mode() || widget_element.widget().is_modified()); }, execute: function() { - var has_changes = false; - var token = scrivito.write_monitor.on('start_write', function() { - has_changes = true; - }); - var dialog_title = widget_element.widget().widget_class_name(); var fetch_markup = function() { return widget_element.fetch_details_markup(); }; - return scrivito.details_dialog.open(dialog_title, fetch_markup).then(function() { - scrivito.write_monitor.off(token); - if (has_changes) { - widget_element.dom_element().trigger('scrivito_reload'); - } + return scrivito.write_monitor.track_changes(function() { + return scrivito.details_dialog.open(dialog_title, fetch_markup); + }, function() { + widget_element.dom_element().trigger('scrivito_reload'); }); } }); } }); @@ -14007,16 +14126,19 @@ scrivito.delete_widget_command(widget_field_element, widget_element) ], function(command) { menu.add_item(widget_dom_element, command); }); + var description = widget_element.widget().widget_class_name(); + menu.set_description(widget_dom_element, description); + if (widget_element.has_details_view() && scrivito.editing_context.is_comparing_mode()) { var options = menu_options(widget_element); if (options) { - var description = scrivito.i18n.translate('widget_menus.' + options.key); - menu.set_description(widget_dom_element, description); + var tooltip = scrivito.i18n.translate('widget_menus.' + options.key); + menu.set_tooltip(widget_dom_element, tooltip); menu.set_icon(widget_dom_element, options.icon); menu.set_css_classes(widget_dom_element, options.css_class); } } }); @@ -14233,10 +14355,13 @@ scrivito.inplace_menus.define(function(menu) { if (scrivito.editing_context.visible_workspace.is_editable() && scrivito.editing_context.is_editing_mode()) { _.each(scrivito.child_list_element.all(), function(child_list_element) { var dom_element = child_list_element.dom_element(); + var description = child_list_element.obj().description_for_editor(); + menu.set_description(dom_element, + scrivito.i18n.translate('child_list_menu.description', description)); _.each([ scrivito.add_subpage_command(child_list_element), scrivito.copy_page_from_clipboard_command(child_list_element), scrivito.move_page_from_clipboard_command(child_list_element), scrivito.sort_items_command(child_list_element) @@ -14317,15 +14442,15 @@ var obj_name = file.name.replace(/[^a-z0-9_.$\-]/ig, '-'); var path = '_resources/' + scrivito.random_hex() + '/' + obj_name; return scrivito.create_obj({blob: file, _path: path, _obj_class: 'Image'}); }; - scrivito.with_saving_overlay(create_image(file).then(function(data) { + scrivito.with_saving_overlay(create_image(file).then(function(obj) { var field_value; if (field_type === 'reference') { - field_value = data.id; + field_value = obj.id; } else if (field_type === 'linklist') { - field_value = [{obj_id: data.id}]; + field_value = [{obj_id: obj.id}]; } else { $.error('Field type must be "reference" or "linklist".'); } return dom_element.scrivito('save', field_value).then(function() {