123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- /*##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/i18n",
- "dojo/i18n!./nls/hpcc",
- "dojo/_base/array",
- "dojo/dom",
- "dojo/dom-form",
- "dojo/on",
- "dijit/registry",
- "dijit/Menu",
- "dijit/MenuItem",
- "dijit/MenuSeparator",
- "dgrid/OnDemandGrid",
- "dgrid/Keyboard",
- "dgrid/Selection",
- "dgrid/selector",
- "dgrid/extensions/ColumnResizer",
- "dgrid/extensions/DijitRegistry",
- "hpcc/_TabContainerWidget",
- "hpcc/ws_access",
- "hpcc/ESPUtil",
- "hpcc/UserDetailsWidget",
- "hpcc/GroupDetailsWidget",
- "dojo/text!../templates/UserQueryWidget.html",
- "dijit/layout/BorderContainer",
- "dijit/layout/TabContainer",
- "dijit/layout/ContentPane",
- "dijit/Toolbar",
- "dijit/form/Form",
- "dijit/form/Button",
- "dijit/form/DropDownButton",
- "dijit/form/ValidationTextBox",
- "dijit/ToolbarSeparator",
- "dijit/form/TextBox",
- "dijit/Dialog",
- "dojox/form/PasswordValidator",
- "hpcc/TableContainer"
- ], function (declare, lang, i18n, nlsHPCC, arrayUtil, dom, domForm, on,
- registry, Menu, MenuItem, MenuSeparator,
- OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
- _TabContainerWidget, WsAccess, ESPUtil, UserDetailsWidget, GroupDetailsWidget,
- template) {
- return declare("UserQueryWidget", [_TabContainerWidget], {
- templateString: template,
- baseClass: "UserQueryWidget",
- i18n: nlsHPCC,
- usersTab: null,
- usersGrid: null,
- postCreate: function (args) {
- this.inherited(arguments);
- this.addGroupForm = registry.byId(this.id + "AddGroupForm");
- this.groupsTab = registry.byId(this.id + "_Groups");
- this.addUserForm = registry.byId(this.id + "AddUserForm");
- this.usersTab = registry.byId(this.id + "_Users");
- },
- // Hitched actions ---
- // Groups ---
- _onRefreshGroups: function () {
- this.refreshGroupsGrid();
- },
- _onEditGroup: function (event) {
- var selections = this.groupsGrid.getSelected();
- var firstTab = null;
- for (var i = selections.length - 1; i >= 0; --i) {
- var tab = this.ensureGroupPane(this.id + "_Group" + selections[i].name, {
- Name: selections[i].name
- });
- if (i == 0) {
- firstTab = tab;
- }
- }
- if (firstTab) {
- this.selectChild(firstTab);
- }
- },
- _onDeleteGroup: function (params) {
- if (confirm(this.i18n.DeleteSelectedGroups)) {
- var selections = this.groupsGrid.getSelected();
- var request = {
- ActionType: "delete"
- };
- arrayUtil.forEach(selections, function (item, idx) {
- request["groupnames_i" + idx] = item.name;
- }, this);
- var context = this;
- WsAccess.GroupAction({
- request: request
- }).then(function (response) {
- context.refreshGroupsGrid(true);
- });
- }
- },
- _onGroupsRowDblClick: function (name) {
- var groupTab = this.ensureGroupPane(this.id + "_Group" + name, {
- Name: name
- });
- this.selectChild(groupTab);
- },
- _onAddGroupSubmit: function () {
- if (this.addGroupForm.validate()) {
- var context = this;
- var request = domForm.toObject(this.addGroupForm.id);
- WsAccess.GroupAdd({
- request: request
- }).then(function (response) {
- context.refreshGroupsGrid();
- });
- registry.byId(this.id + "AddGroupsDropDown").closeDropDown();
- }
- },
- // Users ---
- _onRefreshUsers: function () {
- this.refreshUsersGrid();
- },
- _onEditUser: function (event) {
- var selections = this.usersGrid.getSelected();
- var firstTab = null;
- for (var i = selections.length - 1; i >= 0; --i) {
- var tab = this.ensureUserPane(this.id + "_User" + selections[i].username, {
- Username: selections[i].username,
- Fullname: selections[i].fullname,
- Passwordexpiration: selections[i].passwordexpiration
- });
- if (i == 0) {
- firstTab = tab;
- }
- }
- if (firstTab) {
- this.selectChild(firstTab);
- }
- },
- _onDeleteUser: function (params) {
- var selections = this.usersGrid.getSelected();
- if (confirm(this.i18n.DeleteSelectedUsers)) {
- request = {
- ActionType: "delete"
- };
- arrayUtil.forEach(selections, function (item, idx) {
- request["usernames_i" + idx] = item.username;
- }, this);
- var context = this;
- WsAccess.UserAction({
- request: request
- }).then(function (response) {
- context.refreshUsersGrid(true);
- });
- }
- },
- _onUsersRowDblClick: function (username, fullname, passwordexpiration) {
- var userTab = this.ensureUserPane(this.id + "_" + username, {
- Username: username,
- Fullname: fullname,
- Passwordexpiration: passwordexpiration
- });
- this.selectChild(userTab);
- },
- _onSubmitAddUserDialog: function (event) {
- if (this.addUserForm.validate()) {
- var context = this;
- var request = domForm.toObject(this.addUserForm.id);
- lang.mixin(request, {
- password1: request.password,
- password2: request.password
- })
- WsAccess.AddUser({
- request: request
- }).then(function (response) {
- context.refreshUsersGrid();
- });
- registry.byId(this.id + "AddUsersDropDown").closeDropDown();
- }
- },
- // Implementation ---
- init: function (params) {
- if (this.inherited(arguments))
- return;
- this.initGroupsGrid();
- this.initUsersGrid();
- this.refreshActionState();
- },
- // Groups ---
- initGroupsGrid: function () {
- this.initGroupsContextMenu();
- var store = WsAccess.CreateGroupsStore();
- this.groupsGrid = declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
- allowSelectAll: true,
- deselectOnRefresh: false,
- store: store,
- columns: {
- check: selector({
- width: 27,
- label: " "
- }, "checkbox"),
- name: {
- label: this.i18n.GroupName
- }
- },
- }, this.id + "GroupsGrid");
- this.groupsGrid.noDataMessage = "<span class='dojoxGridNoData'>" + this.i18n.noDataMessage + "</span>";
- var context = this;
- on(document, ".WuidClick:click", function (evt) {
- if (context._onGroupsRowDblClick) {
- var item = context.groupsGrid.row(evt).data;
- context._onGroupsRowDblClick(item.name);
- }
- });
- this.groupsGrid.on(".dgrid-row:dblclick", function (evt) {
- if (context._onGroupsRowDblClick) {
- var item = context.groupsGrid.row(evt).data;
- context._onGroupsRowDblClick(item.name);
- }
- });
- this.groupsGrid.onSelectionChanged(function (event) {
- context.refreshActionState();
- });
- this.groupsGrid.onContentChanged(function (event) {
- context.refreshActionState();
- });
- this.groupsGrid.startup();
- },
- initGroupsContextMenu: function () {
- var context = this;
- var pMenu = new Menu({
- targetNodeIds: [this.id + "GroupsGrid"]
- });
- pMenu.addChild(new MenuItem({
- label: this.i18n.Add,
- onClick: function (args) {
- registry.byId(context.id + "AddGroupsDropDown").openDropDown();
- }
- }));
- pMenu.addChild(new MenuItem({
- label: this.i18n.Edit,
- onClick: function (args) { context._onEditGroup(); }
- }));
- pMenu.addChild(new MenuItem({
- label: this.i18n.Delete,
- onClick: function (args) { context._onDeleteGroup(); }
- }));
- pMenu.addChild(new MenuSeparator());
- pMenu.addChild(new MenuItem({
- label: this.i18n.Refresh,
- onClick: function (args) { context._onRefreshGroups(); }
- }));
- },
- refreshGroupsGrid: function (clearSelection) {
- this.groupsGrid.set("query", {
- id: "*"
- });
- if (clearSelection) {
- this.groupsGrid.clearSelection();
- }
- },
- ensureGroupPane: function (id, params) {
- var retVal = registry.byId(id);
- if (!retVal) {
- retVal = new GroupDetailsWidget({
- id: id,
- title: params.Name,
- closable: true,
- params: params
- });
- this.addChild(retVal, 2);
- }
- return retVal;
- },
- // Users ---
- initUsersGrid: function () {
- this.initUsersContextMenu();
- var store = WsAccess.CreateUsersStore();
- this.usersGrid = declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
- allowSelectAll: true,
- deselectOnRefresh: false,
- store: store,
- columns: {
- check: selector({
- width: 27,
- label: " "
- },"checkbox"),
- username: {
- width: 180,
- label: this.i18n.Username
- },
- fullname: {
- label: this.i18n.FullName
- },
- passwordexpiration: {
- width: 180,
- label: this.i18n.PasswordExpiration
- }
- },
- }, this.id + "UsersGrid");
- this.usersGrid.noDataMessage = "<span class='dojoxGridNoData'>" + this.i18n.noDataMessage + "</span>";
- var context = this;
- on(document, ".WuidClick:click", function (evt) {
- if (context._onUsersRowDblClick) {
- var item = context.usersGrid.row(evt).data;
- context._onUsersRowDblClick(item.username,item.fullname,item.passwordexpiration);
- }
- });
- this.usersGrid.on(".dgrid-row:dblclick", function (evt) {
- if (context._onUsersRowDblClick) {
- var item = context.usersGrid.row(evt).data;
- context._onUsersRowDblClick(item.username,item.fullname,item.passwordexpiration);
- }
- });
- this.usersGrid.onSelectionChanged(function (event) {
- context.refreshActionState();
- });
- this.usersGrid.onContentChanged(function (event) {
- context.refreshActionState();
- });
- this.usersGrid.startup();
- },
- initUsersContextMenu: function () {
- var context = this;
- var pMenu = new Menu({
- targetNodeIds: [this.id + "UsersGrid"]
- });
- pMenu.addChild(new MenuItem({
- label: this.i18n.Add,
- onClick: function (args) {
- registry.byId(context.id + "AddUsersDropDown").openDropDown();
- }
- }));
- pMenu.addChild(new MenuItem({
- label: this.i18n.Edit,
- onClick: function (args) { context._onEditUser(); }
- }));
- pMenu.addChild(new MenuItem({
- label: this.i18n.Delete,
- onClick: function (args) { context._onDeleteUser(); }
- }));
- pMenu.addChild(new MenuSeparator());
- pMenu.addChild(new MenuItem({
- label: this.i18n.Refresh,
- onClick: function (args) { context._onRefreshUsers(); }
- }));
- },
- ensureUserPane: function (id, params) {
- var retVal = registry.byId(id);
- if (!retVal) {
- retVal = new UserDetailsWidget({
- id: id,
- title: params.Username,
- closable: true,
- params: params
- });
- this.addChild(retVal, 2);
- }
- return retVal;
- },
- refreshUsersGrid: function (clearSelection) {
- this.usersGrid.set("query",{
- id: "*"
- });
- if (clearSelection) {
- this.usersGrid.clearSelection();
- }
- },
- // --- ---
- initTab: function () {
- var currSel = this.getSelectedChild();
- if (currSel && !currSel.initalized) {
- if (currSel.id === this.groupsTab.id) {
- } else if (currSel.id === this.usersTab.id) {
- } else {
- if (!currSel.initalized) {
- currSel.init(currSel.params);
- }
- }
- }
- },
- refreshActionState: function () {
- var userSelection = this.usersGrid.getSelected();
- var hasUserSelection = userSelection.length;
- registry.byId(this.id + "EditUsers").set("disabled", !hasUserSelection);
- registry.byId(this.id + "DeleteUsers").set("disabled", !hasUserSelection);
- var groupSelection = this.groupsGrid.getSelected();
- var hasGroupSelection = groupSelection.length;
- registry.byId(this.id + "EditGroups").set("disabled", !hasGroupSelection);
- registry.byId(this.id + "DeleteGroups").set("disabled", !hasGroupSelection);
- }
- });
- });
|