diff options
Diffstat (limited to 'webapps/swat/source/class')
-rw-r--r-- | webapps/swat/source/class/swat/module/ldbbrowse/Gui.js | 131 | ||||
-rw-r--r-- | webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js | 197 |
2 files changed, 313 insertions, 15 deletions
diff --git a/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js b/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js index 1b9677fbd1..b082ec0719 100644 --- a/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js +++ b/webapps/swat/source/class/swat/module/ldbbrowse/Gui.js @@ -16,6 +16,8 @@ function() qx.core.Object.call(this); }); +//qx.OO.addProperty({ name : "_table", type : "object" }); +//qx.OO.addProperty({ name : "_ldbmod", type : "object" }); /** * Build the raw graphical user interface. @@ -141,7 +143,13 @@ qx.Proto.displayData = function(module, rpcRequest) break; case "tree_selection_changed": + + // Always update the table, even if it is not visible this._displayTreeSelectionChangedResults(module, rpcRequest); + + // Update the base field in ldbmod + this._displayLdbmodBaseChanged(module, rpcRequest); + break; case "database_name_changed": @@ -300,6 +308,17 @@ qx.Proto._buildPageBrowse = function(module, page) var splitpane = new qx.ui.splitpane.HorizontalSplitPane("1*", "2*"); splitpane.setEdge(0); + // We need a vertical box layout for the tree and the buttons + var vlayout = new qx.ui.layout.VerticalBoxLayout(); + vlayout.set({ + height: "100%", + top: 5, + left: 5, + right: 5, + bottom: 5, + spacing: 10 + }); + // Create a tree row structure for the tree root var trsInstance = qx.ui.treefullcontrol.TreeRowStructure.getInstance(); var trs = trsInstance.standard(module.dbFile); @@ -310,11 +329,7 @@ qx.Proto._buildPageBrowse = function(module, page) backgroundColor: 255, border: qx.renderer.border.BorderPresets.getInstance().inset, overflow: "auto", - height: null, - top: 10, - left: 0, - right: 0, - bottom: 10, + height: "1*", open: false, alwaysShowPlusMinusSymbol: true }); @@ -333,8 +348,36 @@ qx.Proto._buildPageBrowse = function(module, page) fsm.addObject("tree", tree); fsm.addObject("tree:manager", tree.getManager()); - // Add the tree to the page. - splitpane.addLeft(tree); + // Add the tree to the vlayout. + vlayout.add(tree); + + // Add an horizonatl layout for the "New" and "Modify" buttons + // We need a vertical box layout for the tree and the buttons + var hlayout = new qx.ui.layout.HorizontalBoxLayout(); + hlayout.set({ + height: "auto", + spacing: 10 + }); + + // Add the "New" button + this._newb = new qx.ui.form.Button("New"); + this._newb.addEventListener("execute", this._switchToNewrecord, this); + + // Add the button to the hlayout + hlayout.add(this._newb); + + // Add the "New" button + this._modb = new qx.ui.form.Button("Modify"); + this._modb.addEventListener("execute", this._switchToModrecord, this); + + // Add the button to the hlayout + hlayout.add(this._modb); + + // Add the hlayout to the vlayout. + vlayout.add(hlayout); + + //Add the left vlayout to the splitpane + splitpane.addLeft(vlayout); // Create a simple table model var tableModel = new qx.ui.table.SimpleTableModel(); @@ -345,8 +388,8 @@ qx.Proto._buildPageBrowse = function(module, page) fsm.addObject("tableModel:browse", tableModel); // Create a table - var table = new qx.ui.table.Table(tableModel); - table.set({ + this._table = new qx.ui.table.Table(tableModel); + this._table.set({ top: 10, left: 0, right: 0, @@ -354,24 +397,66 @@ qx.Proto._buildPageBrowse = function(module, page) statusBarVisible: false, columnVisibilityButtonVisible: false }); - table.setColumnWidth(0, 180); - table.setColumnWidth(1, 320); - table.setMetaColumnCounts([1, -1]); - fsm.addObject("table:browse", table); + this._table.setColumnWidth(0, 180); + this._table.setColumnWidth(1, 320); + this._table.setMetaColumnCounts([1, -1]); + fsm.addObject("table:browse", this._table); + + //table.setDisplay(false); // Add the table to the bottom portion of the splitpane - splitpane.addRight(table); + splitpane.addRight(this._table); + + // Build the create/modify widget + this._ldbmod = new swat.module.ldbbrowse.LdbModify(fsm); + this._ldbmod.set({ + top: 10, + left: 0, + right: 0, + bottom: 10 + }); + // Not displayed by default + this._ldbmod.setDisplay(false); + + fsm.addObject("ldbmod:browse", this._ldbmod); + + splitpane.addRight(this._ldbmod); // Add the first splitpane to the page page.add(splitpane); }; +qx.Proto._switchToNormal = function() +{ + this._table.setDisplay(true); + this._ldbmod.setDisplay(false); + this._newb.setEnabled(true); + this._modb.setEnabled(true); +} + +qx.Proto._switchToNewrecord = function() +{ + this._table.setDisplay(false); + this._ldbmod.setDisplay(true); + this._newb.setEnabled(false); + this._modb.setEnabled(false); + this._ldbmod.initNew(this._switchToNormal, this); +} + +qx.Proto._switchToModrecord = function() +{ + this._table.setDisplay(false); + this._ldbmod.setDisplay(true); + this._newb.setEnabled(false); + this._modb.setEnabled(false); + this._ldbmod.initMod(this._table, this._switchToNormal, this); +} qx.Proto._displaySearchResults = function(module, rpcRequest) { var fsm = module.fsm; - // Obtain the table and tableModel objects + // Obtain the ldif object var ldifview = fsm.getObject("LdifView"); ldifview.reset(); @@ -455,6 +540,22 @@ qx.Proto._displayTreeOpenResults = function(module, rpcRequest) } }; +qx.Proto._displayLdbmodBaseChanged = function(module, rpcRequest) +{ + var fsm = module.fsm; + + // Obtain the result object + var result = rpcRequest.getUserData("result").data; + + // If we received an empty list, ... + if (result == null) + { + // ... then ?? + return; + } + + this._ldbmod.setBase(result[0]["dn"]); +}; qx.Proto._displayTreeSelectionChangedResults = function(module, rpcRequest) { diff --git a/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js b/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js new file mode 100644 index 0000000000..2b5dfc18f6 --- /dev/null +++ b/webapps/swat/source/class/swat/module/ldbbrowse/LdbModify.js @@ -0,0 +1,197 @@ +/* + * Copyright:: + * (C) 2006 by Simo Sorce + * + * License: + * GPL v2 or later + */ + +/** + * Ldb Modifier Class + */ + +qx.OO.defineClass("swat.module.ldbbrowse.LdbModify", qx.ui.layout.VerticalBoxLayout, +function(fsm) +{ + qx.ui.layout.VerticalBoxLayout.call(this); + + this._mainArea = new qx.ui.layout.VerticalBoxLayout(); + this._mainArea.set({ + height: "1*", + spacing: 5 + }); + + // Add an horizonatl layout for the "New" and "Modify" buttons + // We need a vertical box layout for the tree and the buttons + this._hlayout = new qx.ui.layout.HorizontalBoxLayout(); + this._hlayout.set({ + height: "auto", + spacing: 10 + }); + + // add a spacer to align buttons to the right + this._leftSpacer = new qx.ui.basic.HorizontalSpacer(); + + // Add the "Cancel" button + this._cancelbtn = new qx.ui.form.Button("Cancel"); + this._cancelbtn.addEventListener("execute", this._cancelOp, this); + + // Add the "OK" button + this._okbtn = new qx.ui.form.Button("OK"); + this._okbtn.addEventListener("execute", fsm.eventListener, fsm); + + // We'll be receiving events on the object, so save its friendly name + fsm.addObject("domod", this._okbtn, "swat.main.fsmUtils.disable_during_rpc"); + + // Add the buttons to the hlayout + this._hlayout.add(this._leftSpacer, this._cancelbtn, this._okbtn); + + // Add the hlayout to the vlayout. + this.add(this._mainArea, this._hlayout); + + // By default this is a new record creator + this._type = "new"; + + // By default this is inactive + this._active = false; + + this.basedn = ""; +}); + +qx.OO.addProperty({ name : "basedn", type : "string" }); + +/** + * Set the type of operation + * + * @param type {String} + * A string containing "new" or "modify" + * + * @param data {object} + * An LDB object with the current object parameters + * Used only if type = "modify" + * + */ + +qx.Proto.isActive = function() { + if (this._active == true) { + return true; + } +} + +/** + * Set the base of the object to add + * + * @param type {string} + * A string containing the base DN + */ + +qx.Proto.setBase = function(base) { + + this.basedn = base; + + if (this._active) { + if (this._type == "new") { + + this._basedn.setValue(this.basedn); + this._basedn.setWidth(8 * this.basedn.length); + } + } +} + +qx.Proto.initNew = function(callback, obj) { + + this._setExitCallback(callback, obj); + + this._active = true; + this._type = "new"; + + var hlayout = new qx.ui.layout.HorizontalBoxLayout(); + hlayout.set({ height: "auto", spacing: 10 }); + + var dnlabel = new qx.ui.basic.Label("DN: "); + + // The name of the new/modified object + // TODO: add validator + this._rdn = new qx.ui.form.TextField(""); + this._rdn.setWidth(128); + + var dnsep = new qx.ui.basic.Label(","); + + // The basedn of the object + // TODO: add validator + this._basedn = new qx.ui.form.TextField(this.basedn); + this._basedn.setWidth(8 * this.basedn.length); + + hlayout.add(dnlabel, this._rdn, dnsep, this._basedn); + + this._mainArea.add(hlayout); + + return; +} + +qx.Proto.initMod = function(table, callback, obj) { + + this._setExitCallback(callback, obj); + + if (this.basedn == "") { + this._callExitCallback(); + return; + } + + this._active = true; + this._type = "modify"; + + this._dn = new qx.ui.basic.Label("DN: " + this.basedn); + + this._mainArea.add(this._dn); + + //TODO: for each entry in the table, add new entries in the object + + return; +} + +qx.Proto._setExitCallback = function(vFunction, vObject) { + + if(typeof vFunction !== "function") { + throw new Error("swat.module.ldbbrowse.LdbModify: setExitCallback(" + vFunction + "' is not a function!"); + } + + this._exitCallback = { + handler : vFunction, + object : vObject + } +} + +qx.Proto._callExitCallback = function() { + + // Shortcuts for handler and object + vFunction = this._exitCallback.handler; + vObject = this._exitCallback.object; + + // Call object function + try + { + if(typeof vFunction === "function") { + vFunction.call(qx.util.Validation.isValid(vObject) ? vObject : this); + } + } + catch(ex) + { + this.error("swat.module.ldbbrowse.LdbModify: Could not call exit callback: ", ex); + } +} + +qx.Proto._reset = function() { + + // Remove existing attributes + this._mainArea.removeAll(); + this._active = false; + this._type = "null"; + return; +} + +qx.Proto._cancelOp = function() { + + this._reset(); + this._callExitCallback(); +} |