app/assets/javascripts/fiona7.js in infopark_fiona7-0.30.0.2 vs app/assets/javascripts/fiona7.js in infopark_fiona7-0.70.0.1

- old
+ new

@@ -1,284 +1,3 @@ //= require jquery //= require jquery_ujs -//= require scrivito_sdk -//= require scrivito_editors - -/* obj.js, patch create & upload */ -(function() { - var format_date = function(date) { - return date.getUTCFullYear().toString() + - format_date_number(date.getUTCMonth() + 1) + // Month numbers are starting at 0. - format_date_number(date.getUTCDate()) + - format_date_number(date.getUTCHours()) + - format_date_number(date.getUTCMinutes()) + - format_date_number(date.getUTCSeconds()); - }; - - var format_date_number = function(number) { - var string = number.toString(); - return string.length === 1 ? '0' + string : string; - }; - - var convert_attributes = function(data) { - var collected_promises = _.map(data, function(value, field_name) { - if (value instanceof Date) { - return $.Deferred().resolve([field_name, format_date(value)]); - } else if (value instanceof window.File) { - return $.Deferred().resolve([field_name, value]); - return scrivito.blob.create(value).then(function(value) { - return [field_name, value]; - }); - } else { - return $.Deferred().resolve([field_name, value]); - } - }); - - return $.when.apply(this, collected_promises).then(function() { - return _.object(arguments); - }); - }; - - var convert_widget_pool = function(widget_pool) { - if(widget_pool) { - var conversion_promises = _.map(widget_pool, function(attributes, widget_id) { - return convert_attributes(attributes).then(function(attributes) { - return [widget_id, attributes]; - }); - }); - - return $.when.apply(this, conversion_promises).then(function() { - return _.object(arguments); - }); - } else { - return $.Deferred().resolve(widget_pool); - } - }; - - var prepare_attributes = function(data) { - return convert_widget_pool(data._widget_pool).then(function(widget_pool) { - return convert_attributes(data).then(function(attributes) { - attributes._widget_pool = widget_pool; - return attributes; - }); - }); - }; - - scrivito.obj.create_original = scrivito.obj.create; - scrivito.obj.create = function (data) { - var blob; - - if (data['blob']) { - blob = data['blob']; - delete data['blob']; - } - return prepare_attributes(data).then(function(attributes) { - var fd, defer, url, base_url = window.location.protocol + '//' + window.location.host + '/__scrivito/'; - url = base_url + 'objs'; - - fd = new FormData(); - - $.each(attributes, function (key, value) { - if (typeof value !== 'undefined') { - fd.append('obj[' + key + ']', value); - } - }); - - if (typeof blob !== 'undefined') { - fd.append('obj[blob]', blob); - } - - defer = $.Deferred(); - - $.ajax({ - url: url, - type: 'POST', - data: fd, - processData: false, - contentType: false - }) - .error(function (xhr, text, error) { - scrivito.alert(text); - defer.reject(text); - }) - .success(function (new_data) { - defer.resolve(scrivito.obj.create_instance_from_server_data(new_data)); - }); - - return defer.promise(); - }); - }; - -}()); - -(function() { - -}()); - -(function() { - var original_create_instance = scrivito.child_list_element.create_instance; - - /* patch the create page command to not create incomprehensible paths */ - scrivito.child_list_element.create_instance = function(cms_element) { - var ret = original_create_instance.call(this, cms_element); - if (typeof ret === "object") { - ret.create_child = function(obj_class) { - var path = (cms_element.path() + '/' + obj_class).replace(/\/\//g, "/"); - - return scrivito.obj.create({ - _path: path, - _obj_class: obj_class - }); - }; - } - return ret; - }; - - /* patch the revert command to allow reverts on rtc workspace*/ - scrivito.revert_obj_command = function(obj, translations_namespace) { - if (!translations_namespace) { - translations_namespace = 'commands.revert_obj'; - } - - return scrivito.command.create_instance({ - id: 'revert_obj', - title: scrivito.t(translations_namespace + '.title'), - icon: '', - - present: function() { - return scrivito.editing_context.selected_workspace.is_editable() && obj && !obj.is_deleted(); - }, - - disabled: function() { - /* here patched: */ - /* - if (scrivito.editing_context.selected_workspace.is_rtc()) { - return scrivito.t(translations_namespace + '.rtc_workspace'); - } - */ - if (!obj.modification()) { - return scrivito.t(translations_namespace + '.not_modified_obj'); - } - if (obj.is_new()) { - return scrivito.t(translations_namespace + '.new_obj'); - } - }, - - update: function() { - return obj.update_modification(); - }, - - execute: function() { - return scrivito.confirmation_dialog({ - title: scrivito.t(translations_namespace + '.dialog.title'), - description: scrivito.t('commands.revert_obj.dialog.description'), - icon: '', - color: 'red', - confirm_button_text: scrivito.t('commands.revert_obj.dialog.confirm'), - confirm_button_color: 'red' - }).then(function() { - return scrivito.with_saving_overlay(obj.revert().then(function() { - scrivito.reload(); - })); - }); - } - }); - }; - - $.i18n().load({ - 'commands.release_obj.title': 'Seite freigeben', - 'commands.release_obj.not_modified_obj': 'Diese Seite wurde nicht geändert. Daher gibt es nichts zu freigeben.', - 'commands.release_obj.dialog.title': 'Wirklich Änderungen an dieser Seite veröffentlichen?', - 'commands.release_obj.dialog.description': 'Eine Arbeitsversion zu veröffentlichen ist endgültig. Dieser Vorgang kann nicht rückgängig gemacht werden.', - 'commands.release_obj.dialog.confirm': 'Freigeben', - 'commands.release_obj.failed': 'Freigabe fehlgeschlagen' - }, 'de'); - - $.i18n().load({ - 'commands.release_obj.title': 'Release page', - 'commands.release_obj.not_modified_obj': 'This resource has not been modified. Therefore, nothing can be released.', - 'commands.release_obj.dialog.title': 'Really release this page?', - 'commands.release_obj.dialog.description': 'Releasing an edited page is final. This operation cannot be reverted.', - 'commands.release_obj.dialog.confirm': 'Release', - 'commands.release_obj.failed': 'Release failed' - }, 'en'); - - var open_confirmation_dialog = function() { - return scrivito.confirmation_dialog({ - title: scrivito.t('commands.release_obj.dialog.title'), - description: scrivito.t('commands.release_obj.dialog.description'), - icon: '', - color: 'green', - confirm_button_text: scrivito.t('commands.release_obj.dialog.confirm'), - confirm_button_color: 'green' - }); - }; - - /* implement release command */ - scrivito.release_obj_command = function(obj, translations_namespace) { - if (!translations_namespace) { - translations_namespace = 'commands.release_obj'; - } - - return scrivito.command.create_instance({ - id: 'release_obj', - title: scrivito.t(translations_namespace + '.title'), - icon: '', - - present: function() { - return scrivito.editing_context.selected_workspace.is_editable() && obj && !obj.is_deleted(); - }, - - disabled: function() { - if (!obj.modification()) { - return scrivito.t(translations_namespace + '.not_modified_obj'); - } - }, - - execute: function() { - /* TODO: implement permission check */ - open_confirmation_dialog().done(function() { - scrivito.with_saving_overlay(scrivito.ajax('PUT', 'objs/' + obj.id() + '/release').then(function() { - scrivito.reload(); - }).fail(function(error) { - scrivito.alert_dialog(scrivito.t(translations_namespace + '.failed')); - })); - }); - } - }); - }; - - /* patch the obj menu */ - scrivito.current_page_menu.init = function() { - if (scrivito.obj.current_page) { - scrivito.menu_bar.register_item_renderer(function(menu_bar) { - var current_page = scrivito.obj.current_page; - scrivito.obj_menu.create(menu_bar.find('#scrivito_current_page_menu'), current_page, [ - scrivito.obj_details_command(current_page), - scrivito.save_obj_to_clipboard_command(current_page), - scrivito.release_obj_command(current_page), - scrivito.delete_obj_command(current_page), - scrivito.revert_obj_command(current_page), - //scrivito.restore_obj_command(current_page), - //scrivito.mark_resolved_obj_command(current_page), - scrivito.duplicate_obj_command(current_page) - ]); - }); - } - }; - - /* enforce permissions */ - var originalGuiStart = scrivito.gui.start; - scrivito.gui.start = function () { - originalGuiStart.call(this, arguments); - if (scrivito.in_editable_view()) { - if (!scrivito.user_permissions.can('write_obj')) { - $('.switch_to_view_mode').click(); - } - } else { - if (!scrivito.user_permissions.can('write_obj')) { - $('.scrivito_viewmode_editing').remove(); - } - } - }; - -}()); +//= require scrivito