PropertiesView.js revision 620268d6c2c779a8b2c676f276680021144b532f
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * Copyright (c) 2014 ForgeRock AS. All rights reserved.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * The contents of this file are subject to the terms
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * of the Common Development and Distribution License
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * (the License). You may not use this file except in
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * compliance with the License.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * You can obtain a copy of the License at
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * See the License for the specific language governing
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * permission and limitations under the License.
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * When distributing Covered Code, include this CDDL
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * Header Notice in each file and include the License file
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * If applicable, add the following below the CDDL Header,
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * with the fields enclosed by brackets [] replaced by
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * your own identifying information:
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows * "Portions Copyrighted [year] [name of copyright owner]"
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows/*global define, $, _, Handlebars, form2js */
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows/*jslint evil: true */
749f21d359d8fbd020c974a1a5227316221bfc9cwesolowsdefine("org/forgerock/openidm/ui/admin/mapping/PropertiesView", [
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "org/forgerock/openidm/ui/admin/util/AdminAbstractView",
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "org/forgerock/commons/ui/common/main/EventManager",
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "org/forgerock/commons/ui/common/main/Configuration",
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "org/forgerock/openidm/ui/admin/delegates/SessionStorageDelegate"
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows ], function(AbstractView, eventManager, conf, UIUtils, constants, sessionStorageDelegate) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows template: "templates/admin/mapping/PropertiesTemplate.html",
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows addProperty: function (e) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows eventManager.sendEvent(constants.ROUTE_REQUEST, {routeName: "addMappingProperty", args: [this.parent.currentMapping().name]});
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows removeProperty: function (e) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows UIUtils.jqConfirm($.t("templates.mapping.confirmRemoveProperty",{property: $(e.target).attr('target')}),_.bind(function(){
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows var mapProps = sessionStorageDelegate.get(this.parent.currentMapping().name + "_Properties") || this.data.mapProps;
2d2a52253051eb056ca017546a076c0f585283f2stephh sessionStorageDelegate.set(this.parent.currentMapping().name + "_Properties",_.reject(mapProps, function (p) { return p.target === $(e.target).attr('target'); }));
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows eventManager.sendEvent(constants.ROUTE_REQUEST, {routeName: "editMappingProperty", args: [this.parent.currentMapping().name, id]});
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows mapProps = sessionStorageDelegate.get(this.parent.currentMapping().name + "_Properties") || sessionStorageDelegate.get("currentMapping").properties,
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if(typeof(prop.condition) === "object" && prop.condition.type === "text/javascript" &&
2d2a52253051eb056ca017546a076c0f585283f2stephh if(!eval(prop.condition.source) && prop.condition.source.length > 0){
2d2a52253051eb056ca017546a076c0f585283f2stephh } catch (e) {
2d2a52253051eb056ca017546a076c0f585283f2stephh if (typeof(prop.transform) === "object" && prop.transform.type === "text/javascript" &&
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows typeof (prop.transform.source) === "string" && sampleData === null) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if (typeof(prop.source) !== "undefined" && prop.source.length) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows sampleData = eval(prop.transform.source); // references to "source" variable expected within this string
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows } catch (err) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if (typeof(prop.source) !== "undefined" && prop.source.length) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows } else if (typeof(prop.source) !== "undefined" && prop.source.length) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if(sampleData === null){
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if (typeof(prop["default"]) !== "undefined" && prop["default"].length) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if (sampleData === null || sampleData === undefined) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "target": Handlebars.Utils.escapeExpression(prop.target),
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "source": Handlebars.Utils.escapeExpression(sourceProp),
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "script": Handlebars.Utils.escapeExpression(script),
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "sample": Handlebars.Utils.escapeExpression(decodeURIComponent((sampleData || ""))),
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows /*if (!$("#findSampleUser").hasClass("ui-autocomplete-input")) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows $("#findSampleUser").autocomplete({
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows delay: 500,
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows minLength: 2,
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows select: function (event, ui) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows conf.globalData.sampleSource = ui.item;
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows sampleSource = ui.item;
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows $("#findSampleUser").val(ui.item.cn);
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows $('#mappingTable').jqGrid('setGridParam', {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows datatype: 'local',
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows data: gridFromMapProps(mapProps)
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows }).trigger('reloadGrid');
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return false;
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows source: function (request, response) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows searchDelegate.searchResults("account", "cn", request.term).always(response);
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows }).data( "ui-autocomplete" )._renderItem = function (ul, item) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return $( "<li>" )
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows .append( "<a>" + Handlebars.Utils.escapeExpression(item.cn) + "<br>" + Handlebars.Utils.escapeExpression(item.sAMAccountName) + " / " + Handlebars.Utils.escapeExpression(item.mail) + "</a>" )
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows .appendTo( ul );
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows //$('#mappingTable').after('<div id="mappingTable_pager"></div>');
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "title": false,
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return (!required) ? '<button target="' + row.target + '" type="button" title="' + $.t("common.form.removeAttribute") + ': ' + row.target + '" class="glyph-icon glyph-icon-minus-sign removePropertyBtn" style="margin-top:4px;"> </button>' : '';
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "key": true
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return (def.length > 0) ? '<span class="attrTabBtn" style="cursor:pointer;" rowId="' + opt.rowId + '" tab="default">' + def + '</span>' : '';
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return (script.length > 0) ? '<span class="attrTabBtn" style="cursor:pointer;" rowId="' + opt.rowId + '" tab="transform">' + script + '</span>' : '';
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows "title": false,
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return (hasConditionScript) ? '<button class="glyph-icon glyph-icon-filter attrTabBtn" style="height:17px;margin-bottom:4px;" rowId="' + opt.rowId + '" title="' + $.t('templates.mapping.conditionScriptApplied') + '" tab="condition"> </button>' : '';
2d2a52253051eb056ca017546a076c0f585283f2stephh "name": "sample",
2d2a52253051eb056ca017546a076c0f585283f2stephh "label": "Sample",
2d2a52253051eb056ca017546a076c0f585283f2stephh "width": "175px"
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows eventManager.sendEvent(constants.ROUTE_REQUEST, {routeName: "editMappingProperty", args: [_this.parent.currentMapping().name, id]});
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows //this prevents the row from being selected if the remove button is clicked
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if (e.target.tagName.toUpperCase() === "BUTTON" || btn.length > 0) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return false;
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows return true;
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows $('#mappingTable').addRowData("blankRow", {"required":true,"target":$.t("templates.mapping.noPropertiesMapped"), "default":"", "script":"", "hasConditionScript":false});
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows _this.parent.$el.find("#findSampleSource").parent().hide();
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows availableProps = sessionStorageDelegate.get(this.parent.currentMapping().name + "_AvailableObjects").target.properties || [];
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows if(!availableProps.length || _.difference(availableProps,_.pluck(_this.data.mapProps,"target")).length) {
749f21d359d8fbd020c974a1a5227316221bfc9cwesolows _this.$el.find('.addProperty').removeProp('disabled');