//= require scrivito_patches/models/api/basic_obj //= require scrivito_patches/models/binary_field_element //= require scrivito_patches/models/obj //= require scrivito_patches/ajax //= require scrivito_patches/attribute_serializer //= require scrivito_patches/ajax_error_handling //= require scrivito_patches/base_obj_path //= require scrivito_patches/cms_rest_api //= require scrivito_patches/obj_serializer //= require scrivito_patches/binary_utils //= 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.withDialogBehaviour(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': 'Workflow starten', 'commands.edit_obj.dialog.title': 'Workflow starten?', 'commands.edit_obj.dialog.description': 'Es wird eine neue Arbeitsversion erstellt.', 'commands.edit_obj.dialog.placeholder': 'Bitte Kommentar eintragen', 'commands.edit_obj.dialog.confirm': 'Starten', 'commands.edit_obj.failed': 'Workflow 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': 'Start a workflow', 'commands.edit_obj.dialog.title': 'Start a workflow for 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': 'Start a workflow', 'commands.edit_obj.failed': 'Workflow 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"]; var releaseAction = function (objId) { open_release_dialog(objId).done(function(objIds, comment) { scrivito.withSavingOverlay(scrivito.ajax('PUT', 'objs/release', {data: {objs: objIds, comment: comment}}).then(function() { scrivito.reload(); })); }); }; var workflowAction = function (action, objId) { open_confirmation_dialog(action, dialog_icons[action]).done(function(comment) { scrivito.withSavingOverlay(scrivito.ajax('PUT', 'objs/workflow/'+action, {data: {id: objId, comment: comment}}).then(function() { if (action == 'edit' || action == 'take') { if (!scrivito.editing_context.is_editing_mode()) { return scrivito.withSavingOverlay( scrivito.change_editing_context({display_mode: 'editing', workspace_id: 'rtc'})); } else { return scrivito.withSavingOverlay(scrivito.reload()); } } else { return scrivito.withSavingOverlay(scrivito.reload()); } })); }); }; 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 var button; // enable workflow buttons $.each(buttons, function (idx, action) { // release is handled differently if (action === 'release') { return; } // find the workflow button button = $('[data-fiona7-private-workflow-button="' + action + '"]', cms_document.browser_window().document); // enable given workflow button button.removeAttr('disabled'); button.removeClass('disabled'); button.click(function () { workflowAction(action, obj.id()); }); }); // remove redundant buttons $.each(actions, function (idx, action) { if (buttons.indexOf(action) === -1) { $('[data-fiona7-private-workflow-button="' + action + '"]', cms_document.browser_window().document).remove(); } }); // conditionally enable release button // find the release button button = $('[data-fiona7-private-workflow-button="release"]', cms_document.browser_window().document); if (obj.modification()) { if (obj.has_restriction()) { // release impossibru button.attr('title', obj.restriction_messages().join("; ")); } else { button.removeAttr('disabled'); button.removeClass('disabled'); button.click(function () { releaseAction(obj.id()); }); } } 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() { return releaseAction(obj.id()); } }); /* 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() { return workflowAction(action, obj.id()); } }); }); }); return; }());