### Eclipse Workspace Patch 1.0 #P mod_listpicker Index: forms/mod_listpicker.js =================================================================== --- forms/mod_listpicker.js (revision 22) +++ forms/mod_listpicker.js (working copy) @@ -20,14 +20,43 @@ if (_bFirstShow) { var _nFormWidth = _g_oListpicker.form.width, _nBtnCancelWidth = elements.btnCancel.getWidth(), - _nBtnNewWidth = elements.btnCreateNew.getWidth(); + _nBtnNewWidth = elements.btnCreateNew.getWidth(), + _nBtnOkWidth = elements.btnOk.getWidth(); elements.btnCancel.text = _g_oListpicker.buttontext.cancel; elements.btnCreateNew.text = _g_oListpicker.buttontext.createnew; + elements.btnOk.text = _g_oListpicker.buttontext.ok; - // Set the position of the Cancel and New buttons - if (_g_oListpicker.callback.createNewMethod == "") { + // Set the position of the Cancel, New and Ok buttons + if(_g_oListpicker.form.multiselect) + { + elements.btnOk.visible = true; + if(_g_oListpicker.callback.createNewMethod == "") + { + elements.btnCreateNew.visible = false; + elements.btnCancel.setLocation( (_nFormWidth / 4) - (_nBtnCancelWidth / 2), elements.btnCancel.getLocationY()); + elements.btnOk.setLocation( (_nFormWidth * 3 / 4) - (_nBtnCancelWidth / 2), elements.btnCancel.getLocationY()); + } + else + { + elements.btnCreateNew.visible = true; + if (application.getOSName() != 'Mac OS X') + { + elements.btnCreateNew.setLocation( (_nFormWidth / 4) - (_nBtnNewWidth / 2), elements.btnCreateNew.getLocationY()); + elements.btnOk.setLocation( (_nFormWidth / 2) - (_nBtnOkWidth / 2), elements.btnOk.getLocationY()); + elements.btnCancel.setLocation( (_nFormWidth * 3 / 4) - (_nBtnCancelWidth / 2), elements.btnCancel.getLocationY()); + } + else + { + elements.btnCancel.setLocation( (_nFormWidth / 4) - (_nBtnCancelWidth / 2), elements.btnCancel.getLocationY()); + elements.btnCreateNew.setLocation( (_nFormWidth / 2) * 2 - (_nBtnNewWidth / 2), elements.btnCreateNew.getLocationY()); + elements.btnOk.setLocation( (_nFormWidth * 3 / 4) - (_nBtnOkWidth / 2), elements.btnOk.getLocationY()); + } + } + } + else if (_g_oListpicker.callback.createNewMethod == "") { elements.btnCreateNew.visible = false; + elements.btnOk.visible = false; elements.btnCancel.setLocation( (_nFormWidth / 2) - (_nBtnCancelWidth / 2), elements.btnCancel.getLocationY()); } else { elements.btnCreateNew.visible = true; @@ -59,6 +88,7 @@ */ function btnCancel(_oEvent) { application.closeFormDialog(); + } /** @@ -129,6 +159,9 @@ case "<=": forms[_sForm][_g_oListpicker.form.filterParam[j][0]] = "<=" + _g_oListpicker.form.filterParam[j][2]; break; + case "!=": + forms[_sForm][_g_oListpicker.form.filterParam[j][0]] = "!" + _g_oListpicker.form.filterParam[j][2]; + break; } } } @@ -199,3 +232,55 @@ doSearch(); return true } + +/** + * @properties={typeid:24,uuid:"EE24A1D2-3B17-49F3-B1A3-0C153926CE57"} + */ +function selectOnAction(event) +{ + if(foundset[_g_oListpicker.form.tableName + '_to_selected']) + { + if(foundset[_g_oListpicker.form.tableName + '_to_selected'].selected) + { + databaseManager.saveData(foundset[_g_oListpicker.form.tableName + '_to_selected'].getSelectedRecord()); + } + else + { + foundset[_g_oListpicker.form.tableName + '_to_selected'].deleteRecord(); + } + } +} + +/** + * Perform the element default action. + * + * @param {JSEvent} event the event that triggered the action + * + * @properties={typeid:24,uuid:"21F32558-89C5-4BB2-A449-10C39D4B91AE"} + */ +function btnOk(_oEvent) { + try { + // select record and return returnValue + var _sForm = _oEvent.getFormName(); + var _oSelectedArray = _g_oListpicker.form.selectedDataset.getColumnAsArray(2); + + if (_g_oListpicker.callback.methodName != "") { + // Method + if (_g_oListpicker.callback.methodFormName != "") { + forms[_g_oListpicker.callback.methodFormName][_g_oListpicker.callback.methodName](_oSelectedArray); + } else { + globals[_g_oListpicker.callback.methodName](_oSelectedArray); + } + } else if (_g_oListpicker.callback.formName == "") { + // Global variable + globals[_g_oListpicker.callback.columnName] = _oSelectedArray; + } else { + // Form + table column/form variable + forms[_g_oListpicker.callback.formName][_g_oListpicker.callback.columnName] = _oSelectedArray; + } + application.closeFormDialog(); + } catch (e) { + // TODO: handle exception + application.output(e.msg, LOGGINGLEVEL.ERROR); + } +} Index: globals.js =================================================================== --- globals.js (revision 22) +++ globals.js (working copy) @@ -57,8 +57,11 @@ loadAllRecords: false, // optional, load all records when no search criteria is given. editableColumns: new Array(), // optional, only set to editable a columns if it name is in this array. - columnValuelists: new Object() // optional. Must be filled {columnName: valuelistName} + columnValuelists: new Object(), // optional. Must be filled {columnName: valuelistName} + multiselect: false, // optional, enabled a multiselect form if true. + selectedDataset: databaseManager.createEmptyDataSet(0,['selected','pickColumID']) // used only when multiselect is enabled to store the selected records. + } this.callback = { @@ -75,7 +78,8 @@ this.buttontext = { cancel: "Cancel", // optional, for use with i18n - createnew: "Create New" // optional, for use with i18n + createnew: "Create New", // optional, for use with i18n + ok: "Ok" // optional, for use with i18n } this.show = function() { @@ -115,14 +119,35 @@ _oForm = solutionModel.newForm(this.form.name, ("db:/" + this.form.serverName + "/" + this.form.tableName), this.form.stylesheet, false, this.form.width, this.form.height); _oForm.extendsForm = "mod_listpicker"; // form inheritence, here we get all the settings and objects of the original form - _oLabel = _oForm.newLabel("", 0, 30, 23, this.form.rowHeight, solutionModel.getForm("mod_listpicker").getFormMethod("btnSelect")); - _oLabel.mediaOptions = SM_MEDIAOPTION.CROP - _oLabel.imageMedia = solutionModel.getMedia("btn_select.png") - _oLabel.verticalAlignment = SM_ALIGNMENT.TOP; - _oLabel.anchors = SM_ANCHOR.NORTH | SM_ANCHOR.WEST; - _oLabel.transparent = true; - _oLabel.showClick = false; - _oLabel.showFocus = false; + if(!this.form.multiselect) + { + _oLabel = _oForm.newLabel("", 0, 30, 23, this.form.rowHeight, solutionModel.getForm("mod_listpicker").getFormMethod("btnSelect")); + _oLabel.mediaOptions = SM_MEDIAOPTION.CROP + _oLabel.imageMedia = solutionModel.getMedia("btn_select.png") + _oLabel.verticalAlignment = SM_ALIGNMENT.TOP; + _oLabel.anchors = SM_ANCHOR.NORTH | SM_ANCHOR.WEST; + _oLabel.transparent = true; + _oLabel.showClick = false; + _oLabel.showFocus = false; + } + else + { + var _oSelectedDatasource = this.form.selectedDataset.createDataSource(this.form.name +'_select', [JSColumn.INTEGER,JSColumn.INTEGER]); + var _oRelation; + + if(!solutionModel.getRelation(this.form.tableName + '_to_selected')) + { + _oRelation = solutionModel.newRelation(this.form.tableName + '_to_selected', this.form.serverName, this.form.tableName, _oSelectedDatasource, JSRelation.INNER_JOIN); + _oRelation.newRelationItem(this.form.pickColumn,'=','pickColumID'); + _oRelation.allowCreationRelatedRecords = true; + } + _oField = _oForm.newField(this.form.tableName + '_to_selected.selected',JSField.CHECKS, 0, 30, 23, this.form.rowHeight); + _oField.onAction = solutionModel.getForm("mod_listpicker").getFormMethod("selectOnAction"); + while(this.form.selectedDataset.getMaxRowIndex()) + { + this.form.selectedDataset.removeRow(1); + } + } for (i = 0; i < this.form.columnWidths.length; i++) { if (this.form.columnWidths[i] > -1) { @@ -153,6 +178,7 @@ } _oField.valuelist = (this.form.columnValuelists[this.form.displayColumns[i]]) ? solutionModel.getValueList(this.form.columnValuelists[this.form.displayColumns[i]]) : null; } + // Pass the JSListpicker object to the form-variable for further processing (like when clicking on form buttons) forms[this.form.name]._g_oListpicker = this; Index: forms/mod_listpicker.frm =================================================================== --- forms/mod_listpicker.frm (revision 22) +++ forms/mod_listpicker.frm (working copy) @@ -112,6 +112,19 @@ transparent:true, typeid:7, uuid:"D5DAC86E-8721-47BD-86AA-51EC911D18BA" +}, +{ +location:"470,466", +mediaOptions:14, +name:"btnOk", +onActionMethodID:"21F32558-89C5-4BB2-A449-10C39D4B91AE", +onDoubleClickMethodID:"-1", +onRightClickMethodID:"-1", +size:"120,26", +text:"Ok", +transparent:true, +typeid:7, +uuid:"F5A823D5-8D01-4F08-8F5E-AE0831CE795C" } ], name:"mod_listpicker",