ConfigDelegate.js revision e26e5073e1266868172d72453c97f413fe2fb603
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/**
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Copyright (c) 2011-2012 ForgeRock AS. All rights reserved.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * The contents of this file are subject to the terms
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * of the Common Development and Distribution License
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * (the License). You may not use this file except in
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * compliance with the License.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * You can obtain a copy of the License at
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * http://forgerock.org/license/CDDLv1.0.html
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * See the License for the specific language governing
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * permission and limitations under the License.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * When distributing Covered Code, include this CDDL
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Header Notice in each file and include the License file
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * at http://forgerock.org/license/CDDLv1.0.html
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * If applicable, add the following below the CDDL Header,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * with the fields enclosed by brackets [] replaced by
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * your own identifying information:
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * "Portions Copyrighted [year] [name of copyright owner]"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*global define */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsdefine("org/forgerock/openidm/ui/common/delegates/ConfigDelegate", [
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "jquery",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "underscore",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "org/forgerock/commons/ui/common/util/Constants",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "org/forgerock/commons/ui/common/main/AbstractDelegate",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "org/forgerock/commons/ui/common/main/Configuration",
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "org/forgerock/commons/ui/common/main/EventManager"
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs], function($, _, constants, AbstractDelegate, conf, eventManager) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs var obj = new AbstractDelegate(constants.host + "/openidm/config");
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs obj.serviceCall = function (callParams) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs // we don't want 404 errors to the config store to flash the typical "Not Found" warning to the user,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs // so we override the default 404 behavior with this simple stub handler.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs var defaultErrorsHandlers = {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs "Not found": {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs status: 404
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs };
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs callParams.errorsHandlers = _.extend(callParams.errorsHandlers || {}, defaultErrorsHandlers);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return Object.getPrototypeOf(obj).serviceCall.call(obj,callParams);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs };
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs obj.getConfigList = function(successCallback, errorCallback) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return obj.serviceCall({ url:"", type: "GET", success: successCallback, error: errorCallback});
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs };
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs obj.readEntity = function (id, successCallback, errorCallback) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs var promise = $.Deferred(),
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs clone;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (!conf.delegateCache.config || !conf.delegateCache.config[id]) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (!conf.delegateCache.config) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs conf.delegateCache.config = {};
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return Object.getPrototypeOf(obj).readEntity.call(obj,id, successCallback, errorCallback)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs .then(
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs function (result) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs conf.delegateCache.config[id] = result;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return $.extend(true, {}, result);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs },
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs function () {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs delete conf.delegateCache.config[id];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs });
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs } else {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs clone = $.extend(true, {}, conf.delegateCache.config[id]);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs promise.resolve(clone);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (successCallback) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs successCallback(clone);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return promise;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs };
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs obj.updateEntity = function(id, objectParam, successCallback, errorCallback) {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs return Object.getPrototypeOf(obj).updateEntity.call(obj, id, objectParam, successCallback, errorCallback)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs .always(function () {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs delete conf.delegateCache.config[id];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs });
};
obj.deleteEntity = function(id, successCallback, errorCallback) {
return Object.getPrototypeOf(obj).deleteEntity.call(obj, id, successCallback, errorCallback)
.always(function () {
delete conf.delegateCache.config[id];
});
};
obj.clearDelegateCache = function(id){
if (id) {
delete conf.delegateCache.config[id];
} else {
conf.delegateCache.config = {};
}
};
return obj;
});