Browse Source

HUE-292. The Chooser JFrame linker `data-chooseFor` name selector now starts form the FORM parent element of the link if it exists

Thomas Aylott 15 years ago
parent
commit
6d12431bd4
1 changed files with 35 additions and 34 deletions
  1. 35 34
      desktop/core/static/js/Source/JFrameLinkers/CCS.JFrame.Chooser.js

+ 35 - 34
desktop/core/static/js/Source/JFrameLinkers/CCS.JFrame.Chooser.js

@@ -19,45 +19,46 @@ description: Opens a CCS.FileChooser for any element with the ccs-choose_file, c
 provides: [CCS.JFrame.Chooser]
 provides: [CCS.JFrame.Chooser]
 requires: [/CCS.JFrame]
 requires: [/CCS.JFrame]
 script: CCS.JFrame.Chooser.js
 script: CCS.JFrame.Chooser.js
-
 ...
 ...
 */
 */
 
 
-(function(){
+;(function(){
 
 
-        var caption = {'dir': 'Choose A Directory',
-                        'file' : 'Choose A File',
-                        'any' : 'Choose A Path'
-        };
+var caption = {
+	'dir': 'Choose A Directory',
+	'file': 'Choose A File',
+	'any': 'Choose A Path'
+};
 
 
-        var chooser = function(filter) {
-                return function(e, link) {
-                        //Stop link from its standard action
-                        e.preventDefault();
-                        var targetName = link.get('data','chooseFor');
-                        var targetInput = $(this.parentWidget).getElement('input[name=' + targetName + ']');
-                        var jbrowser = this.parentWidget;
-                        //use parent widget to get jbrowser for CCS.chooseFile
-                        //CCS.chooseFile creates an ART alert which contains a FileChooser from which teh user can select a file.
-                //The function argument is the callback which is called after the OK button in the ART alert is clicked.
-                        CCS.Desktop.load("FileBrowser", function(){
-                                CCS.chooseFile(jbrowser, '/', caption[filter], function(data) {
-                                        targetInput.set('value', data.path);
-                                        targetInput.fireEvent('change');
-                                        //hide overtext on targetInput 
-                                        var overtext = targetInput.retrieve('OverText');
-                                        if(overtext) overtext.hide();
-                                }, {
-                                        filter: filter 
-                                });
-                        });
-                };
-        };
+var chooser = function(filter){
+	return function(e, link){
+		//Stop link from its standard action
+		e.preventDefault();
+		var targetName = link.get('data-chooseFor');
+		var parent = link.getParent('form') || $(this.parentWidget);
+		var targetInput = parent.getElement('input[name=' + targetName + ']');
+		var jbrowser = this.parentWidget;
+		//use parent widget to get jbrowser for CCS.chooseFile
+		//CCS.chooseFile creates an ART alert which contains a FileChooser from which teh user can select a file.
+		//The function argument is the callback which is called after the OK button in the ART alert is clicked.
+		CCS.Desktop.load("FileBrowser", function(){
+			CCS.chooseFile(jbrowser, '/', caption[filter], function(data){
+				targetInput.set('value', data.path);
+				targetInput.fireEvent('change');
+				//hide overtext on targetInput
+				var overtext = targetInput.retrieve('OverText');
+				if (overtext) overtext.hide();
+			}, {
+				filter: filter
+			});
+		});
+	};
+};
 
 
-        CCS.JFrame.addGlobalLinkers({
-                '.ccs-choose_file': chooser('file'), 
-                '.ccs-choose_dir': chooser('dir'), 
-                '.ccs-choose_path': chooser('any') 
-        });
+CCS.JFrame.addGlobalLinkers({
+	'.ccs-choose_file': chooser('file'),
+	'.ccs-choose_dir': chooser('dir'),
+	'.ccs-choose_path': chooser('any')
+});
 
 
 })();
 })();