EditConnectorView.js revision 450b61c67b9e44df8df53d6dc501d5263f098e97
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 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, $, _, Handlebars, form2js, window */
], function(AbstractConnectorView,
uiUtils) {
events: {
"change #connectorType" : "loadConnectorTemplate",
"onValidate": "onValidate",
"click #connectorForm fieldset legend" : "sectionHideShow",
"click #updateObjectTypes" : "objectTypeFormSubmit",
"click #updateSync" : "syncFormSubmit",
"click .addLiveSync" : "addLiveSync",
"customValidate": "customValidate",
"click .edit-objectType" : "editObjectType",
"click .delete-objectType" : "deleteObjectType",
"click #addObjectType" : "addObjectType",
"change #selectObjectConfig" : "changeObjectTypeConfig",
"change .retryOptions": "retryOptionChanged",
"change .maxRetries" : "pendingSyncChangesCheck",
"change .postRetryAction": "postRetryActionChange",
"change #connectorForm :input" : "connectorChangesCheck",
"keypress #connectorForm :input" : "connectorFlowCheck",
"paste #connectorForm :input" : "connectorFlowCheck"
},
data: {
},
"org.forgerock.openicf.connectors.ldap-connector" : [
{
"displayName" : "Saved Configuration",
"fileName" : "savedConfig",
"type": "ldap"
},
{
"displayName" : "AD LDAP Configuration",
"fileName" : "provisioner.openicf-adldap",
"type": "ldap"
},
{
"displayName" : "ADLDS LDAP Configuration",
"fileName" : "provisioner.openicf-adldsldap",
"type": "ldap"
},
{
"displayName" : "DJ LDAP Configuration",
"fileName" : "provisioner.openicf-ldap",
"type": "ldap"
},
{
"displayName" : "Full LDAP Configuration",
"fileName" : "fullConfig",
"type": "ldap"
},
{
"displayName" : "IBM LDAP Configuration",
"fileName" : "provisioner.openicf-racfldap",
"type": "ldap"
}
]
},
connectorTypeRef: null,
connectorList: null,
oAuthConnector: false,
this.data = {};
this.data.versionDisplay = {};
this.data.currentMainVersion = null;
this.data.objectTypes = null;
this.oAuthConnector = false;
this.connectorTypeRef = null;
this.connectorList = null;
this.postActionBlockScript = null;
this.name = null;
this.addedLiveSyncSchedules = [];
this.connectorTypeRef = null;
this.userDefinedObjectTypes = null;
//Get available list of connectors
$.when(ConnectorDelegate.availableConnectors(), connectorUtils.getIconList()).then(_.bind(function(connectors, iconList){
//Build Connector type selection
.groupBy( function(connectorRef) {
return connectorRef.displayName;
})
.pairs()
.sortBy(function(connectorRef) {
return connectorRef[0];
})
.map(function(connectorRef){
return {
};
})
.value();
//Get current connector details
ConfigDelegate.readEntity(this.data.systemType +"/" + this.data.connectorId).then(_.bind(function(data){
var tempVersion;
this.currentObjectTypeLoaded = "savedConfig";
//Store in memory version of connector details. This is to ensure we can move around tabs and keep the correct data state.
this.connectorDetails = data;
//Build a version object
return v;
}, this);
}, this);
//Filter down to the current edited connector Type
}, this);
//Filter the connector types down to the current major version
this.data.versionDisplay[0].versions = _.filter(this.data.versionDisplay[0].versions, function(version){
}, this);
//Get the connector type for top header display
//OAuth branch
this.connectorTypeRef = ConnectorRegistry.getConnectorModule(this.data.connectorTypeName + "_" +this.data.currentMainVersion);
this.connectorTypeRef.setToken(tokenDetails, data, this.data.systemType + "/" +this.data.connectorId, urlArgs);
}, this));
} else {
this.parentRender(_.bind(function () {
//Sync settings
case 0:
break;
case -1:
break;
default:
break;
}
this.warningMessageCheck();
}
"eventName": "",
"deleteElement": false,
});
} else if (data.syncFailureHandler) {
}
//set validation for the connector form
//alert if a connector is currently set to a bundle version that doesn't exist
if (this.data.rangeFound) {
this.$el.find("#connectorWarningMessage .message").append('<div class="pending-changes connector-version">' +$.t("config.messages.ConnectorMessages.connectorVersionChange", {"range": this.data.oldVersion, "version": data.connectorRef.bundleVersion}) +'</div>');
}
//Get connector template
this.connectorTypeRef = ConnectorRegistry.getConnectorModule(this.data.connectorTypeName + "_" + this.data.currentMainVersion);
//Determine if the template is OAuth
if (this.connectorTypeRef.oAuthConnector) {
this.oAuthConnector = true;
} else {
this.oAuthConnector = false;
}
//Render the connector template / details
this.connectorTypeRef.render({"connectorType": this.data.connectorTypeName + "_" + this.data.currentMainVersion,
"animate": true,
"connectorDefaults": data,
_.bind(function () {
//Set the current newest version incase there is a range
this.connectorTypeRef.data.connectorDefaults.connectorRef.bundleVersion = data.connectorRef.bundleVersion;
this.setSubmitFlow();
if (callback) {
callback();
}
}, this));
this.setupLiveSync();
}, this));
}
}, this));
}, this));
},
connectorFlowCheck: function() {
if(this.oAuthConnector) {
this.setSubmitFlow();
}
},
//Saves the connector tab
connectorFormSubmit: function(event) {
var mergedResult = this.getProvisioner();
//Checks for connector specific save function to do any additional changes to data
if(this.connectorTypeRef.connectorSaved) {
}
ConfigDelegate.updateEntity(this.data.systemType + "/" + this.data.connectorId, mergedResult).then(_.bind(function () {
this.connectorDetails = mergedResult;
this.warningMessageCheck();
}, this));
}, this));
},
//Saves the sync tab
syncFormSubmit: function() {
this.connectorDetails.syncFailureHandler.maxRetries = parseInt(syncData.syncFailureHandler.maxRetries, 10);
this.connectorDetails.syncFailureHandler.postRetryAction = syncData.syncFailureHandler.postRetryAction;
this.connectorDetails.syncFailureHandler.postRetryAction = {"script": this.postActionBlockScript.generateScript()};
}
ConfigDelegate.updateEntity(this.data.systemType + "/" + this.data.connectorId, this.connectorDetails).then(_.bind(function () {
this.warningMessageCheck();
}, this));
},
//Saves the object type tab
objectTypeFormSubmit: function() {
if(!this.userDefinedObjectTypes) {
}
ConfigDelegate.updateEntity(this.data.systemType + "/" + this.data.connectorId, this.connectorDetails).then(_.bind(function () {
this.previousObjectType = this.userDefinedObjectTypes;
this.warningMessageCheck();
}, this));
},
//will hide warning message if no messages left
warningMessageCheck: function() {
}
},
addLiveSync: function(schedule) {
"defaults": {
"enabled" : true,
"persisted" : true
},
"invokeService": "provisioner",
"newSchedule": true
});
}
}
},
setupLiveSync: function() {
var tempName = "",
sourcePieces = [];
this.updateLiveSyncObjects();
// Get all schedule IDS
var schedulerPromises = [];
// Get the schedule of each ID
}, this);
//////////////////////////////////////////////////////////////////////////////////////////////////
// //
// TODO: Use queryFilters to avoid having to pull back all schedules and sifting through them. //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////
"defaults": {
},
});
}
}
}, this);
} else {
}
}, this));
}, this));
if (!this.postActionBlockScript) {
"eventName": "",
"deleteElement": false
});
}
},
updateLiveSyncObjects: function() {
var objectTypes = [];
if (this.name) {
}, this);
} else {
}, this);
}
// For each schedule on the page
// The schedule is not included in the livesync source list
}
}, this);
// For each possible liveSync
// The source is not scheduled add it to dropdown
}
}, this);
} else {
}
} else {
}
},
this.updateLiveSyncObjects();
},
retryOptionChanged: function() {
case "0":
break;
case "-1":
break;
case "*":
break;
}
this.pendingSyncChangesCheck();
},
postRetryActionChange: function() {
} else {
}
this.pendingSyncChangesCheck();
},
pendingSyncChangesCheck: function() {
this.$el.find("#connectorWarningMessage .message").append('<div class="pending-changes sync-pending">' +$.t("templates.connector.pendingSync") +'</div>');
}
},
connectorChangesCheck: function() {
this.$el.find("#connectorWarningMessage .message").append('<div class="pending-changes connector-pending">' +$.t("templates.connector.pendingConnectorChanges") +'</div>');
}
},
//This function is to find the newest version of a connector and select it if a user provides a range
versionRangeCheck: function(version) {
var cleanVersion = null,
//Checks to see if there is a range
if(version.indexOf("(") !== -1 || version.indexOf(")") !== -1 || version.indexOf("[") !== -1 || version.indexOf("]") !== -1) {
} else {
if (cleanVersion === null) {
} else {
//Parse float is used to convert the returned string version to a number to allow basic comparison of greater / lesser value
}
}
}
}, this);
}
this.data.rangeFound = true;
} else {
this.data.rangeFound = false;
}
return cleanVersion;
},
//Returns the current provisioner based on a merged copy of the connector defaults and what was set in the template by the user
getProvisioner: function() {
var connectorData,
mergedResult = {},
arrayComponents = $(".connector-array-component");
if(this.connectorTypeRef.getGenericState()) {
delete connectorData.root;
}
connectorData.enabled = true;
} else {
connectorData.enabled = false;
}
delete connectorData.connectorType;
connectorData.objectTypes = {};
//Added logic to ensure array parts correctly add and delete what is set
mergedResult.configurationProperties[tempKeys[0]] = tempArrayObject.configurationProperties[tempKeys[0]];
}
}, this);
return mergedResult;
},
//Renders the object type table
renderObjectTypes: function(newObjectTypes) {
this.userDefinedObjectTypes = newObjectTypes;
+ "<td><button class='btn btn-link edit-objectType'><i class='fa fa-pencil'></i></button>"
+ "<button class='btn btn-link delete-objectType'><i class='fa fa-times'></i></button></td></tr>");
}, this));
this.updateLiveSyncObjects();
this.$el.find("#connectorWarningMessage .message").append('<div class="pending-changes objecttype-pending">' +$.t("templates.connector.pendingObjectTypes") +'</div>');
}
},
//Since we are using tab panels we need custom validate to correctly enable / disable the connector submit
customValidate: function() {
} else {
}
},
//When clicking the pencil for an object type
editObjectType: function(event) {
objectTypesDialog.render(this.userDefinedObjectTypes || this.data.objectTypes, objectTypeName, this.getProvisioner(), _.bind(this.renderObjectTypes, this));
},
//When clicking the delete icon for an object type
deleteObjectType: function(event){
if(!this.userDefinedObjectTypes) {
}
delete this.userDefinedObjectTypes[objectTypeName];
this.renderObjectTypes(this.userDefinedObjectTypes);
},
//When adding a new object type
addObjectType: function() {
objectTypesDialog.render(this.userDefinedObjectTypes || this.data.objectTypes, null, this.getProvisioner(), _.bind(this.renderObjectTypes, this));
},
//Used when an object type template selector is available.
changeObjectTypeConfig: function(event) {
if(!this.userDefinedObjectTypes) {
}
if(value === "fullConfig") {
}, this), _.bind(function () {
}, this)
);
} else if(value === "savedConfig") {
if(this.previousObjectType) {
this.renderObjectTypes(this.previousObjectType);
}
} else {
}, this), _.bind(function () {
}, this)
);
}
this.currentObjectTypeLoaded = value;
}, this), "330px");
}
});
return new AddEditConnectorView();
});