app/assets/javascripts/fiona7_ui.js in infopark_fiona7-1.2.0.2.3 vs app/assets/javascripts/fiona7_ui.js in infopark_fiona7-1.5.2.0.0
- old
+ new
@@ -1,8 +1,15 @@
-//= require scrivito_patches/models/ajax
-//= require scrivito_patches/models/blob
+//= 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._;
@@ -85,11 +92,11 @@
scrivito.dialog.open_and_center_with_transition(view).then(function() {
// view loaded
});
- scrivito.with_dialog_behaviour(view, deferred, {enter: accept, escape: cancel});
+ scrivito.withDialogBehaviour(view, deferred, {enter: accept, escape: cancel});
},
function(xhr, text_status, error) {
});
return deferred;
@@ -224,18 +231,88 @@
"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', {
@@ -258,15 +335,11 @@
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();
- }));
- });
+ return releaseAction(obj.id());
}
});
/* TODO: enforce permissions */
/* TODO: better sorting */
@@ -289,24 +362,10 @@
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 workflowAction(action, obj.id());
}
});
});
});