RoleEntitlementsEditView.js revision d84445f383c4eb7a93a274379edeb69f82ee8810
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2011-2015 ForgeRock AS. All rights reserved.
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*/
/*global define, $, form2js, _, JSONEditor */
/**
* @author huck.elliott
*/
"bootstrap-dialog",
], function(AbstractView, eventManager, constants, cookieHelper, uiUtils, resourceDelegate, messagesManager, BootstrapDialog, conf, InlineScriptEditor, configDelegate) {
element: "#dialogs",
noBaseTemplate: true,
events: {
"click #btn-add-attribute": "addAttribute",
"click .btn-delete-attribute": "deleteAttribute",
"click .mappingLink": "closeDialog",
"click #addMapping": "addMapping",
"click .removeMapping": "removeMapping"
},
closeDialog: function(e) {
},
var _this = this,
dialogTitle = (assignmentName) ? $.t("templates.admin.RoleEntitlementsTemplate.editEntitlement",{entitlementName: assignmentName}) : $.t("templates.admin.RoleEntitlementsTemplate.addEntitlement"),
removeAssignmentNameFromRoute = _.bind(function() {
if(this.data.assignmentRouteParam) {
eventManager.sendEvent(constants.ROUTE_REQUEST, {routeName: "adminEditManagedObjectView", args: this.data.args});
}
}, this);
this.currentDialog = $('<div id="roleEntitlementsEditContainer"></div>');
this.data.JSONEditors = [];
this.setElement(this.currentDialog);
message: this.currentDialog,
},
onhide: function() {
},
buttons: [{
label: $.t("common.form.cancel"),
id:"entitlementEditDialogCancel",
}
}, {
label: $.t('common.form.save'),
id: "entitlementEditDialogSubmit",
cssClass: "btn-primary",
_this.saveAssignment(function() {
});
}
}]
});
},
}, this);
}, this);
_.bind(function () {
if(!this.data.assignment) {
this.data.newAssignment = true;
this.addAttribute();
} else {
this.setJSONEditors();
this.data.newAssignment = false;
}
this.setScripts();
this.setAttributeOperationsPopovers();
if(callback){
callback();
}
}, this), "replace");
}, this));
},
disable_edit_json: true,
disable_array_reorder: true,
disable_collapse: true,
schema:{},
});
}, this));
return editor;
},
setJSONEditors: function() {
}, this);
},
setScripts: function() {
var emptyScript = {
type: "text/javascript",
globals: {},
file: ""
};
"eventName": "onAssignment",
"noValidation": true,
});
"eventName": "onUnassignment",
"noValidation": true,
});
},
addAttribute: function(e) {
if(e) {
e.preventDefault();
}
this.setAttributeOperationsPopovers();
},
deleteAttribute: function(e) {
var editorIndex = this.$el.find(".assignment-attributes .list-group-item").find(e.target).closest(".list-group-item").index();
e.preventDefault();
//remove the JSONEditor for this attribute
},
getAttributes: function() {
var attr = {};
return attr;
}, this);
},
saveAssignment: function(callback) {
var invalid = false,
if(onAssignment) {
}
if(onUnassignment) {
}
resourceDelegate.updateResource(this.data.serviceUrl, this.data.role._id, this.data.role, _.bind(function() {
var msg = (this.data.newAssignment) ? "templates.admin.RoleEntitlementsTemplate.assignmentAddSuccess" : "templates.admin.RoleEntitlementsTemplate.assignmentSaveSuccess";
messagesManager.messages.addMessage({"message": $.t(msg,{ assignment: this.data.assignmentName })});
if(callback) {
callback();
}
}, this));
}, this);
if(!this.data.assignment) {
invalid = true;
}
}
if(invalid) {
messagesManager.messages.addMessage({"type": "error","message": $.t("templates.admin.RoleEntitlementsTemplate.entitlementDuplicationError")});
} else {
doSave();
}
},
setAttributeOperationsPopovers: function() {
placement:'bottom',
html: true,
}).on('shown.bs.popover', function () {
var popup = $(this),
e.preventDefault();
});
});
});
},
if(addMapping) {
if(!mapping.assignmentsToMap) {
mapping.assignmentsToMap = [];
}
} else {
return a === this.data.assignmentName;
}, this);
}
}
return mapping;
}, this);
messagesManager.messages.addMessage({"message": $.t("templates.admin.RoleEntitlementsTemplate." + msg,{ assignmentName: this.data.assignmentName, mappingName: mappingName })});
}, this));
}, this));
},
addMapping: function(e) {
e.preventDefault();
if(mappingName.length) {
this.mappingAction(mappingName, true);
}
},
removeMapping: function(e) {
e.preventDefault();
this.mappingAction(mappingName);
}
});
return new RoleEntitlementsEditView();
});