git_sitools_idoc / szcluster-db / workspace / client-user / js / components / forms / mainContainer.js @ d45a7442
| 1 |
/***************************************
|
|---|---|
| 2 |
* Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
|
| 3 |
*
|
| 4 |
* This file is part of SITools2.
|
| 5 |
*
|
| 6 |
* SITools2 is free software: you can redistribute it and/or modify
|
| 7 |
* it under the terms of the GNU General Public License as published by
|
| 8 |
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
* (at your option) any later version.
|
| 10 |
*
|
| 11 |
* SITools2 is distributed in the hope that it will be useful,
|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
* GNU General Public License for more details.
|
| 15 |
*
|
| 16 |
* You should have received a copy of the GNU General Public License
|
| 17 |
* along with SITools2. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
***************************************/
|
| 19 |
/*global Ext, sitools, i18n, userLogin, DEFAULT_WIN_HEIGHT, DEFAULT_WIN_WIDTH, getDesktop, projectGlobal, SitoolsDesk, DEFAULT_PREFERENCES_FOLDER*/
|
| 20 |
/*global loadUrl*/
|
| 21 |
/*
|
| 22 |
* @include "formComponentsPanel.js"
|
| 23 |
*/
|
| 24 |
Ext.namespace('sitools.user.component.forms');
|
| 25 |
|
| 26 |
/**
|
| 27 |
* The global Panel. A panel with a formComponentsPanel and the buttons.
|
| 28 |
* @cfg {string} dataUrl Attachement Url of the dataset
|
| 29 |
* @cfg {string} datasetId datasetId
|
| 30 |
* @cfg {string} datasetName Dataset Name
|
| 31 |
* @cfg {Ext.grid.ColumnModel} datasetCm Column model of the dataset
|
| 32 |
* @cfg {string} formId Form Id
|
| 33 |
* @cfg {string} formName Form Name
|
| 34 |
* @cfg {Array} formParameters Array of form parameters
|
| 35 |
* @cfg {Array} formZones Array of form Zones containing parameters
|
| 36 |
* @cfg {number} formWidth Form Width
|
| 37 |
* @cfg {number} formHeight Form Height
|
| 38 |
* @cfg {string} formCss Name of a specific css class to apply to form
|
| 39 |
* @cfg {string} datasetView Name of the datasetView Object
|
| 40 |
* @cfg {Array} dictionaryMappings the Mapping between dataset column Model and concepts
|
| 41 |
* @class sitools.user.component.forms.mainContainer
|
| 42 |
* @extends Ext.Panel
|
| 43 |
* @requires sitools.user.component.formComponentsPanel
|
| 44 |
*/
|
| 45 |
sitools.user.component.forms.mainContainer = function (config) { |
| 46 |
//sitools.component.users.datasets.forms = function (config) {
|
| 47 |
Ext.apply(this, config);
|
| 48 |
this.componentType = "form"; |
| 49 |
|
| 50 |
var panelIdObject = {};
|
| 51 |
|
| 52 |
// New Form model with zones
|
| 53 |
if (!Ext.isEmpty(this.formZones)){ |
| 54 |
Ext.each(this.formZones, function(formParam) { |
| 55 |
//AVANT MODIF AVEC UN BUB var containerId = formParam.containerPanelId;
|
| 56 |
var containerId = formParam.id;
|
| 57 |
if (Ext.isEmpty(panelIdObject[containerId])){
|
| 58 |
panelIdObject[containerId] = []; |
| 59 |
} |
| 60 |
panelIdObject[containerId].push(formParam); |
| 61 |
}); |
| 62 |
} else { // old form model |
| 63 |
Ext.each(config.formParameters, function(formParam) {
|
| 64 |
var containerId = formParam.containerPanelId;
|
| 65 |
if (Ext.isEmpty(panelIdObject[containerId])){
|
| 66 |
panelIdObject[containerId] = []; |
| 67 |
} |
| 68 |
panelIdObject[containerId].push(formParam); |
| 69 |
}); |
| 70 |
} |
| 71 |
|
| 72 |
var items = [];
|
| 73 |
var globalParams = {};
|
| 74 |
|
| 75 |
Ext.iterate(panelIdObject, function(key, formParams){
|
| 76 |
var componentList = new sitools.user.component.formComponentsPanel({ |
| 77 |
border: true, |
| 78 |
css : config.formCss,
|
| 79 |
formId : config.formId,
|
| 80 |
id : key
|
| 81 |
}); |
| 82 |
|
| 83 |
if (!Ext.isEmpty(this.formZones)) { |
| 84 |
globalParams.formZones = formParams; |
| 85 |
} else {
|
| 86 |
globalParams.oldParameters = formParams; |
| 87 |
} |
| 88 |
|
| 89 |
componentList.datasetCm = config.dataset.columnModel; |
| 90 |
componentList.loadParameters(globalParams, config.dataUrl, "dataset");
|
| 91 |
|
| 92 |
items.push(componentList); |
| 93 |
}, this);
|
| 94 |
|
| 95 |
this.zonesPanel = new Ext.Panel({ |
| 96 |
width : config.formWidth,
|
| 97 |
height : config.formHeight,
|
| 98 |
css : config.formCss,
|
| 99 |
formId : config.formId,
|
| 100 |
items : [items]
|
| 101 |
}); |
| 102 |
|
| 103 |
if (Ext.isEmpty(config.dataset)) {
|
| 104 |
Ext.Ajax.request({
|
| 105 |
url : config.dataUrl,
|
| 106 |
method : "GET", |
| 107 |
scope : this, |
| 108 |
success : function (ret) { |
| 109 |
if (showResponse(ret)) {
|
| 110 |
var json = Ext.decode(ret.responseText);
|
| 111 |
// this.componentList.datasetCm = json.dataset.columnModel;
|
| 112 |
// this.componentList.loadParameters(config.formParameters, config.dataUrl, "dataset");
|
| 113 |
this.datasetId = json.dataset.id;
|
| 114 |
this.datasetName = json.dataset.name;
|
| 115 |
this.datasetCm = json.dataset.columnModel;
|
| 116 |
this.datasetView = json.dataset.datasetView;
|
| 117 |
this.dictionaryMappings = json.dataset.dictionaryMappings;
|
| 118 |
} |
| 119 |
} |
| 120 |
}); |
| 121 |
} |
| 122 |
else {
|
| 123 |
// this.componentList.datasetCm = config.dataset.columnModel;
|
| 124 |
// this.componentList.loadParameters(config.formParameters, config.dataUrl, "dataset");
|
| 125 |
this.datasetId = config.dataset.id;
|
| 126 |
this.datasetName = config.dataset.name;
|
| 127 |
this.datasetCm = config.dataset.columnModel;
|
| 128 |
this.datasetView = config.dataset.datasetView;
|
| 129 |
this.dictionaryMappings = config.dataset.dictionaryMappings;
|
| 130 |
} |
| 131 |
|
| 132 |
sitools.user.component.forms.mainContainer.superclass.constructor.call(this, Ext.apply({
|
| 133 |
height : config.formHeight,
|
| 134 |
width : config.formWidth,
|
| 135 |
autoScroll : true, |
| 136 |
bodyBorder : false, |
| 137 |
border : false, |
| 138 |
iconCls : 'z-btn-search', |
| 139 |
items : [this.zonesPanel], |
| 140 |
buttons : [
|
| 141 |
|
| 142 |
// ************************* Reset Form button ************************** //
|
| 143 |
{
|
| 144 |
text : 'Reset Form', |
| 145 |
scope : this, |
| 146 |
iconCls : 'x-btn-reset', |
| 147 |
handler : function () { |
| 148 |
var containers = this.find("stype", 'sitoolsFormContainer'); |
| 149 |
Ext.each(containers, function (container) {
|
| 150 |
if(Ext.isFunction(container.resetToDefault)){
|
| 151 |
container.resetToDefault(); |
| 152 |
} |
| 153 |
}, this);
|
| 154 |
|
| 155 |
} |
| 156 |
}, |
| 157 |
// ********************************************************************** //
|
| 158 |
|
| 159 |
{
|
| 160 |
text : i18n.get('label.search'), |
| 161 |
scope : this, |
| 162 |
iconCls : 'x-btn-search', |
| 163 |
handler : function () { |
| 164 |
this.onSearch(config);
|
| 165 |
} |
| 166 |
} |
| 167 |
], |
| 168 |
listeners : {
|
| 169 |
scope : this, |
| 170 |
resize : function () { |
| 171 |
if (!Ext.isEmpty(this.zonesPanel.getEl())) { |
| 172 |
var cmpChildSize = this.zonesPanel.getSize(); |
| 173 |
var size = this.body.getSize(); |
| 174 |
var xpos = 0, ypos = 0; |
| 175 |
if (size.height > cmpChildSize.height) {
|
| 176 |
ypos = (size.height - cmpChildSize.height) / 2;
|
| 177 |
} |
| 178 |
if (size.width > cmpChildSize.width) {
|
| 179 |
xpos = (size.width - cmpChildSize.width) / 2;
|
| 180 |
} |
| 181 |
this.zonesPanel.setPosition(xpos, ypos);
|
| 182 |
} |
| 183 |
|
| 184 |
} |
| 185 |
}, |
| 186 |
bbar : new Ext.ux.StatusBar({ |
| 187 |
text : i18n.get('label.ready'), |
| 188 |
iconCls : 'x-status-valid', |
| 189 |
hidden : true |
| 190 |
}) |
| 191 |
})); |
| 192 |
|
| 193 |
}; |
| 194 |
Ext.extend(sitools.user.component.forms.mainContainer, Ext.Panel, {
|
| 195 |
onSearch : function (config) { |
| 196 |
|
| 197 |
var valid = true; |
| 198 |
|
| 199 |
this.zonesPanel.items.each(function(componentList){ |
| 200 |
valid = valid && componentList.isComponentsValid(); |
| 201 |
},this);
|
| 202 |
|
| 203 |
if (!valid) {
|
| 204 |
this.getBottomToolbar().setStatus({
|
| 205 |
text : i18n.get('label.checkformvalue'), |
| 206 |
iconCls : 'x-status-error' |
| 207 |
}); |
| 208 |
this.getBottomToolbar().setVisible(true); |
| 209 |
return;
|
| 210 |
} else {
|
| 211 |
this.getBottomToolbar().setVisible(false); |
| 212 |
} |
| 213 |
//Execute a request to get the dataset config
|
| 214 |
Ext.Ajax.request({
|
| 215 |
url : config.dataUrl,
|
| 216 |
method : "GET", |
| 217 |
scope : this, |
| 218 |
success : function (ret) { |
| 219 |
var Json = Ext.decode(ret.responseText);
|
| 220 |
if (!Json.success) {
|
| 221 |
Ext.Msg.alert(i18n.get('label.warning'), Json.message);
|
| 222 |
return;
|
| 223 |
} else {
|
| 224 |
var dataset = Json.dataset;
|
| 225 |
this.doSearch(config, dataset);
|
| 226 |
} |
| 227 |
}, |
| 228 |
failure : alertFailure
|
| 229 |
}); |
| 230 |
}, |
| 231 |
|
| 232 |
/**
|
| 233 |
* Build the query for the liveGrid and build the livegrid component
|
| 234 |
* @param config
|
| 235 |
* @returns
|
| 236 |
*/
|
| 237 |
doSearch : function (config, dataset) { |
| 238 |
var containers = this.find("stype", 'sitoolsFormContainer'); |
| 239 |
var formParams = [];
|
| 240 |
var glue = ""; |
| 241 |
var i = 0; |
| 242 |
Ext.each(containers, function (container) {
|
| 243 |
// var f = form.getForm();
|
| 244 |
|
| 245 |
if (Ext.isFunction(container.getParameterValue)) {
|
| 246 |
var param = container.getParameterValue();
|
| 247 |
if (!Ext.isEmpty(param)) {
|
| 248 |
formParams.push(this.paramValueToApi(param));
|
| 249 |
} |
| 250 |
} |
| 251 |
}, this);
|
| 252 |
|
| 253 |
var desktop = getDesktop();
|
| 254 |
var win = desktop.getWindow("windResultForm" + config.formId); |
| 255 |
if (win) {
|
| 256 |
win.close(); |
| 257 |
} |
| 258 |
if (Ext.isFunction(this.searchAction)) { |
| 259 |
this.searchAction(formParams, dataset, this.scope); |
| 260 |
} |
| 261 |
else {
|
| 262 |
this.defaultSearchAction(formParams, dataset);
|
| 263 |
} |
| 264 |
|
| 265 |
}, |
| 266 |
|
| 267 |
defaultSearchAction : function (formParams, dataset) { |
| 268 |
var jsObj = eval(dataset.datasetView.jsObject);
|
| 269 |
var componentCfg = {
|
| 270 |
dataUrl : dataset.sitoolsAttachementForUsers,
|
| 271 |
datasetId : dataset.id,
|
| 272 |
datasetCm : dataset.columnModel,
|
| 273 |
datasetName : dataset.name,
|
| 274 |
formParams : formParams,
|
| 275 |
dictionaryMappings : dataset.dictionaryMappings,
|
| 276 |
datasetViewConfig : dataset.datasetViewConfig,
|
| 277 |
preferencesPath : "/" + dataset.name, |
| 278 |
preferencesFileName : "datasetView" |
| 279 |
}; |
| 280 |
var windowConfig = {
|
| 281 |
// id : "windResultForm" + config.formId,
|
| 282 |
title : i18n.get('label.dataTitle') + " : " + dataset.name, |
| 283 |
datasetName : dataset.name,
|
| 284 |
type : "data", |
| 285 |
saveToolbar : true, |
| 286 |
iconCls : "dataviews" |
| 287 |
}; |
| 288 |
SitoolsDesk.addDesktopWindow(windowConfig, componentCfg, jsObj); |
| 289 |
}, |
| 290 |
|
| 291 |
_getSettings : function () { |
| 292 |
return {
|
| 293 |
objectName : "forms", |
| 294 |
dataUrl : this.dataUrl, |
| 295 |
dataset : this.dataset, |
| 296 |
formId : this.formId, |
| 297 |
formName : this.formName, |
| 298 |
formParameters : this.formParameters, |
| 299 |
formWidth : this.formWidth, |
| 300 |
formHeight : this.formHeight, |
| 301 |
formCss : this.formCss, |
| 302 |
datasetView : this.datasetView, |
| 303 |
dictionaryMappings : this.dictionaryMappings, |
| 304 |
preferencesPath : this.preferencesPath, |
| 305 |
preferencesFileName : this.preferencesFileName |
| 306 |
}; |
| 307 |
}, |
| 308 |
/**
|
| 309 |
* Build a string using a form param Value.
|
| 310 |
* @param {} paramValue An object with attributes : at least type, code, value and optionnal userDimension, userUnit
|
| 311 |
* @return {string} something like "TEXTFIELD|ColumnAlias|value"
|
| 312 |
*/
|
| 313 |
paramValueToApi : function (paramValue) { |
| 314 |
var stringParam = paramValue.type + "|" + paramValue.code + "|" + paramValue.value; |
| 315 |
if (!Ext.isEmpty(paramValue.userDimension) && !Ext.isEmpty(paramValue.userUnit)) {
|
| 316 |
stringParam += "|" + paramValue.userDimension + "|" + paramValue.userUnit.unitName; |
| 317 |
} |
| 318 |
return stringParam;
|
| 319 |
} |
| 320 |
}); |
| 321 |
|