"
- ),
-
- /**
- * @property {Ext.XTemplate} _tooltipCandidateTpl The tooltip candidate template
- * @private
- */
- _tooltipCandidateTpl: Ext.create('Ext.XTemplate',
- "
",
- "
{label}
",
- "
",
- "
",
- "
",
- " : {comment:this.convertToHtml}
",
- "",
- "
",
- "
",
- "
",
- {
- convertToHtml: function(value)
- {
- return value.replace(/\n/g, '
');
- }
- }
- )
- },
-
-
- fields: [
- {name: 'id', mapping: '@id'},
- {name: 'name', mapping: '@name'},
- {name: 'label', mapping: '@label', type: 'string', sortType: Ext.data.SortTypes.asNonAccentedUCString},
- {name: 'text', mapping: '@label', type: 'string', sortType: Ext.data.SortTypes.asNonAccentedUCString},
- {name: 'ta', mapping: '@ta'},
- {name: 'ts', mapping: '@ts'},
- {name: 'tg', mapping: '@tg'},
- {name: 'comment', mapping: '@comment', defaultValue: ''},
- {name: 'type', mapping: '@type ', defaultValue: 'term'},
- {name: 'synonyms', mapping: '@synonyms'},
- {name: 'leaf', type: 'boolean', mapping: '@leaf'},
- {name: 'qtip', persist: false, convert: function (v, record) {
- if (record.get('type') == 'term')
- {
- return Ametys.plugins.thesaurus.tool.TermEntry._tooltipTermTpl.applyTemplate(record.data);
- }
- else if (record.get('type') == 'candidate')
- {
- return Ametys.plugins.thesaurus.tool.TermEntry._tooltipCandidateTpl.applyTemplate(record.data);
- }
- else
- {
- return null;
- }
- }},
- {name: 'cls', mapping: '@cls', defaultValue: ''},
- {name: 'iconCls', mapping: '@iconCls'},
- {name: 'iconLarge', mapping: '@iconLarge'}
- ]
-
-});
-
Index: main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/TermEntry.js
===================================================================
--- main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/TermEntry.js (revision 30361)
+++ main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/TermEntry.js (working copy)
@@ -31,16 +31,16 @@
"
{label}
",
"
",
"
",
- "
",
+ "",
" : {tg}
",
"",
- "",
+ "",
" : {ts}
",
"",
- "",
+ "",
" : {ta}
",
"",
- "",
+ "",
" : {synonyms}
",
"",
"",
@@ -85,14 +85,14 @@
{name: 'type', mapping: '@type ', defaultValue: 'term'},
{name: 'synonyms', mapping: '@synonyms'},
{name: 'leaf', type: 'boolean', mapping: '@leaf'},
- {name: 'qtip', persist: false, convert: function (v, record) {
- if (record.get('type') == 'term')
+ {name: 'qtip', persist: false, calculate: function (data) {
+ if (data.type == 'term')
{
- return Ametys.plugins.thesaurus.tool.TermEntry._tooltipTermTpl.applyTemplate(record.data);
+ return Ametys.plugins.thesaurus.tool.TermEntry._tooltipTermTpl.applyTemplate(data);
}
- else if (record.get('type') == 'candidate')
+ else if (data.type == 'candidate')
{
- return Ametys.plugins.thesaurus.tool.TermEntry._tooltipCandidateTpl.applyTemplate(record.data);
+ return Ametys.plugins.thesaurus.tool.TermEntry._tooltipCandidateTpl.applyTemplate(data);
}
else
{
Index: main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTool.i18n.js
===================================================================
--- main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTool.i18n.js (revision 32275)
+++ main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTool.i18n.js (working copy)
@@ -1,481 +0,0 @@
-/*
-
- * Copyright 2014 Anyware Services
- *
- * 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.
- */
-
-/**
- * This tool displays thesaurus
- * @private
- */
-Ext.define('Ametys.plugins.thesaurus.tool.ThesaurusTool', {
- extend: "Ametys.tool.Tool",
-
- /**
- * @property {String} _thesaurusId The id of thesaurus
- * @private
- */
-
- /**
- * @property {String} _thesaurusLabel The label of thesaurus
- * @private
- */
- constructor: function(config)
- {
- this.callParent(arguments);
-
- Ametys.message.MessageBus.on(Ametys.message.Message.SELECTION_CHANGED, this._onMessageSelectionChanged, this);
- Ametys.message.MessageBus.on(Ametys.message.Message.MODIFIED, this._onMessageModified, this);
- Ametys.message.MessageBus.on(Ametys.message.Message.CREATED, this._onMessageCreated, this);
- Ametys.message.MessageBus.on(Ametys.message.Message.DELETED, this._onMessageDeleted, this);
- },
-
- getMBSelectionInteraction: function()
- {
- return Ametys.tool.Tool.MB_TYPE_ACTIVE;
- },
-
- sendCurrentSelection: function()
- {
- var node = this.getSelectedNode();
-
- var termTargets = [];
-
- if (node != null && node.get('type') == 'term')
- {
- termTargets.push ({
- type: Ametys.message.MessageTarget.CONTENT,
- parameters: {
- ids: [node.getId()]
- }
- });
- }
-
- if (node != null && node.get('type') == 'candidate')
- {
- termTargets.push ({
- type: Ametys.message.MessageTarget.THESAURUS_CANDIDATE,
- parameters: {
- ids: [node.getId()]
- }
- });
- }
-
- var mtTargets = [];
- if (!Ext.isEmpty(this.getMicrothesaurusId()))
- {
- mtTargets.push({
- type: Ametys.message.MessageTarget.MICROTHESAURUS,
- parameters: {
- id: this.getMicrothesaurusId(),
- label: this._tree.getRootNode().get('label')
- },
- subtargets: termTargets
- });
- }
-
- Ext.create("Ametys.message.Message", {
- type: Ametys.message.Message.SELECTION_CHANGED,
- targets: {
- type: Ametys.message.MessageTarget.THESAURUS,
- parameters: {
- id: this._thesaurusId,
- label: this._thesaurusLabel
- },
- subtargets: mtTargets
- }
- });
- },
-
- setParams: function (params)
- {
- this.callParent (arguments);
-
- this._thesaurusId = params['id'];
- this.refresh();
- },
-
- createPanel: function()
- {
- var i = this.getId().indexOf('$') + 1;
- var thesaurusId = this.getId().substring(i);
-
- this._tree = new Ametys.plugins.thesaurus.tool.ThesaurusTreePanel({
- region: 'center',
- thesaurusId: thesaurusId,
- tool: this,
- rootVisible: true,
-
- viewConfig: {
- plugins: {
- ptype: 'ametystreeviewdragdrop',
- containerScroll: true,
- appendOnly: true,
- sortOnDrop: true,
- expandDelay: 500,
- setAmetysDragInfos: Ext.bind(this.getDragInfo, this)
- }
- }
- });
-
- this._tree.on('selectionchange', this._onSelectNode, this);
- this._tree.on('beforeitemdblclick', this._onItemDblClick, this);
-
- return this._tree;
- },
-
- /**
- * @private
- * This event is thrown by the getDragData to add the 'source' of the drag.
- * @param {Object} item The default drag data that will be transmitted. You have to add a 'source' item in it:
- * @param {Ametys.relation.RelationPoint} item.source The source (in the relation way) of the drag operation.
- */
- getDragInfo: function(item)
- {
- var contentIds = [];
- for (var i = 0; i < item.records.length; i++)
- {
- contentIds.push(item.records[i].get('id'));
- }
-
- if (contentIds.length > 0)
- {
- item.source = {
- relationTypes: [Ametys.relation.Relation.REFERENCE],
- targets: {
- type: Ametys.message.MessageTarget.CONTENT,
- parameters: { ids: contentIds }
- }
- };
- }
- },
-
- /**
- * This listener is called before the dblclick event on an node is processed.
- * Open the term.
- * @param {Ext.view.View} view The view
- * @param {Ext.data.Model} record The record that belongs to the item
- * @param {HTMLElement} item The item's element
- * @param {Number} index The item's index
- * @private
- */
- _onItemDblClick: function (view, record, item, index)
- {
- if (record.get('type') == 'term')
- {
- Ametys.tool.ToolsManager.openTool('uitool-content', {'id': record.getId()});
- }
- },
-
- /**
- * This function is called when a node is selected.
- * @param {Ext.selection.Model} sm The selection model
- * @param {Ext.data.NodeInterface[]} selected The selected nodes
- * @private
- */
- _onSelectNode: function (sm, selected)
- {
- if (selected.length == 0)
- {
- this._currentNode = null;
- }
- else
- {
- var node = selected[0];
- this._currentNode = node;
- }
-
- this.sendCurrentSelection();
- },
-
- refresh: function()
- {
- this.showRefreshing();
- this._updateInfos();
- },
-
- /**
- * Update tool information
- * @private
- */
- _updateInfos: function()
- {
- Ametys.data.ServerComm.callMethod({
- role: "org.ametys.plugins.thesaurus.ThesaurusDAO",
- methodName: 'getThesaurusLabel',
- parameters: [this._thesaurusId],
- errorMessage: false,
- callback: {
- handler: this._updateInfosCb,
- scope: this
- }
- });
- },
-
- /**
- * Callback function called after #_updateInfos is processed.
- * Updates the tool's title and tooltip.
- * @param {Object} result The server response.
- * @param {Object[]} args The callback arguments
- */
- _updateInfosCb: function (result, args)
- {
- if (result.error && result.error == "not-found")
- {
- Ametys.Msg.show({
- title: "
",
- msg: "
",
- buttons: Ext.Msg.OK,
- icon: Ext.Msg.ERROR,
- fn: function (btn)
- {
- this.showRefreshed();
- this.close();
- },
- scope: this
- });
-
- return;
- }
-
- this._thesaurusLabel = result.label;
-
- this.setInfo ({
- title: result.label
- });
-
- this._tree.loadMicrothesaurii (null, Ext.bind(this._refreshCb, this));
- },
-
- /**
- * Callback function after refresh
- * @private
- */
- _refreshCb: function ()
- {
- this.showRefreshed();
- },
-
- /**
- * Get the tree panel
- * @return {Ametys.plugins.thesaurus.tool.ThesaurusTreePanel} The tree
- */
- getTree: function ()
- {
- return this._tree;
- },
-
- /**
- * Get the current selected node
- * @return {Ext.data.NodeInterface} The selected node
- */
- getSelectedNode: function()
- {
- return this.getTree().getSelectionModel().getSelection()[0];
- },
-
- /**
- * Get the id of selected node in the tree.
- * If no node is selected, returns the id of the current microthesaurus
- */
- getSelectedNodeId: function()
- {
- var node = this.getSelectedNode();
-
- return node != null ? node.getId() : null;
- },
-
- /**
- * Get the thesaurus id
- * @return {String} the thesaurus id
- */
- getThesaurusId: function()
- {
- return this._thesaurusId;
- },
-
- /**
- * Get the thesaurus id
- * @return {String} the thesaurus id
- */
- getMicrothesaurusId: function()
- {
- return this._tree.getMTComboBox().getValue();
- },
-
- /**
- * Get the selected microthesaurus
- * @return {Ametys.plugins.thesaurus.tool.MicrothesaurusEntry} the microthesaurus
- */
- getSelectedMT: function ()
- {
- return this._tree.getSelectedMT();
- },
-
- /**
- * Listener when a Ametys.message.Message#SELECTION_CHANGED message was received
- * @param {Ametys.message.Message} message The selection message
- * @private
- */
- _onMessageSelectionChanged: function (message)
- {
- var target = message.getTarget(Ametys.message.MessageTarget.CONTENT);
- if (target != null && this._isOnCurrentTree(target.getParameters().additionalData.thesaurusId, target.getParameters().additionalData.microthesaurusId))
- {
- var node = this._tree.getStore().getNodeById(target.getParameters().id);
- if (node && this._tree.getSelectionModel().isSelected(node))
- {
- // Same selection
- return;
- }
-
- var me = this;
- this._tree.suspendEvent('selectionchange');
- this._tree.selectNodesByPath ([target.getParameters().additionalData.path], null, function () {
- me._tree.resumeEvent('selectionchange');
- });
- }
- },
-
- /**
- * Listener when a Ametys.message.Message#MODIFIED message was received
- * @param {Ametys.message.Message} message The modified message
- * @private
- */
- _onMessageModified: function (message)
- {
- var target = message.getTarget(Ametys.message.MessageTarget.THESAURUS);
- if (target != null && this._isOnCurrentTree(target.getParameters().id))
- {
- this._updateInfos();
- return;
- }
-
- var target = message.getTarget(Ametys.message.MessageTarget.MICROTHESAURUS);
- if (target != null && this._isOnCurrentTree(target.getParameters().thesaurusId))
- {
- // TODO ne pas recharger l'arbre
- this._tree.loadMicrothesaurii (target.getParameters().id);
- return;
- }
-
- target = message.getTarget(new RegExp("^" + Ametys.message.MessageTarget.CONTENT + "|" + Ametys.message.MessageTarget.THESAURUS_CANDIDATE + "$"));
- if (target != null)
- {
- var node = this._tree.getStore().getNodeById(target.getParameters().id);
- if (node)
- {
- node.set('text', target.getParameters().title);
- node.commit();
- }
- this._tree.refreshNode (target.getParameters().id);
- }
- },
-
- /**
- * Listener when a Ametys.message.Message#CREATED message was received
- * @param {Ametys.message.Message} message The modified message
- * @private
- */
- _onMessageCreated: function (message)
- {
- var target = message.getTarget(Ametys.message.MessageTarget.MICROTHESAURUS);
- if (target != null && this._isOnCurrentTree(target.getParameters().thesaurusId))
- {
- this._tree.loadMicrothesaurii (target.getParameters().id);
- return;
- }
-
- var target = message.getTarget(Ametys.message.MessageTarget.CONTENT);
- if (target != null && this._isOnCurrentTree(target.getParameters().additionalData.thesaurusId, target.getParameters().additionalData.microthesaurusId))
- {
- // Force leaf to false on parent node
- var node = this._tree.getStore().getNodeById(target.getParameters().additionalData.parentId);
- if (node != null)
- {
- node.set('leaf', false);
- }
- // Then refresh parent node
- this._tree.refreshNode (target.getParameters().additionalData.parentId || target.getParameters().additionalData.microthesaurusId);
- }
-
- var target = message.getTarget(Ametys.message.MessageTarget.THESAURUS_CANDIDATE);
- if (target != null && this._isOnCurrentTree(target.getParameters().additionalData.thesaurusId, target.getParameters().additionalData.microthesaurusId))
- {
- var node = this._tree.getStore().getNodeById(target.getParameters().additionalData.parentId);
- if (node != null)
- {
- // Then refresh parent node
- this._tree.refreshNode (target.getParameters().additionalData.parentId);
- }
- else
- {
- // Root node for candidates does not exist, refresh root node
- this._tree.refreshNode (this._tree.getRootNode().getId());
- }
- }
- },
-
- /**
- * Listener when a Ametys.message.Message#DELETED message was received
- * @param {Ametys.message.Message} message The modified message
- * @private
- */
- _onMessageDeleted: function (message)
- {
- var target = message.getTarget(Ametys.message.MessageTarget.THESAURUS);
- if (target != null && target.getParameters().id == this._thesaurusId)
- {
- this.close();
- return;
- }
-
- var target = message.getTarget(Ametys.message.MessageTarget.MICROTHESAURUS);
- if (target != null && this._isOnCurrentTree(target.getParameters().thesaurusId))
- {
- this._tree.loadMicrothesaurii ();
- return;
- }
-
- var target = message.getTarget(Ametys.message.MessageTarget.CONTENT);
- if (target != null && this._isOnCurrentTree(target.getParameters().additionalData.thesaurusId, target.getParameters().additionalData.microthesaurusId))
- {
- this._tree.deleteNode (target.getParameters().id);
- }
-
- var target = message.getTarget(Ametys.message.MessageTarget.THESAURUS_CANDIDATE);
- if (target != null && this._isOnCurrentTree(target.getParameters().additionalData.thesaurusId, target.getParameters().additionalData.microthesaurusId))
- {
- this._tree.deleteNode (target.getParameters().id);
- }
- },
-
- /**
- * Determines if the tool is concerned with the last update
- * @param {String} thesaurusId The id of thesaurus concerned with the update
- * @param {String} microthesaurusId The id of microthesaurus concerned with the update. Can be null.
- * @return {Boolean} true if the tool is concerned with the last update
- * @private
- */
- _isOnCurrentTree: function (thesaurusId, microthesaurusId)
- {
- if (thesaurusId == null || this._thesaurusId != thesaurusId)
- {
- return false;
- }
-
- return microthesaurusId == null || this.getMicrothesaurusId() == microthesaurusId;
- }
-});
-
Index: main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTool.js
===================================================================
--- main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTool.js (revision 30361)
+++ main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTool.js (working copy)
@@ -103,6 +103,7 @@
this.callParent (arguments);
this._thesaurusId = params['id'];
+ this._thesaurusLabel = params['label'];
this.refresh();
},
@@ -251,9 +252,7 @@
this._thesaurusLabel = result.label;
- this.setInfo ({
- title: result.label
- });
+ this.setTitle(result.label);
this._tree.loadMicrothesaurii (null, Ext.bind(this._refreshCb, this));
},
Index: main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTreePanel.i18n.js
===================================================================
--- main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTreePanel.i18n.js (revision 32275)
+++ main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTreePanel.i18n.js (working copy)
@@ -1,1076 +0,0 @@
-/*
- * Copyright 2014 Anyware Services
- *
- * 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.
- */
-
-/**
- * This class provides a TreePanel for thesaurus
- * The tree includes a toolbar which allow to :
- * - filter resources on name,
- * - refresh a node
- * - expand a node
- * - collapse the all tree.
- * The default tree store uses the {@link Ametys.plugins.thesaurus.tool.TermEntry} model. Override the #createTreeStore method to use another Model.
- * @private
- */
-Ext.define('Ametys.plugins.thesaurus.tool.ThesaurusTreePanel', {
- extend: 'Ext.tree.Panel',
-
- /**
- * @cfg {String} thesaurusId The id of root thesaurus
- */
-
- /**
- * @property {String} _thesaurusId See {#cfg-thesaurusId}
- * @private
- */
-
- /**
- * @cfg {String} microthesaurusId The id of microthesaurus. Can be null to choose microthesaurus in a list
- */
-
- /**
- * @property {String} _microthesaurusId See {#cfg-microthesaurusId}
- */
-
- /**
- * @cfg {Boolean} hideCandidates=false Set to true to hide candidates
- */
-
- /**
- * @property {Boolean} _hideCandidates See {#cfg-hideCandidates}
- */
-
- /**
- * @cfg {Boolean} checkMode=false To select terms by checkboxes
- */
- checkMode : false,
-
- cls: 'thesaurus-tree',
-
- /**
- * @cfg {String} The css class for synonym node
- */
- synonymCls: 'synonym',
-
- statics: {
- /**
- * The default filter.
- */
- DEFAULT_FILTER: function(node)
- {
- return node ? true : false;
- }
- },
-
- initComponent: function ()
- {
- Ext.apply(this, {
- folderSort: false,
- root: {
- text: "
",
- hasChild: true,
- editable: false,
- allowDrag: false,
- allowDrop: false,
- expanded: true,
- name: '',
- type: 'microthesaurus',
- iconCls: 'tree-icon-microthesaurus',
- loaded: true // Prevent AJAX request
- },
- store: this.createTreeStore()
- });
-
- this.callParent();
- },
-
- constructor: function (config)
- {
- this._thesaurusId = config.thesaurusId;
- this._microthesaurusId = config.microthesaurusId;
- this._hideCandidates = config.hideCandidates || false;
-
- config.rootVisible = config.rootVisible || false;
-
- // Docked items
- config.dockedItems = this.getDockItems(config);
-
- // No result panel
- var noResultPanelCfg = this._getNoResultPanelCfg();
- if (noResultPanelCfg)
- {
- noResultPanelCfg.dock = noResultPanelCfg.dock || 'top';
- config.dockedItems.push(noResultPanelCfg);
- }
-
- this._filterConfig = config.filter || Ametys.plugins.thesaurus.tool.ThesaurusTreePanel.DEFAULT_FILTER;
-
- this._counter = {};
- this._filterValue = null;
-
- this.callParent(arguments);
-
- if (this.checkMode)
- {
- this.on ('beforeitemappend', this._setCheckedProperty, this);
- }
- },
-
- /**
- * @private
- * Listen to the beforeappend event of the tree store, to set the 'checked' property on node
- * @param {Ext.data.NodeInterface} node The current node
- * @param {Ext.data.NodeInterface} child The child node to be appended
- */
- _setCheckedProperty: function(node, child)
- {
- var type = child.get('type');
- if (type == 'term' || type == 'candidate')
- {
- child.set('checked', false);
- }
- },
-
- /**
- * Get the dock items
- * @param {Object} config The initial tree panel configuration
- * @return {Object[]} The dock items configuration
- */
- getDockItems: function (config)
- {
- var dockedItems = config.dockedItems || [];
-
- if (!this._microthesaurusId)
- {
- var comboCfg = this._getMicroThesaurusComboCfg();
- comboCfg.dock = comboCfg.dock || 'top';
- dockedItems.push(comboCfg);
- }
-
- var topToolbarCfg = this._getTopToolbarCfg();
- if (topToolbarCfg)
- {
- topToolbarCfg.dock = topToolbarCfg.dock || 'top';
- dockedItems.push(topToolbarCfg);
- }
-
- var bottomToolbarCfg = this._getBottomToolbarCfg();
- if (bottomToolbarCfg)
- {
- bottomToolbarCfg.dock = bottomToolbarCfg.dock || 'bottom';
- dockedItems.push(bottomToolbarCfg);
- }
-
- return dockedItems;
- },
-
- /**
- * Returns the combo box of microthesaurii
- * @return {Ext.form.ComboBox} The combo box
- */
- getMTComboBox: function ()
- {
- return this.getDockedItems('form[dock="top"]')[0].down('combo');
- },
-
- /**
- * Get the selected MicroThesaurus
- * @return {Ametys.plugins.thesaurus.tool.MicrothesaurusEntry} the microthesaurus
- */
- getSelectedMT: function()
- {
- return this._microThesaurusStore.getById(this.getMTComboBox().getValue());
- },
-
- /**
- * @protected
- * Get configuration object for combox box of microthesaurii
- * @return {Ext.form.ComboBox} The combo box
- */
- _getMicroThesaurusComboCfg: function ()
- {
- this._microThesaurusStore = Ext.create('Ext.data.Store', {
- model: 'Ametys.plugins.thesaurus.tool.MicrothesaurusEntry',
- sortOnLoad: true,
- sorters: [{property: 'label', direction:'ASC'}],
- proxy: {
- type: 'ametys',
- plugin: 'thesaurus',
- url: 'microthesaurus-list',
- extraParams: {id: this._thesaurusId},
- reader: {
- type: 'xml',
- record: '> Node'
- }
- },
- autoLoad: false
- });
-
- return {
- xtype: 'form',
- border: false,
- layout: 'column',
- cls: 'thesaurus-tree-form',
-
- items: [{
- xtype: 'combobox',
- columnWidth: 1,
-
- typeAhead: true,
- forceSelection: true,
- triggerAction: 'all',
- cls: 'ametys',
-
- labelSeparator: '',
- labelWidth: 90,
- name: 'microthesaurus',
- fieldLabel: "
",
- store: this._microThesaurusStore,
- valueField: 'id',
- displayField: 'label',
-
- listConfig: {
- cls: 'ametys-boundlist'
- },
-
- listeners: {
- 'select': Ext.bind (this._microThesaurusComboSelect, this)
- }
- }]
- }
- },
-
- /**
- * @protected
- * Retrieves the bottom toolbar config object.
- */
- _getBottomToolbarCfg: function()
- {
- if (!this._hideCandidates)
- {
- return {
- xtype: 'panel',
- layout: 'column',
- border: false,
- cls: 'thesaurus-tree-toolbar',
- defaultType: 'button',
- items: [{
- // Add candidate
- text: "
",
- tooltip: "
",
- handler: Ext.bind (this._createCandidate, this),
- icon: Ametys.getPluginResourcesPrefix('thesaurus') + '/img/actions/add_candidate_16.png',
- cls: 'x-btn-text-icon'
- }]
- };
- }
- return null;
- },
-
- /**
- * @protected
- * Retrieves the top toolbar config object.
- */
- _getTopToolbarCfg: function()
- {
- return {
- xtype: 'panel',
- layout: 'column',
- border: false,
- cls: 'thesaurus-tree-toolbar',
- defaultType: 'button',
- items: [{
- // Search input
- xtype: 'textfield',
- columnWidth: 1,
- itemId: 'search-filter-input',
- emptyText: "
",
- enableKeyEvents: true,
- minLength: 3,
- minLengthText: "
",
- msgTarget: 'qtip',
- listeners: {keyup: { fn: this._onKeyUp, scope: this, delay: 500}}
- },
- {
- // Clear filter
- width: 20,
- tooltip: "
",
- handler: Ext.bind (this._clearSearchFilter, this),
- icon: Ametys.getPluginResourcesPrefix('cms') + '/img/tree/clear.gif',
- cls: 'x-btn-text-icon',
- style: {
- marginRight: '20px'
- }
- },
- {
- // Expand node
- width: 20,
- tooltip: "
",
- handler: Ext.bind (this._expandNode, this, [], false),
- icon: Ametys.getPluginResourcesPrefix('cms') + '/img/tree/expand-all.gif',
- cls: 'x-btn-text-icon'
- },
- {
- // Collapse all
- width: 20,
- tooltip: "
",
- handler: Ext.bind (this.collapseAll, this),
- icon: Ametys.getPluginResourcesPrefix('cms') + '/img/tree/collapse-all.gif',
- cls: 'x-btn-text-icon'
- },
- {
- // Refresh node
- width: 20,
- tooltip: "
",
- handler: Ext.bind (this.refreshNode, this, [], false),
- icon: Ametys.getPluginResourcesPrefix('cms') + '/img/tree/refresh.png',
- cls: 'x-btn-text-icon'
- }
- ]
- };
- },
-
- /**
- * Create candidate
- * @param {Ext.Button} btn The button
- * @private
- */
- _createCandidate: function(btn)
- {
- Ametys.plugins.thesaurus.helper.EditCandidateHelper.open (Ametys.getPluginResourcesPrefix('thesaurus') + '/img/actions/add_candidate_16.png',
- "
", Ext.bind(this._doCreateCandidate, this));
- },
-
- /**
- * @private
- * Creates a new candidate
- * @param {String} label The label
- * @param {String} comment The comment
- */
- _doCreateCandidate: function (label, comment)
- {
- var microthesaurusId = this.getRootNode().getId();
-
- Ametys.data.ServerComm.callMethod({
- role: "org.ametys.plugins.thesaurus.ThesaurusDAO",
- methodName: 'createCandidate',
- parameters: [label, comment, 'fr', microthesaurusId], // FIXME fr hard coded
- errorMessage: "
",
- callback: {
- handler: this._createCandidateCb,
- scope: this
- }
- });
- },
-
- /**
- * @private
- * Callback function after creating candidate
- * @param {Object} result The result object
- * @param {Object[]} args The callback arguments
- */
- _createCandidateCb: function(result, args)
- {
- var checkedNodesBeforeRefresh = this.checkMode ? this.getChecked() : [];
-
- var node = this.getStore().getNodeById(result.parentId);
- if (node != null)
- {
- // Refresh parent node
- this.refreshNode (result.parentId, Ext.bind (this._checkNodesAfterRefresh, this, [checkedNodesBeforeRefresh], true));
- }
- else
- {
- // Root node for candidates does not exist, refresh root node
- this.refreshNode (this.getRootNode().getId(), Ext.bind (this._checkNodesAfterRefresh, this, [checkedNodesBeforeRefresh], true));
- }
- },
-
- /**
- * Check nodes after a refresh
- * @param {Ext.data.NodeInterface} node The refreshed node
- * @param {Ext.data.NodeInterface[]} checkedNodes The checked nodes before refreshing
- * @private
- */
- _checkNodesAfterRefresh: function (node, checkedNodes)
- {
- if (checkedNodes.length > 0)
- {
- var paths = [];
- Ext.Array.each (checkedNodes, function (node) {
- paths.push (node.getPath('name').substring(1));
- })
-
- this.expandNodesByPath(paths, node, function (success, lastNode) {
- if (success)
- {
- lastNode.set('checked', true);
- }
- });
- }
- },
-
- /**
- * @protected
- * Retrieves the 'no result' panel config
- */
- _getNoResultPanelCfg: function()
- {
- var html = "
";
- html += this._hideCandidates ? "
" : "
"
-
- var cfg = {
- xtype: 'component',
- itemId: 'noresult',
- cls: 'no-result-panel',
- hidden: true,
- html: html,
- listeners: {
- click: {
- fn: this._hideCandidates ? this._clearSearchFilter : this._createCandidateFromFilter,
- scope: this,
- element: 'el'
- }
- }
- };
-
- return cfg;
- },
-
- /**
- * This listener is called on 'keyup' event on filter input field.
- * Filters the tree by text input.
- * @param {Ext.form.Field} field The field
- * @private
- */
- _onKeyUp: function (field)
- {
- var value = new String(field.getValue()).trim();
- this._filterField = field;
-
- if (this._filterValue == value)
- {
- // Do nothing
- return;
- }
-
- this._filterValue = value;
-
- if (value.length > 2)
- {
- var rootNode = this.getRootNode();
- this._getFilteredTerms (value, rootNode);
- }
- else
- {
- this._hideNoResultPanel();
- this.clearFilter();
- }
- },
-
- /**
- * Clear all filters
- */
- clearFilter: function (node)
- {
- node = node || this.getRootNode();
-
- var view = this.getView();
-
- node.cascadeBy( function(node) {
- if (node.get('cls') == this.synonymCls)
- {
- node.set('cls','');
- }
- var uiNode = view.getNodeByRecord(node);
-
- if (uiNode)
- {
- this._filterConfig(node) ? Ext.get(uiNode).setDisplayed('table-row') : Ext.get(uiNode).setDisplayed('none');
- }
- }, this);
- },
-
- /**
- * Filters by a set of function. The specified function will be called for each Record in this Store.
- * If the function returns true the Record is included, otherwise it is filtered out.
- * @param {Function/Function[]} filterFn A function or a set of functions to be called. It will be passed the following parameters:
- * @param {Ext.data.Model} [node=root node] The node to test for filtering
- */
- filterBy: function (filterFn, node)
- {
- node = node || this.getRootNode();
-
- if (!Ext.isArray(filterFn))
- {
- filterFn = [filterFn];
- }
-
- var view = this.getView();
-
- node.cascadeBy( function (node) {
-
- var uiNode = view.getNodeByRecord(node);
-
- var display = true;
- for (var i=0; i < filterFn.length; i++)
- {
- display = display && filterFn[i](node);
- }
-
- if (uiNode)
- {
- display ? Ext.get(uiNode).setDisplayed('table-row') : Ext.get(uiNode).setDisplayed('none');
- }
- }, this);
-
- var selection = this.getSelectionModel().getSelection();
- var currentNode = selection.length > 0 ? selection[0] : null;
- if (currentNode)
- {
- var uiNode = this.getView().getNodeByRecord(currentNode);
- if (!uiNode || Ext.get(uiNode) == null || !Ext.get(uiNode).isVisible(true))
- {
- this.getSelectionModel().deselectAll();
- }
- }
- },
-
- /**
- * Get the terms the name matches the given value
- * @param {String} value The value to match
- * @param {Ext.data.Model} rootNode The root node
- * @param {Ext.data.Model} node The initial node to search from. Can be null. If null start from root node.
- * @param {Function} [callback] The function called on server response. Transmited to #_filterTermsCb.
- * @private
- */
- _getFilteredTerms: function (value, rootNode, node, callback)
- {
- node = node || rootNode;
-
- Ametys.data.ServerComm.callMethod({
- role: "org.ametys.plugins.thesaurus.ThesaurusDAO",
- methodName: 'filterTermsByRegExp',
- parameters: [value, node.getId()],
- errorMessage: "
",
- callback: {
- handler: this._filterTermsCb,
- scope: this,
- arguments: {
- node: node,
- callback: callback
- }
- }
- });
- },
-
- /**
- * @private
- * Callback function after searching terms
- * @param {Object} result The result object
- * @param {Object[]} args The callback arguments
- */
- _filterTermsCb: function(result, args)
- {
- var paths = result.paths;
- var hasResult = false;
- var node = args.node || this.getRootNode();
- var callback = args.callback;
-
- if (!paths)
- {
- return;
- }
-
-
- if (paths.length == 0)
- {
- this.filterBy (function () {return false});
- }
- else
- {
- hasResult = true;
- this._expandAndFilter (paths, this.getRootNode(), node);
- }
-
- if (!hasResult)
- {
- this._showNoResultPanel();
- this.getSelectionModel().deselectAll();
- Ext.defer (this._filterField.markInvalid, 100, this._filterField, ["
"]);
- }
- else
- {
- this._hideNoResultPanel();
- this._filterField.clearInvalid();
- }
-
- if (Ext.isFunction(callback))
- {
- callback();
- }
- },
-
- /**
- * Create a new candidate from filter value
- * @param {Ext.Button} btn The clicked button
- * @private
- */
- _createCandidateFromFilter: function (btn)
- {
- var topItems = this.getDockedItems('panel[dock="top"]');
- var filterValue = topItems[topItems.length - 1].down('#search-filter-input').getValue();
-
- var me = this;
- Ametys.plugins.thesaurus.helper.EditCandidateHelper.open (Ametys.getPluginResourcesPrefix('thesaurus') + '/img/actions/add_candidate_16.png',
- "
", function (label, comment) {
- me._clearSearchFilter();
- me._doCreateCandidate(label, comment);
- },
- filterValue);
- },
-
- /**
- * Clear the filter search
- * @param {Ext.Button} btn The button
- * @private
- */
- _clearSearchFilter: function(btn)
- {
- this.clearFilter();
-
- var topItems = this.getDockedItems('panel[dock="top"]');
- topItems[topItems.length - 1].down('#search-filter-input').reset();
-
- this._filterValue = null;
-
- this._hideNoResultPanel();
- },
-
- /**
- * Hide the panel showing there is no result.
- * @private
- */
- _hideNoResultPanel: function ()
- {
- var noResultPanel = this.getDockedItems('#noresult')[0];
- if (noResultPanel)
- {
- noResultPanel.hide();
- }
- },
-
- /**
- * Show the panel showing there is no result.
- * @private
- */
- _showNoResultPanel: function ()
- {
- var noResultPanel = this.getDockedItems('#noresult')[0];
- if (noResultPanel)
- {
- noResultPanel.show();
- }
- },
-
- /**
- * Expand the tree to the given paths. Then filter nodes matching the given paths by calling the #_filterPaths method
- * @param {Object[]} paths The paths to expand
- * @param {Ext.data.Model} rootNode The concerned root node
- * @param {Ext.data.Model} node The node from which apply filter
- * @private
- */
- _expandAndFilter: function(paths, rootNode, node)
- {
- node = node || rootNode;
-
- this._counter[rootNode.getId()] = paths.length;
- for (var i=0; i < paths.length; i++)
- {
- var path = paths[i].path;
- this.expandPath (rootNode.getPath('name') + '/' + paths[i].path, 'name', null, Ext.bind (this._filterPaths, this, [paths, rootNode, node, paths[i].matchSynonyms || false], true));
- }
- },
-
- /**
- * Filter nodes by path once the last expand has been processed
- * @param {Boolean} success true if the expand was successful
- * @param {Ext.data.Model} lastNode the last node that was expanded
- * @param {String[]} paths The path to filter by
- * @param {Ext.data.Model} rootNode The concerned root node
- * @param {Ext.data.Model} node The node from which apply filter
- * @param {Boolean} matchSynonyms 'true' if the filter matched thank to synomyns
- * @private
- */
- _filterPaths: function (success, lastNode, paths, rootNode, node, matchSynonyms)
- {
- if (matchSynonyms)
- {
- lastNode.set('cls', this.synonymCls);
- }
-
- // only execute the filterBy after the last expandPath()
- if (--this._counter[rootNode.getId()] == 0)
- {
- var filterFn = Ext.bind (this._filterByPath, this, [paths, rootNode], true);
-
- // FIXME Ensure that expand is complete by deferring the filterBy function ...
- Ext.defer(this.filterBy, 50, this, [filterFn, node]);
- }
-
- },
-
- /**
- * Returns true if the node path is a part of given paths
- * @param {Ext.data.Model} node The node to test
- * @param {String[]} paths The paths
- * @param {Ext.data.Model} rootNode The root node to build the complete paths
- * @private
- */
- _filterByPath: function (node, paths, rootNode)
- {
- var currentPath = node.getPath('name');
- for (var i=0; i < paths.length; i++)
- {
- var path = rootNode.getPath('name') + '/' + paths[i].path;
- if (path.indexOf(currentPath + '/') == 0)
- {
- return true;
- }
-
- if (path == currentPath)
- {
- return this._filterConfig(node);
- }
- }
- return false;
- },
-
- /**
- * @protected
- * Create the tree store
- * @param {Object} config The tree panel configuration
- * @return {Ext.data.TreeStore} The created tree store
- */
- createTreeStore: function (config)
- {
- var store = Ext.create('Ext.data.TreeStore', Ext.apply({
- model: 'Ametys.plugins.thesaurus.tool.TermEntry',
- proxy: {
- type: 'ametys',
- plugin: 'thesaurus',
- url: 'microthesaurus-nodes',
- reader: {
- type: 'xml',
- root: 'Nodes',
- record: '> Node'
- }
- }
- }, this._getStoreSortInfo()));
-
- store.addListener ('beforeload', this._onStoreBeforeLoad, this);
- return store;
-
- },
-
- /**
- * @private
- * Set the request parameters before loading the store.
- * @param {Ext.data.Store} store The store.
- * @param {Ext.data.Operation} operation The Ext.data.Operation object that will be passed to the Proxy to load the Store.
- */
- _onStoreBeforeLoad: function (store, operation)
- {
- operation.params = operation.params || {};
- operation.params.hideCandidates = this._hideCandidates;
- },
-
- /**
- * @protected
- * Must return an object containing sort configuration property for the internal {@link Ext.data.TreeStore}
- */
- _getStoreSortInfo: function()
- {
- return {
- sorters: [{
- sorterFn: function(o1, o2){
- if (o1.data.type == 'root-candidates')
- {
- return 1;
- }
- else if (o2.data.type == 'root-candidates')
- {
- return -1;
- }
- else
- {
- return 0;
- }
- }
- },
- // Alphabetical sort
- {property: 'text', direction:'ASC'}]
- };
- },
-
- /**
- * Get the current selected node (folder)
- * @return {Ext.data.NodeInterface} The selected node
- */
- getSelectedNode: function()
- {
- return this.getSelectionModel().getSelection()[0];
- },
-
- /**
- * Load the microthesaurii
- * @param {String} [microThesaurusId] The id of microthesaurus to select after loading. Can be null.
- * @param {Function} [callback] The callback function to call after loading success
- */
- loadMicrothesaurii: function (microThesaurusId, callback)
- {
- if (!this._microthesaurusId)
- {
- // Load microthesaurus combobox
- Ext.apply(this._microThesaurusStore.getProxy().extraParams, {id: this._thesaurusId});
-
- this._microThesaurusStore.load({
- scope: this,
- callback: function(records, operation, success) {
- if (this._microThesaurusStore.getCount() >= 1)
- {
- var selectedMT = microThesaurusId != null ? this._microThesaurusStore.getById(microThesaurusId) : this._microThesaurusStore.getAt(0);
-
- var selectedMTId = selectedMT.get(this.getMTComboBox().valueField, true);
- var selectedMTLabel = selectedMT.get(this.getMTComboBox().displayField, true);
-
- var rootNode = this.getRootNode();
- rootNode.set('text', selectedMTLabel);
- rootNode.set('label', selectedMTLabel);
- rootNode.set('name', '');
- rootNode.setId (selectedMTId);
- rootNode.commit();
-
- this.getMTComboBox().setValue(selectedMTId);
- this.getSelectionModel().deselectAll();
-
- this.getStore().load({
- params: {
- node: selectedMTId
- },
- scope:this,
- callback: function (records, operation, success) {
-
- this.getSelectionModel().select(this.getRootNode());
-
- if (Ext.isFunction(callback))
- {
- callback();
- }
- }
- });
- }
- else
- {
- if (Ext.isFunction(callback))
- {
- callback();
- }
- }
- }
- });
- }
- else
- {
- var rootNode = this.getRootNode();
- rootNode.set('name', '');
- rootNode.setId (this._microthesaurusId);
- rootNode.commit();
-
- this.getStore().load({
- params: {
- node: this._microthesaurusId
- },
- scope:this,
- callback: function (records, operation, success) {
-
- this.getSelectionModel().select(this.getRootNode());
-
- if (Ext.isFunction(callback))
- {
- callback();
- }
- }
- });
- }
-
- },
-
- /**
- * Deletes a node from the tree and selects the parent node.
- * @param {String} id The id of the node to delete.
- * @private
- */
- deleteNode: function(id)
- {
- var node = this.getStore().getNodeById(id);
-
- if (node != null)
- {
- var parentNode = node.parentNode;
- this.getSelectionModel().select([parentNode]);
- node.remove();
- }
- },
-
- /**
- * This function reload the given node
- * @param {String} id The id of the node to reload
- * @param {Function} callback The callback function to call after reload. Can be null. Has the following parameters:
- * @param {Ext.data.Model} callback.node The refreshed node
- */
- refreshNode: function (id, callback)
- {
- var node;
- if (id == null)
- {
- var selection = this.getSelectionModel().getSelection();
- node = selection.length > 0 ? selection[0] : null;
-
- // Workaround - Refresh selection in case node is not existing anymore (deleted by another user for example).
- this.getSelectionModel().deselect(node);
- this.getSelectionModel().select(node);
- }
- else
- {
- node = this.getStore().getNodeById(id);
- }
-
- if (node != null)
- {
- // Set leaf to false, to allow children to be added during the load. Leaf will be set to true again if needed after the load.
- node.set('leaf', false);
-
- this.getStore().load({
- node: node,
- callback: function() {
-
- if (this._filterValue && this._filterValue.length > 2)
- {
- this._getFilteredTerms (this._filterValue, this.getRootNode(), node, callback ? Ext.bind(callback, null, [node]) : null);
- }
- else
- {
- Ext.defer(this._expandNode, 200, this, [node, callback]);
- }
-
-
- },
- scope: this
- });
- }
- },
-
- /**
- * Expand the given node
- * @param {String} node The node to expand.
- * @param {Function} callback The callback function to call after reload. Can be null. Has the following parameters:
- * @param {Ext.data.Model} callback.node The expended node
- * @private
- */
- _expandNode: function (node, callback)
- {
- if (node == null)
- {
- var selection = this.getSelectionModel().getSelection();
- node = selection.length > 0 ? selection[0] : null;
- }
-
- if (node != null)
- {
- if (!node.hasChildNodes())
- {
- node.set('leaf', true);
- }
-
- callback = callback ? Ext.bind(callback, null, [node]) : null;
- this.expandNode (node, false, callback);
- }
- },
-
- /**
- * @private
- * Listener when a item is selected in the list. Reload the tree.
- * @param {Ext.form.field.ComboBox} combo The combox box
- * @param {Array} records The selected records
- * @param {Object} eOpts The options
- */
- _microThesaurusComboSelect: function(combo, records, eOpts)
- {
- this.getSelectionModel().deselectAll();
- this._clearSearchFilter();
-
- var rootNode = this.getRootNode();
- rootNode.setId (records[0].getId());
- rootNode.set ('text', records[0].get ('label'));
- rootNode.set ('label', records[0].get ('label'));
- rootNode.set('name', '');
- rootNode.commit();
-
- this.getStore().load({
- params: {
- node: records[0].getId()
- },
- scope:this,
- callback: function (records, operation, success) {
- this.getSelectionModel().select(this.getRootNode());
- }
- });
- },
-
- /**
- * Expand the tree to the given paths.
- * @param {String[]} paths The paths to expand
- * @param {Ext.data.Model} rootNode The concerned root node
- * @param {Function} callback The callback function to call after expand. Can be null.
- */
- expandNodesByPath: function(paths, rootNode, callback)
- {
- var rootNode = rootNode || this.getRootNode();
-
- for (var i=0; i < paths.length; i++)
- {
- this.expandPath (rootNode.getPath('name') + '/' + paths[i], 'name', null, callback);
- }
- },
-
- /**
- * Select a node in the tree. The full AmetysObject path is required.
- * @param {String[]} paths The paths of node to select
- * @param {Ext.data.Model} rootNode The concerned root node
- * @param {Function} callback The callback function to call after selection. Can be null.
- */
- selectNodesByPath: function(paths, rootNode, callback)
- {
- var rootNode = rootNode || this.getRootNode();
-
- for (var i=0; i < paths.length; i++)
- {
- this.selectPath (rootNode.getPath('name') + '/' + paths[i], 'name', null, callback);
- }
- }
-
-});
-
Index: main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTreePanel.js
===================================================================
--- main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTreePanel.js (revision 32275)
+++ main/plugin-thesaurus/resources/js/Ametys/plugins/thesaurus/tool/ThesaurusTreePanel.js (working copy)
@@ -78,18 +78,7 @@
{
Ext.apply(this, {
folderSort: false,
- root: {
- text: "
",
- hasChild: true,
- editable: false,
- allowDrag: false,
- allowDrop: false,
- expanded: true,
- name: '',
- type: 'microthesaurus',
- iconCls: 'tree-icon-microthesaurus',
- loaded: true // Prevent AJAX request
- },
+ root: this._getInitRootConfig(),
store: this.createTreeStore()
});
@@ -326,7 +315,7 @@
// Collapse all
width: 20,
tooltip: "
",
- handler: Ext.bind (this.collapseAll, this),
+ handler: Ext.bind (this.collapseAll, this, [], false),
icon: Ametys.getPluginResourcesPrefix('cms') + '/img/tree/collapse-all.gif',
cls: 'x-btn-text-icon'
},
@@ -700,7 +689,12 @@
for (var i=0; i < paths.length; i++)
{
var path = paths[i].path;
- this.expandPath (rootNode.getPath('name') + '/' + paths[i].path, 'name', null, Ext.bind (this._filterPaths, this, [paths, rootNode, node, paths[i].matchSynonyms || false], true));
+ var options = {
+ field: 'name',
+ separator: null,
+ callback: Ext.bind (this._filterPaths, this, [paths, rootNode, node, paths[i].matchSynonyms || false], 2)
+ };
+ this.expandPath (rootNode.getPath('name') + '/' + paths[i].path, options);
}
},
@@ -774,7 +768,7 @@
url: 'microthesaurus-nodes',
reader: {
type: 'xml',
- root: 'Nodes',
+ rootProperty: 'Nodes',
record: '> Node'
}
}
@@ -789,12 +783,13 @@
* @private
* Set the request parameters before loading the store.
* @param {Ext.data.Store} store The store.
- * @param {Ext.data.Operation} operation The Ext.data.Operation object that will be passed to the Proxy to load the Store.
+ * @param {Ext.data.operation.Operation} operation The Ext.data.Operation object that will be passed to the Proxy to load the Store.
*/
_onStoreBeforeLoad: function (store, operation)
{
- operation.params = operation.params || {};
- operation.params.hideCandidates = this._hideCandidates;
+ operation.setParams(Ext.apply(operation.getParams() || {}, {
+ hideCandidates: this._hideCandidates
+ }));
},
/**
@@ -853,61 +848,18 @@
{
var selectedMT = microThesaurusId != null ? this._microThesaurusStore.getById(microThesaurusId) : this._microThesaurusStore.getAt(0);
- var selectedMTId = selectedMT.get(this.getMTComboBox().valueField, true);
- var selectedMTLabel = selectedMT.get(this.getMTComboBox().displayField, true);
-
- var rootNode = this.getRootNode();
- rootNode.set('text', selectedMTLabel);
- rootNode.set('label', selectedMTLabel);
- rootNode.set('name', '');
- rootNode.setId (selectedMTId);
- rootNode.commit();
+ this._setRootNode(selectedMT);
- this.getMTComboBox().setValue(selectedMTId);
+ this.getMTComboBox().setValue(selectedMT.getId());
this.getSelectionModel().deselectAll();
- this.getStore().load({
- params: {
- node: selectedMTId
- },
- scope:this,
- callback: function (records, operation, success) {
-
- this.getSelectionModel().select(this.getRootNode());
-
- if (Ext.isFunction(callback))
- {
- callback();
- }
- }
- });
+ this.getSelectionModel().select(this.getRootNode());
}
else
{
- if (Ext.isFunction(callback))
- {
- callback();
- }
+ //we do not have some microthesaurus
+ this.getStore().setRoot(this._getInitRootConfig());
}
- }
- });
- }
- else
- {
- var rootNode = this.getRootNode();
- rootNode.set('name', '');
- rootNode.setId (this._microthesaurusId);
- rootNode.commit();
-
- this.getStore().load({
- params: {
- node: this._microthesaurusId
- },
- scope:this,
- callback: function (records, operation, success) {
-
- this.getSelectionModel().select(this.getRootNode());
-
if (Ext.isFunction(callback))
{
callback();
@@ -915,6 +867,21 @@
}
});
}
+ else
+ {
+ this.getStore().setRoot(Ext.apply(this.getStore().getRoot(), {
+ name: '',
+ id: this._microthesaurusId
+ }));
+
+ this.getSelectionModel().select(this.getRootNode());
+
+ if (Ext.isFunction(callback))
+ {
+ callback();
+ }
+ this.refreshNode();
+ }
},
@@ -950,15 +917,18 @@
node = selection.length > 0 ? selection[0] : null;
// Workaround - Refresh selection in case node is not existing anymore (deleted by another user for example).
- this.getSelectionModel().deselect(node);
- this.getSelectionModel().select(node);
+ if (node != null)
+ {
+ this.getSelectionModel().deselect(node);
+ this.getSelectionModel().select(node);
+ }
}
else
{
node = this.getStore().getNodeById(id);
}
- if (node != null)
+ if (node != null && node.getId() != 'root')
{
// Set leaf to false, to allow children to be added during the load. Leaf will be set to true again if needed after the load.
node.set('leaf', false);
@@ -1014,29 +984,55 @@
* @private
* Listener when a item is selected in the list. Reload the tree.
* @param {Ext.form.field.ComboBox} combo The combox box
- * @param {Array} records The selected records
- * @param {Object} eOpts The options
+ * @param {Ext.data.Model} record The selected record
+ * @param {Object} eOpts The options object passed to Ext.util.Observable.addListener.
*/
- _microThesaurusComboSelect: function(combo, records, eOpts)
+ _microThesaurusComboSelect: function(combo, record, eOpts)
{
this.getSelectionModel().deselectAll();
this._clearSearchFilter();
- var rootNode = this.getRootNode();
- rootNode.setId (records[0].getId());
- rootNode.set ('text', records[0].get ('label'));
- rootNode.set ('label', records[0].get ('label'));
- rootNode.set('name', '');
- rootNode.commit();
+ this._setRootNode(record);
- this.getStore().load({
- params: {
- node: records[0].getId()
- },
- scope:this,
- callback: function (records, operation, success) {
- this.getSelectionModel().select(this.getRootNode());
- }
+ this.getSelectionModel().select(this.getRootNode());
+ },
+
+ /**
+ * @private
+ * @return {Object} The config of the initial root node
+ */
+ _getInitRootConfig: function()
+ {
+ return {
+ text: "
",
+ leaf: true,
+ editable: false,
+ allowDrag: false,
+ allowDrop: false,
+ name: '',
+ type: 'microthesaurus',
+ iconCls: 'tree-icon-microthesaurus'
+ }
+ },
+
+ /**
+ * @private
+ * Set the root node to the given record
+ * @param {Ext.data.Model} record The selected record
+ */
+ _setRootNode: function(record)
+ {
+ this.getStore().setRoot({
+ id: record.getId(),
+ text: record.get ('label'),
+ editable: false,
+ allowDrag: false,
+ allowDrop: false,
+ expanded: true,
+ label: record.get ('label'),
+ name: '',
+ type: 'microthesaurus',
+ iconCls: 'tree-icon-microthesaurus'
});
},
Index: main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/MicroThesaurusNodeGenerator.java
===================================================================
--- main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/MicroThesaurusNodeGenerator.java (revision 32275)
+++ main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/MicroThesaurusNodeGenerator.java (working copy)
@@ -31,13 +31,13 @@
import org.xml.sax.SAXException;
import org.ametys.cms.repository.Content;
+import org.ametys.core.util.I18nUtils;
+import org.ametys.core.util.I18nizableText;
import org.ametys.plugins.repository.AmetysObject;
import org.ametys.plugins.repository.AmetysObjectIterable;
import org.ametys.plugins.repository.AmetysObjectResolver;
import org.ametys.plugins.repository.TraversableAmetysObject;
import org.ametys.plugins.thesaurus.content.ThesaurusItemContentType;
-import org.ametys.runtime.util.I18nUtils;
-import org.ametys.runtime.util.I18nizableText;
/**
* Generates a subtree of the resources explorer.
Index: main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/ThesaurusDAO.java
===================================================================
--- main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/ThesaurusDAO.java (revision 32275)
+++ main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/ThesaurusDAO.java (working copy)
@@ -50,6 +50,7 @@
import org.ametys.cms.repository.WorkflowAwareContentHelper;
import org.ametys.cms.workflow.AbstractContentWorkflowComponent;
import org.ametys.cms.workflow.ContentWorkflowHelper;
+import org.ametys.core.ui.Callable;
import org.ametys.plugins.repository.AmetysObject;
import org.ametys.plugins.repository.AmetysObjectIterable;
import org.ametys.plugins.repository.AmetysObjectResolver;
@@ -65,7 +66,6 @@
import org.ametys.plugins.repository.metadata.RichText;
import org.ametys.plugins.thesaurus.content.ThesaurusItemContentType;
import org.ametys.plugins.thesaurus.workflow.CreateTermFunction;
-import org.ametys.runtime.ui.Callable;
import com.opensymphony.workflow.WorkflowException;
Index: main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/clientsideelement/CompatibleTermMetadataFilter.java
===================================================================
--- main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/clientsideelement/CompatibleTermMetadataFilter.java (revision 32275)
+++ main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/clientsideelement/CompatibleTermMetadataFilter.java (working copy)
@@ -29,7 +29,7 @@
import org.ametys.plugins.thesaurus.Thesaurus;
import org.ametys.plugins.thesaurus.ThesaurusDAO;
import org.ametys.plugins.thesaurus.content.ThesaurusItemContentType;
-import org.ametys.runtime.util.I18nizableText;
+import org.ametys.core.util.I18nizableText;
/**
* This extension is used when dragging thesaurus terms on content.
Index: main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/clientsideelement/ThesaurusGallery.java
===================================================================
--- main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/clientsideelement/ThesaurusGallery.java (revision 32275)
+++ main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/clientsideelement/ThesaurusGallery.java (working copy)
@@ -23,11 +23,11 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.ametys.cms.ui.SimpleMenu;
+import org.ametys.core.ui.SimpleMenu;
import org.ametys.plugins.repository.AmetysObjectIterable;
import org.ametys.plugins.thesaurus.Thesaurus;
import org.ametys.plugins.thesaurus.ThesaurusDAO;
-import org.ametys.runtime.ui.Callable;
+import org.ametys.core.ui.Callable;
/**
* This element creates a menu with one gallery item per thesaurus.
Index: main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/parameter/TermsValidator.java
===================================================================
--- main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/parameter/TermsValidator.java (revision 32275)
+++ main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/parameter/TermsValidator.java (working copy)
@@ -22,9 +22,9 @@
import org.ametys.cms.repository.Content;
import org.ametys.plugins.repository.AmetysObjectResolver;
import org.ametys.plugins.thesaurus.ThesaurusDAO;
-import org.ametys.runtime.util.I18nizableText;
-import org.ametys.runtime.util.parameter.DefaultValidator;
-import org.ametys.runtime.util.parameter.Errors;
+import org.ametys.core.util.I18nizableText;
+import org.ametys.core.parameter.DefaultValidator;
+import org.ametys.runtime.parameter.Errors;
/**
Index: main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/search/IndexedContentsGenerator.java
===================================================================
--- main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/search/IndexedContentsGenerator.java (revision 32275)
+++ main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/search/IndexedContentsGenerator.java (working copy)
@@ -44,7 +44,7 @@
import org.ametys.cms.repository.Content;
import org.ametys.plugins.thesaurus.ThesaurusDAO;
import org.ametys.plugins.thesaurus.content.ThesaurusItemContentType;
-import org.ametys.runtime.plugins.core.dispatcher.ServerCommHelper;
+import org.ametys.core.util.ServerCommHelper;
/**
* SAX the contents indexed with one or more terms
Index: main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/search/SelectTermSearchGenerator.java
===================================================================
--- main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/search/SelectTermSearchGenerator.java (revision 32275)
+++ main/plugin-thesaurus/src/org/ametys/plugins/thesaurus/search/SelectTermSearchGenerator.java (working copy)
@@ -45,7 +45,7 @@
import org.ametys.plugins.repository.query.expression.StringExpression;
import org.ametys.plugins.thesaurus.MicroThesaurus;
import org.ametys.plugins.thesaurus.ThesaurusDAO;
-import org.ametys.runtime.plugins.core.dispatcher.ServerCommHelper;
+import org.ametys.core.util.ServerCommHelper;
/**
* Search generator used by 'edition.select-term' widget