9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne/**
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * The contents of this file are subject to the terms of the Common Development and
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * Distribution License (the License). You may not use this file except in compliance with the
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * License.
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne *
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * specific language governing permission and limitations under the License.
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne *
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * When distributing Covered Software, include this CDDL Header Notice in each file and include
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * Header, with the fields enclosed by brackets [] replaced by your own identifying
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * information: "Portions copyright [year] [name of copyright owner]".
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne *
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * Copyright 2015 ForgeRock AS.
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne */
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne/*global define, window */
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.brownedefine("org/forgerock/openidm/ui/admin/dashboard/widgets/ResourceListWidget", [
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "jquery",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "underscore",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "bootstrap",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "org/forgerock/commons/ui/common/main/AbstractView",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "org/forgerock/openidm/ui/admin/delegates/SyncDelegate",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "org/forgerock/openidm/ui/admin/delegates/ConnectorDelegate",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "org/forgerock/openidm/ui/common/delegates/ConfigDelegate",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne "org/forgerock/openidm/ui/admin/util/ConnectorUtils"
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne], function($, _, bootstrap,
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne AbstractView,
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne SyncDelegate,
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne ConnectorDelegate,
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne ConfigDelegate,
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne ConnectorUtils) {
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne var widgetInstance = {},
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne Widget = AbstractView.extend({
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne noBaseTemplate: true,
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne template: "templates/admin/dashboard/widgets/ResourceListWidgetTemplate.html",
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne render: function(args, callback) {
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne var tempIconClass;
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne this.element = args.element;
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne $.when(SyncDelegate.mappingDetails(),
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne ConnectorDelegate.currentConnectors(),
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne ConfigDelegate.readEntity("managed"),
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne ConnectorUtils.getIconList()).then(
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne _.bind(function (sync, connectors, managedObjects, iconList) {
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne _.each(connectors, _.bind(function(connector){
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne tempIconClass = ConnectorUtils.getIcon(connector.connectorRef.connectorName, iconList);
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne connector.iconClass = tempIconClass.iconClass;
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne connector.iconSrc = tempIconClass.src;
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne }, this));
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne sync.mappings = _.sortBy(_.sortBy(sync.mappings, 'name'));
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne this.data.mappings = sync.mappings.slice(0, 4);
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne connectors = _.sortBy(_.sortBy(connectors, 'displayName'));
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne this.data.connectors = connectors.slice(0, 4);
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne managedObjects.objects = _.sortBy(_.sortBy(managedObjects.objects, 'name'));
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne this.data.managedObjects = managedObjects.objects.slice(0, 4);
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne this.parentRender(_.bind(function(){
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne if(callback) {
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne callback();
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne }
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne }, this));
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne }, this));
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne }
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne });
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne widgetInstance.generateWidget = function(loadingObject, callback) {
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne var widget = {};
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne $.extend(true, widget, new Widget());
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne widget.render(loadingObject, callback);
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne return widget;
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne };
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne return widgetInstance;
9ef3a0e80a4e67fde2d24364ad9a7d5d64654f19jason.browne});