diff --git a/controllers/reports.py b/controllers/reports.py index 9b55ae3fbd73dc810f957e202ab3c168749ffd68..57fac3027e57a1e65442e10e726e4c3f8f95bcfb 100644 --- a/controllers/reports.py +++ b/controllers/reports.py @@ -19,7 +19,7 @@ def report_1(): def report_2(): - """Return the url arguments + """Return the URL arguments """ selector = Selector(virtdb.foo1, extfield='my_format') @@ -30,4 +30,13 @@ def report_2(): return iframe # standart response with the selected values + return dict(test=selector.as_dict()) + + +def report_3(): + """Return the URL arguments + + """ + selector = Selector(virtdb.harvester_selector) + response.view = 'reports/report_2.html' return dict(test=selector.as_dict()) \ No newline at end of file diff --git a/languages/fr-fr.py b/languages/fr-fr.py index 139397585eb3ba43b82bee54c36c2855e6b27f48..80496d5d53cac7ee2a5141bced1bde845004d41d 100644 --- a/languages/fr-fr.py +++ b/languages/fr-fr.py @@ -41,6 +41,7 @@ 'Forms': 'Formulaires', 'General': 'Général', 'Grids': 'Tables', +'Harvest': 'Harvest', 'harvesters': 'harvesters', 'Help': 'Help', 'Host': 'Host', @@ -71,6 +72,7 @@ 'Report type': 'Type du rapport', 'report_1': 'report_1', 'report_2': 'report_2', +'report_3': 'report_3', 'reports': 'rapports', 'Reports': 'Rapports', 'Select': 'Selectionner', diff --git a/models/virtdb.py b/models/virtdb.py index 12ffa7500bc6f86b5112729df796f9cfd1e95930..991519ce1e87881d285e1f04ed477a3a5a7fd54c 100644 --- a/models/virtdb.py +++ b/models/virtdb.py @@ -21,3 +21,11 @@ virtdb.define_table("foo1", Field('my_format', default='html', requires=IS_IN_SET(['html', 'latex', 'pdf'])), Field('my_axis'), Field('my_granularity')) + + +virtdb.define_table("harvester_selector", + Field('id_projects', db.projects, label='Project'), + Field('controller', 'string', label='Harvest')) + +virtdb.harvester_selector.id_projects.requires = \ +IS_IN_DB(db, 'projects.id', 'projects.project') \ No newline at end of file diff --git a/models/widgets_fields.py b/models/widgets_fields.py index fe5250b601dd4eea0f36b44c4494ee0303c5b3e9..ffa58c244e1aea4d4b1dea784b3c9ba90dd33bd4 100644 --- a/models/widgets_fields.py +++ b/models/widgets_fields.py @@ -3,16 +3,13 @@ """ # -# Modify publications fields +# publications # fieldsModifier = dbui.FieldsModifier('publications') fieldsModifier.configure_field('conference_start', format='Y-m-d') fieldsModifier.configure_field('conference_end', format='Y-m-d') fieldsModifier.configure_field('year', maxValue=datetime.now().year) -# -# Merge fields for the publication form -# fieldsModifier.merge_fields('first_page', 'last_page', fieldLabel=T('Pages'), @@ -24,7 +21,7 @@ fieldsModifier.merge_fields('conference_start', defaults={'flex': 1}) # -# filterBox for foo1 selector +# foo1 selector # fieldsModifier = dbui.FieldsModifier('foo1') fieldsModifier.configure_field('my_axis', @@ -41,3 +38,22 @@ fieldsModifier.configure_field('my_granularity', store='axesStore', valueField='granularity', xtype='xlinkedcombobox') + +# +# harvesters +# +fieldsModifier = dbui.FieldsModifier('harvester_selector') +fieldsModifier.configure_field('id_projects', + displayField='ProjectsProject', + role='master', + store='harvestersStore', + valueField='HarvestersId_projects', + xtype='xlinkedcombobox') + +fieldsModifier.configure_field('controller', + displayField='HarvestersController', + mode='local', + role='slave', + store='harvestersStore', + valueField='HarvestersController', + xtype='xlinkedcombobox') diff --git a/models/widgets_viewport.py b/models/widgets_viewport.py index f253bf03973aeba03782b1013b469caaaf95449a..c9473fc288bfa8cd375c8491bc29d470f8377acd 100644 --- a/models/widgets_viewport.py +++ b/models/widgets_viewport.py @@ -27,14 +27,18 @@ helpNode.add_child(T('versions'), versionNode) # # the report node # -reportNode = dbui.Node(T('Reports')) -node = dbui.Panel(html="salut ma poule") -reportNode.add_child(T('report_1'), node) +node_1 = dbui.Panel(html="salut ma poule") + +node_2 = dbui.to_panelWithUrlSelector(virtdb.foo1, + baseUrl=URL('reports', 'report_2')) -node = dbui.to_panelWithUrlSelector(virtdb.foo1, - baseUrl=URL('reports', 'report_2')) -reportNode.add_child(T('report_2'), node) +node_3 = dbui.to_panelWithUrlSelector(virtdb.harvester_selector, + baseUrl=URL('reports', 'report_3')) +reportNode = dbui.Node(T('Reports')) +reportNode.add_child(T('report_1'), node_1) +reportNode.add_child(T('report_2'), node_2) +reportNode.add_child(T('report_3'), node_3) # # The viewport with its navigation tree diff --git a/static/plugin_dbui/src/linkedcombobox.js b/static/plugin_dbui/src/linkedcombobox.js index 041eb99c5d83eb01eadf37e6b5ec6ae5cdbf6ee7..5d033784bb257e553c8ed462db5d19fe6f245fd9 100644 --- a/static/plugin_dbui/src/linkedcombobox.js +++ b/static/plugin_dbui/src/linkedcombobox.js @@ -1,7 +1,6 @@ /** - * Linked combobox has been designed to solve the case with two comboboxes - * where the values of the second one depend on the select value of the - * first one. + * Linked combobox has been designed to solve the case when the values of + * a combobox depends on the select value of another combobox. * * The design is based on a master and a slave combobox which are * linked to a common store. @@ -40,61 +39,83 @@ App.form.LinkedComboBox = Ext.extend(Ext.form.ComboBox, { */ initComponent: function () { - // configure a master combobox. - // create a local store containing the values which can be used - // to filter the master store + // common configuration + this.triggerAction = 'all'; + + // prepare the stores for the master role if (this.role === 'master') { this.masterStore = App.getStore(this.store); this.mode = 'local'; this.store = new Ext.data.ArrayStore({ - fields: [this.displayField, this.valueField], - data: this.getMasterData() + fields: [this.displayField, this.valueField] }); - // configure a slave combobox - } else if (this.role === 'slave'){ - + if (!this.masterStore.getTotalCount()) { + this.masterStore.load({ + callback: this.loadMasterData, + scope: this + }); + + } else { + this.loadMasterData(); + } + } + + // prepare the store for the slave role + if (this.role === 'slave') { this.store = App.getStore(this.store); + + if (!this.store.getTotalCount()) { + this.store.load({ + callback: this.initSlave, + scope: this + }); + + } else { + this.initSlave(); + } } - - // configuration parameters common to master and slave - this.triggerAction = 'all'; // construct the underlying class. DON'T MOVE App.form.LinkedComboBox.superclass.initComponent.call(this); // logic to filter the content of the master store + // when a value is selected in the master combobox if (this.role === 'master') { this.on('select', this.filterMasterStore, this); // logic to update the content of a slave + // when a value is selected in the master combobox } else if (this.role === 'slave') { this.store.on('datachanged', this.onDataChanged, this); } - - // logic to load the underlying view in the initialisation phase - // by mimicking the click by a user - // require by the filtering mechanism - this.on('render', function (combo) { - combo.onTriggerClick(); - combo.collapse(); - }); }, /** - * Helper method to extract the master values to filter the common store. + * Helper method to filter the master store + * with the current value of the combobox * + * @param {Ext.form.combobox} combo + * @param {Ext.data.Record} record + * @param {Integer} index + */ + filterMasterStore: function (combo, record, index) { + this.masterStore.filter(this.valueField, combo.getValue()); + }, + + /** + * Private method to load data in the combo store from the master one */ - getMasterData: function () { + loadMasterData: function () { var data = [], key, keys = [], i, record; - + for (i = 0; i < this.masterStore.getCount(); i += 1) { record = this.masterStore.getAt(i); key = record.get(this.displayField); @@ -103,28 +124,55 @@ App.form.LinkedComboBox = Ext.extend(Ext.form.ComboBox, { data.push([key, record.get(this.valueField)]); } } - return data; + + this.store.loadData(data); + }, /** - * Helper method to filter the master store + * Private method to initialise the slave combobox + * A slave is disable at startup. * - * @param {Ext.form.combobox} combo - * @param {Ext.data.Record} record - * @param {Integer} index - */ - filterMasterStore: function (combo, record, index) { - this.masterStore.filter(this.valueField, combo.getValue()); + */ + initSlave: function () { + + if (this.role !== 'slave') { + return; + } + + // Reset and disable the combobox. + // + // NOTE + // when the user select a value in the master combobox + // for the first time, the value of the slave are not filtered + // It contains all possible values. + // To fix this issue, the code mimic the click by a user + // on the slave combobox and then it works !!! + // + if (this.rendered) { + this.onTriggerClick(); + this.collapse(); + this.reset(); + this.disable(); + + } else { + this.on('render', function (combo) { + combo.onTriggerClick(); + combo.collapse(); + combo.reset(); + combo.disable(); + }); + } }, - /** - * Helper method to update the combo box content and to select - * the first value of the filtered store + * Handler to update the content of the slave combobox content and to select + * when a master value is selected */ onDataChanged: function () { var value = this.store.getAt(0).get(this.valueField); this.setValue(value); + this.enable(); } });