//= 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' }); }; var open_release_dialog = function(obj_id) { var base_url = window.location.protocol + '//' + window.location.host + '/__scrivito/'; var path = 'objs/' + obj_id + '/release/preview'; var deferred = $.Deferred(); $.ajax(base_url + path, { type: 'GET', dataType: 'html', cache: false }).then( function(result, text_status, xhr) { var view = $(result); $('#scrivito_editing').append(view); var accept = function() { scrivito.dialog.close_with_transition(view); var checkedObjs = view.find(':checked').map(function() { return $(this).val(); }).get(); var comment = view.find('#release-comment').val(); deferred.resolve(checkedObjs, comment); return false; }; var cancel = function() { scrivito.dialog.close_with_transition(view); deferred.reject(); return false; }; var expand = function() { $(this).next().slideToggle(); return false; }; view.find('.scrivito_accept').on('click', accept); view.find('.scrivito_cancel').on('click', cancel); view.find('.expanding').on('click', expand); scrivito.dialog.open_and_center_with_transition(view).then(function() { // view loaded }); scrivito.with_dialog_behaviour(view, deferred, {enter: accept, escape: cancel}); }, function(xhr, text_status, error) { }); return deferred; }; $.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': 'Bitte Kommentar eintragen', 'commands.release_obj.dialog.confirm': 'Freigeben', 'commands.release_obj.failed': 'Freigabe fehlgeschlagen', 'commands.edit_obj.title': 'Seite bearbeiten', 'commands.edit_obj.dialog.title': 'Seite bearbeiten?', 'commands.edit_obj.dialog.description': 'Es wird eine neue Arbeitsversion erstellt.', 'commands.edit_obj.dialog.placeholder': 'Bitte Kommentar eintragen', 'commands.edit_obj.dialog.confirm': 'Bearbeiten', 'commands.edit_obj.failed': 'Bearbeitung 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': 'Bitte Kommentar eintragen', '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': 'Bitte Kommentar eintragen', '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': 'Bitte Kommentar eintragen', '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': 'Bitte Kommentar eintragen', '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': 'Bitte Kommentar eintragen', 'commands.take_obj.dialog.confirm': 'Übernehmen', 'commands.take_obj.failed': 'Übernahme fehlgeschlagen', 'editing_disabled.workflow': 'Die Datei unterliegt einem Workflow und kann nicht direkt bearbeitet werden.', 'editing_disabled.permissions': 'Ihnen fehlen die Rechte um die Datei zu bearbeiten' }, '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.edit_obj.title': 'Edit page', 'commands.edit_obj.dialog.title': 'Edit this page?', 'commands.edit_obj.dialog.description': 'A new version of this page will be created.', 'commands.edit_obj.dialog.placeholder': 'Comment', 'commands.edit_obj.dialog.confirm': 'Edit', 'commands.edit_obj.failed': 'Edit 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': 'Current page will be rejected. This operation cannot be reverted.', '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': 'Committed page will be signed. This operation cannot be reverted.', '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', 'editing_disabled.workflow': 'The current page belongs to a workflow and cannot be edited directly.', 'editing_disabled.permissions': 'You do not have the permissions required to edit this page.' }, 'en'); var dialog_icons = { "edit": "", "forward": "", "reject": "", "commit": "", "sign": "", "take": "", "release": "" }; var icons = { "edit": "pen", "forward": "check", "reject": "cross", "commit": "check", "sign": "circ_pen", "take": "exclamation", "release": "globe" }; var actions = ["edit", "forward", "reject","commit", "sign", "take"]; scrivito.gui.on('document', function(cms_document) { var page_config = (cms_document.page_config() || {})['current_page'] || {}; var obj = cms_document.page(); var buttons = page_config['buttons'] || []; var workflow_enabled = page_config['workflow']; if (cms_document.browser_window().name !== 'scrivito_application') { // TODO: add special handling for scrivito_details_dialog and scrivito_inspector return; } /* release button */ scrivito.page_menu(cms_document).add('fiona7.idx'+99+'.release_obj', { title: scrivito.t('commands.release_obj.title'), icon: icons['release'], present: function() { return scrivito.editing_context.selected_workspace.is_editable() && obj && (!workflow_enabled || (buttons.indexOf('release') !== -1)); }, disabled: function() { if (!obj.modification()) { return scrivito.t('commands.release_obj.not_modified_obj'); } if (obj.has_restriction()) { return obj.restriction_messages().join("; "); } }, update: function() { return obj.reload(); }, execute: function() { open_release_dialog(obj.id()).done(function(objIds, comment) { scrivito.with_saving_overlay(scrivito.ajax('PUT', 'objs/release', {data: {objs: objIds, comment: comment}}).then(function() { scrivito.reload(); })); }); } }); /* TODO: enforce permissions */ /* TODO: better sorting */ /* disable editing */ setTimeout(function (){ if (page_config['editing_disabled']) { scrivito.editing_mode.disable(scrivito.t('editing_disabled.workflow')); } else { scrivito.editing_mode.enable(); } }, 0); /* add workflow buttons */ $.each(actions, function(idx, action) { scrivito.page_menu(cms_document).add('fiona7.idx'+idx+'.'+action+'_obj', { title: scrivito.t('commands.'+action+'_obj.title'), icon: icons[action], present: function() { return buttons.indexOf(action) !== -1; }, execute: function() { open_confirmation_dialog(action, dialog_icons[action]).done(function(comment) { scrivito.with_saving_overlay(scrivito.ajax('PUT', 'objs/workflow/'+action, {data: {id: obj.id(), comment: comment}}).then(function() { if (action == 'edit' || action == 'take') { if (!scrivito.editing_context.is_editing_mode()) { return scrivito.with_saving_overlay( scrivito.change_editing_context({display_mode: 'editing', workspace_id: 'rtc'})); } else { return scrivito.with_saving_overlay(scrivito.reload()); } } else { return scrivito.with_saving_overlay(scrivito.reload()); } })); }); } }); }); }); return; }());