123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- /*##############################################################################
- # 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/common",
- "dojo/i18n!./nls/GridDetailsWidget",
- "dojo/store/Memory",
- "dojo/store/Observable",
- "dijit/registry",
- "dijit/Menu",
- "dijit/MenuItem",
- "dijit/MenuSeparator",
- "dijit/PopupMenuItem",
- "hpcc/_TabContainerWidget",
- "dojo/text!../templates/GridDetailsWidget.html",
- "dijit/layout/TabContainer",
- "dijit/layout/BorderContainer",
- "dijit/Toolbar",
- "dijit/form/Button",
- "dijit/ToolbarSeparator",
- "dijit/layout/ContentPane"
- ], function (declare, lang, i18n, nlsCommon, nlsSpecific, Memory, Observable,
- registry, Menu, MenuItem, MenuSeparator, PopupMenuItem,
- _TabContainerWidget,
- template) {
- return declare("GridDetailsWidget", [_TabContainerWidget], {
- templateString: template,
- baseClass: "GridDetailsWidget",
- i18n: lang.mixin(nlsCommon, nlsSpecific),
- gridTitle: "Change Me",
- idProperty: "Change Me",
- store: null,
- toolbar: null,
- gridTab: null,
- grid: null,
- contextMenu: null,
- postCreate: function (args) {
- this.inherited(arguments);
- this.toolbar = registry.byId(this.id + "Toolbar");
- this.gridTab = registry.byId(this.id + "_Grid");
- },
- startup: function (args) {
- this.inherited(arguments);
- this.initGrid();
- this.initContextMenu();
- },
- // Hitched actions ---
- _onRefresh: function (event) {
- this.refreshGrid();
- },
- _onOpen: function (event, params) {
- var selections = this.grid.getSelected();
- var firstTab = null;
- for (var i = 0; i < selections.length; ++i) {
- var tab = this.ensurePane(selections[i], params);
- if (i == 0) {
- firstTab = tab;
- }
- }
- if (firstTab) {
- this.selectChild(firstTab);
- }
- },
- _onRowDblClick: function (row) {
- var tab = this.ensurePane(row);
- this.selectChild(tab);
- },
- // Implementation ---
- initGrid: function() {
- var context = this;
- var store = new Memory({
- idProperty: this.idProperty,
- data: []
- });
- this.store = Observable(store);
- this.grid = this.createGrid(this.id + "Grid");
- this.grid.on(".dgrid-row:dblclick", function (evt) {
- if (context._onRowDblClick) {
- var row = context.grid.row(evt).data;
- context._onRowDblClick(row);
- }
- });
- this.grid.on(".dgrid-row:contextmenu", function (evt) {
- if (context._onRowContextMenu) {
- }
- });
- this.grid.onSelectionChanged(function (event) {
- context._refreshActionState();
- });
- this.grid.onContentChanged(function (object, removedFrom, insertedInto) {
- context._refreshActionState();
- });
- if (!this.grid.get("noDataMessage")) {
- this.grid.set("noDataMessage", "<span class='dojoxGridNoData'>" + this.i18n.noDataMessage + "</span>");
- }
- if (!this.grid.get("loadingMessage")) {
- this.grid.set("loadingMessage", "<span class='dojoxGridNoData'>" + this.i18n.loadingMessage + "</span>");
- }
- this.grid.startup();
- },
- getTitle: function () {
- return this.gridTitle;
- },
- appendMenuItem: function (menu, label, onClick) {
- var menuItem = new MenuItem({
- label: label,
- onClick: onClick
- });
- menu.addChild(menuItem);
- return menuItem;
- },
- appendContextMenuItem: function (label, onClick) {
- return this.appendMenuItem(this.contextMenu, label, onClick);
- },
- initContextMenu: function () {
- var context = this;
- this.contextMenu = new Menu({
- targetNodeIds: [this.id + "Grid"]
- });
- this.appendContextMenuItem(this.i18n.Refresh, function () {
- context._onRefresh();
- });
- this.contextMenu.addChild(new MenuSeparator());
- this.appendContextMenuItem(this.i18n.Open, function () {
- context._onOpen();
- });
- if (this.appendContextMenu) {
- this.appendContextMenu();
- }
- this.contextMenu.startup();
- },
- initTab: function () {
- var currSel = this.getSelectedChild();
- if (currSel) {
- if (!currSel.initalized) {
- if (currSel.init && currSel.hpcc) {
- currSel.init(currSel.hpcc.params);
- }
- currSel.initalized = true;
- } else if (currSel.refresh && !currSel.noRefresh) {
- currSel.refresh(currSel.hpcc.refreshParams);
- }
- }
- },
- getDetailID: function (row, params) {
- return this.id + "_" + "Detail" + row[this.idProperty];
- },
- ensurePane: function (row, params) {
- var id = this.getDetailID(row, params);
- var retVal = registry.byId(id);
- if (!retVal) {
- retVal = this.createDetail(id, row, params);
- this.addChild(retVal);
- } else {
- lang.mixin(retVal.hpcc, {
- refreshParams: params
- });
- }
- return retVal;
- },
- _refreshActionState: function () {
- var selection = this.grid.getSelected();
- this.refreshActionState(selection);
- },
- refreshActionState: function (selection) {
- registry.byId(this.id + "Open").set("disabled", !selection.length);
- }
- });
- });
|