//= require scrivito_patches/models/ajax //= require scrivito_patches/models/blob //= require scrivito_patches/models/obj //= require_self (function() { var scrivito = window.scrivito; var _ = window._; var $ = window.$; 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; }; var open_confirmation_dialog = function(action,icon) { return scrivito.prompt_dialog({ title: scrivito.t('commands.'+action+'_obj.dialog.title'), description: scrivito.t('commands.'+action+'_obj.dialog.description'), placeholder: scrivito.t('commands.'+action+'_obj.dialog.placeholder'), icon: icon, color: 'green', accept_button_text: scrivito.t('commands.'+action+'_obj.dialog.confirm'), accept_button_color: 'green' }); }; $.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': 'Ä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.placeholder': 'Kommentar', 'commands.release_obj.dialog.confirm': 'Freigeben', 'commands.release_obj.failed': 'Freigabe fehlgeschlagen', 'commands.forward_obj.title': 'Seite weiterleiten', 'commands.forward_obj.dialog.title': 'Seite weiterleiten?', 'commands.forward_obj.dialog.description': 'Die Arbeitsversion wird an einen weiteren Bearbeiter weitergeleitet. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.forward_obj.dialog.placeholder': 'Kommentar', 'commands.forward_obj.dialog.confirm': 'Weiterleiten', 'commands.forward_obj.failed': 'Weiterleitung fehlgeschlagen', 'commands.reject_obj.title': 'Seite ablehnen', 'commands.reject_obj.dialog.title': 'Seite ablehnen?', 'commands.reject_obj.dialog.description': 'Die Arbeitsversion wird abgelehnt. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.reject_obj.dialog.placeholder': 'Kommentar', 'commands.reject_obj.dialog.confirm': 'Ablehnen', 'commands.reject_obj.failed': 'Ablehnung fehlgeschlagen', 'commands.sign_obj.title': 'Seite abzeichnen', 'commands.sign_obj.dialog.title': 'Seite abzeichnen?', 'commands.sign_obj.dialog.description': 'Die eingereichte Version wird abgezeichnet. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.sign_obj.dialog.placeholder': 'Kommentar', 'commands.sign_obj.dialog.confirm': 'Abzeichnen', 'commands.sign_obj.failed': 'Abzeichnung fehlgeschlagen', 'commands.commit_obj.title': 'Seite einreichen', 'commands.commit_obj.dialog.title': 'Seite einreichen?', 'commands.commit_obj.dialog.description': 'Die Arbeitsversion wird eingereicht. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.commit_obj.dialog.placeholder': 'Kommentar', 'commands.commit_obj.dialog.confirm': 'Einreichen', 'commands.commit_obj.failed': 'Einreichung fehlgeschlagen', 'commands.take_obj.title': 'Seite übernehmen', 'commands.take_obj.dialog.title': 'Seite übernehmen?', 'commands.take_obj.dialog.description': 'Die Arbeitsversion wird übernommen. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.take_obj.dialog.placeholder': 'Kommentar', 'commands.take_obj.dialog.confirm': 'Übernehmen', 'commands.take_obj.failed': 'Übernahme 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': 'Release this page?', 'commands.release_obj.dialog.description': 'Releasing an edited page is final. This operation cannot be reverted.', 'commands.release_obj.dialog.placeholder': 'Comment', 'commands.release_obj.dialog.confirm': 'Release', 'commands.release_obj.failed': 'Release failed', 'commands.forward_obj.title': 'Forward page', 'commands.forward_obj.dialog.title': 'Forward this page?', 'commands.forward_obj.dialog.description': 'Forward and edited page is final. This operation cannot be reverted.', 'commands.forward_obj.dialog.placeholder': 'Comment', 'commands.forward_obj.dialog.confirm': 'Forward', 'commands.forward_obj.failed': 'Forward failed', 'commands.reject_obj.title': 'Reject page', 'commands.reject_obj.dialog.title': 'Reject this page?', 'commands.reject_obj.dialog.description': 'Die Arbeitsversion wird abgelehnt. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.reject_obj.dialog.placeholder': 'Comment', 'commands.reject_obj.dialog.confirm': 'Reject', 'commands.reject_obj.failed': 'Reject failed', 'commands.sign_obj.title': 'Sign page', 'commands.sign_obj.dialog.title': 'Sign this page?', 'commands.sign_obj.dialog.description': 'Die eingereichte Version wird abgezeichnet. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.sign_obj.dialog.placeholder': 'Comment', 'commands.sign_obj.dialog.confirm': 'Sign', 'commands.sign_obj.failed': 'Signing failed', 'commands.commit_obj.title': 'Commit page', 'commands.commit_obj.dialog.title': 'Commit this page?', 'commands.commit_obj.dialog.description': 'Die Arbeitsversion wird eingereicht. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.commit_obj.dialog.placeholder': 'Comment', 'commands.commit_obj.dialog.confirm': 'Commit', 'commands.commit_obj.failed': 'Commit failed', 'commands.take_obj.title': 'Take page', 'commands.take_obj.dialog.title': 'Tage this page?', 'commands.take_obj.dialog.description': 'Die Arbeitsversion wird übernommen. Dieser Vorgang kann nicht rückgängig gemacht werden.', 'commands.take_obj.dialog.placeholder': 'Comment', 'commands.take_obj.dialog.confirm': 'Take', 'commands.take_obj.failed': 'Take failed' }, 'en'); var dialog_icons = { "forward": "", "reject": "", "commit": " heck;", "sign": "", "take": "", "release": "" }; var icons = { "forward": "check", "reject": "cross", "commit": "check", "sign": "circ_pen", "take": "exclamation", "release": "globe" }; var actions = ["forward", "reject","commit", "sign", "take", "release"]; actions = ["release"]; scrivito.gui.on('document', function(cms_document) { //console.log('adding release button'); var obj = cms_document.page(); _.each(actions, function(action,idx) { scrivito.page_menu(cms_document).add('fiona7.idx'+idx+'.'+action+'_obj', { title: scrivito.t('commands.'+action+'_obj.title'), icon: icons[action], present: function() { return scrivito.editing_context.selected_workspace.is_editable() && obj;// && !obj.is_deleted() && scrivito.user_permissions.can(action + '_obj'); }, disabled: function() { if (action == 'release' && !obj.modification()) { return scrivito.t('commands.release_obj.not_modified_obj'); } }, update: function() { return obj.reload(); }, execute: function() { /* TODO: implement permission check */ open_confirmation_dialog(action, dialog_icons[action]).done(function(comment) { scrivito.with_saving_overlay(scrivito.ajax('PUT', 'objs/' + obj.id() + '/release?comment=' + (comment || "")).then(function() { scrivito.reload(); }).fail(function(error) { scrivito.alert_dialog(scrivito.t('commnds.'+action+'_obj.failed')); })); }); } }); }); //var menu = cms_document.menu(); //menu.push(scrivito.command_separator.create_instance({id: 'fiona7.zz_sparator'})); //cms_document.set_menu(menu); //scrivito.configure_menu_order(['fiona7.*', '*']); }); return; /* 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; }; /* 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(); } } }; }());