ProcessHistoryView.js revision e26e5073e1266868172d72453c97f413fe2fb603
0N/A/**
1879N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
0N/A * Copyright (c) 2015 ForgeRock AS. All rights reserved.
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the License). You may not use this file except in
0N/A * compliance with the License.
0N/A *
0N/A * You can obtain a copy of the License at
0N/A * http://forgerock.org/license/CDDLv1.0.html
0N/A * See the License for the specific language governing
0N/A * permission and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * Header Notice in each file and include the License file
0N/A * at http://forgerock.org/license/CDDLv1.0.html
1472N/A * If applicable, add the following below the CDDL Header,
1472N/A * with the fields enclosed by brackets [] replaced by
1472N/A * your own identifying information:
0N/A * "Portions Copyrighted [year] [name of copyright owner]"
0N/A */
0N/A
1879N/A/*global define */
1879N/A
1879N/Adefine("org/forgerock/openidm/ui/admin/workflow/ProcessHistoryView", [
1879N/A "jquery",
0N/A "underscore",
0N/A "org/forgerock/openidm/ui/admin/util/AdminAbstractView",
0N/A "org/forgerock/openidm/ui/common/delegates/ResourceDelegate",
0N/A "org/forgerock/commons/ui/common/util/UIUtils",
0N/A "org/forgerock/commons/ui/common/main/AbstractModel",
0N/A "org/forgerock/commons/ui/common/main/AbstractCollection",
0N/A "org/forgerock/commons/ui/common/main/EventManager",
0N/A "org/forgerock/commons/ui/common/util/Constants",
0N/A "org/forgerock/openidm/ui/admin/util/BackgridUtils",
0N/A "org/forgerock/commons/ui/common/main/Router",
0N/A "backgrid"
0N/A], function($, _,
0N/A AdminAbstractView,
0N/A ResourceDelegate,
0N/A uiUtils,
0N/A AbstractModel,
0N/A AbstractCollection,
0N/A eventManager,
0N/A constants,
0N/A BackgridUtils,
0N/A router,
0N/A Backgrid) {
0N/A var ProcessHistoryView = AdminAbstractView.extend({
0N/A template: "templates/admin/workflow/ProcessHistoryViewTemplate.html",
0N/A events: {
0N/A "change #processHistoryFilterType" : "filterType"
0N/A },
0N/A model : {
0N/A userFilter: "anyone",
0N/A processTypeFilter: "all"
0N/A },
0N/A element: "#processHistory",
0N/A render: function(args, callback) {
3863N/A this.data.processDefinitions = args[0];
0N/A
0N/A this.parentRender(_.bind(function() {
0N/A var processGrid,
0N/A ProcessModel = AbstractModel.extend({ "url": "/openidm/workflow/processinstance/history" }),
0N/A Process = AbstractCollection.extend({ model: ProcessModel });
1142N/A
0N/A this.model.processes = new Process();
0N/A
0N/A this.model.processes.on('backgrid:sort', function(model) {
0N/A var cid = model.cid,
0N/A filtered = model.collection.filter(function (model) {
1142N/A return model.cid !== cid;
0N/A });
1142N/A
0N/A _.each(filtered, function (model) {
0N/A model.set('direction', null);
0N/A });
0N/A });
0N/A
0N/A this.model.processes.url = "/openidm/workflow/processinstance/history?_queryId=filtered-query&finished=true";
0N/A this.model.processes.state.pageSize = null;
0N/A this.model.processes.state.sortKey = "-startTime";
0N/A
0N/A processGrid = new Backgrid.Grid({
className: "table",
emptyText: $.t("templates.workflows.processes.noCompletedProcesses"),
columns: [
{
name: "processDefinitionResourceName",
label: $.t("templates.workflows.processes.processInstance"),
cell: Backgrid.Cell.extend({
render: function () {
this.$el.html('<a href="#workflow/processinstance/' +this.model.id +'">' +this.model.get("processDefinitionResourceName") +'<small class="text-muted"> (' +this.model.id +')</small></a>');
this.delegateEvents();
return this;
}
}),
sortable: true,
editable: false
},
{
name: "startUserId",
label: $.t("templates.workflows.processes.startedBy"),
cell: "string",
sortable: true,
editable: false
},
{
name: "startTime",
label: $.t("templates.workflows.processes.created"),
cell: BackgridUtils.DateCell("startTime"),
sortable: true,
editable: false
},
{
name: "endTime",
label: "COMPLETED",
cell: BackgridUtils.DateCell("endTime"),
sortable: true,
editable: false
},
{
name: "",
cell: BackgridUtils.ButtonCell([
{
className: "fa fa-pencil grid-icon",
callback: function() {
eventManager.sendEvent(constants.EVENT_CHANGE_VIEW, {route: router.configuration.routes.processInstanceView, args: [this.model.id]});
}
}
]),
sortable: false,
editable: false
}],
collection: this.model.processes
});
this.$el.find("#processHistoryGridHolder").append(processGrid.render().el);
this.model.processes.getFirstPage();
this.$el.find("#processHistoryAssignedTo").selectize({
valueField: '_id',
labelField: 'userName',
searchField: ["userName","givenName", "sn"],
create: false,
preload: true,
onChange: _.bind(function(value) {
this.model.userFilter = value;
this.reloadGrid();
},this),
render : {
item: function(item, escape) {
var username = '<small class="text-muted"> (' +escape(item.userName) +')</small>';
if(item._id === "anyone") {
username = '';
}
return '<div>' +
'<span class="user-title">' +
'<span class="user-fullname">' + escape(item.givenName) +' ' +escape(item.sn) + '</span>' +
username +
'</span>' +
'</div>';
},
option: function(item, escape) {
var username = '<small class="text-muted"> (' +escape(item.userName) +')</small>';
if(item._id === "anyone") {
username = "";
}
return '<div>' +
'<span class="user-title">' +
'<span class="user-fullname">' + escape(item.givenName) +' ' +escape(item.sn) + '</span>' +
username +
'</span>' +
'</div>';
}
},
load: _.bind(function(query, callback) {
var queryFilter;
if (!query.length) {
queryFilter = "userName sw \"\" &_pageSize=10";
} else {
queryFilter = "givenName sw \"" +query +"\" or sn sw \"" +query +"\" or userName sw \"" +query +"\"";
}
ResourceDelegate.searchResource(queryFilter, "managed/user").then(function(search) {
callback(search.result);
},
function(){
callback();
}
);
}, this)
});
this.$el.find("#processHistoryAssignedTo")[0].selectize.addOption({
_id : "anyone",
userName: "Anyone",
givenName : "Anyone",
sn : ""
});
this.$el.find("#processHistoryAssignedTo")[0].selectize.setValue("anyone", true);
if(callback) {
callback();
}
}, this));
},
filterType : function(event) {
this.model.processTypeFilter = $(event.target).val();
this.reloadGrid();
},
reloadGrid: function() {
var filterString = "_queryId=filtered-query&finished=true";
if(this.model.userFilter !== "anyone") {
filterString = filterString +"&startUserId=" + this.model.userFilter;
if(this.model.processTypeFilter !== "all") {
filterString = filterString + "&processDefinitionKey=" +this.model.processTypeFilter;
}
} else if (this.model.processTypeFilter !== "all") {
filterString = filterString + "&processDefinitionKey=" + this.model.processTypeFilter;
}
this.model.processes.url = "/openidm/workflow/processinstance/history?" + filterString;
this.model.processes.getFirstPage();
}
});
return new ProcessHistoryView();
});