Browse Source

HUE-139. Changing JFrame to allow Alert and Prompt to use their own Behavior instances

Marcus McLaughlin 15 years ago
parent
commit
750142317a

+ 25 - 16
desktop/core/static/js/Source/CCS/CCS.JFrame.js

@@ -129,18 +129,11 @@ CCS.JFrame = new Class({
 		});
 		});
 		if(this.options.size) this.behavior.resize(this.options.size.width, this.options.size.height);
 		if(this.options.size) this.behavior.resize(this.options.size.width, this.options.size.height);
 		['attachKeys', 'detachKeys', 'addShortcut', 'addShortcuts', 'removeShortcut', 'removeShortcuts',
 		['attachKeys', 'detachKeys', 'addShortcut', 'addShortcuts', 'removeShortcut', 'removeShortcuts',
-		 'applyDelegates', 'getScroller', 'getContentElement', 'invokeLinker'].each(function(method){
+		 'applyDelegates', 'getScroller', 'getContentElement', 'invokeLinker', 'configureRequest'].each(function(method){
 			this.behavior.passMethod(method, this[method].bind(this));
 			this.behavior.passMethod(method, this[method].bind(this));
 		}, this);
 		}, this);
 		this.behavior.passMethods({
 		this.behavior.passMethods({
 			getContainerSize: this.getCurrentSize.bind(this),
 			getContainerSize: this.getCurrentSize.bind(this),
-			configureRequest: function(request){
-				this._setRequestOptions(request, {
-					onSuccess: function(nodes, elements, text){
-						this._requestSuccessHandler(request, text);
-					}.bind(this)
-				});
-			}.bind(this),
 			registerKeyboard: function(keyboard){
 			registerKeyboard: function(keyboard){
 				this.keyboard.manage(keyboard);
 				this.keyboard.manage(keyboard);
 			}.bind(this),
 			}.bind(this),
@@ -160,6 +153,19 @@ CCS.JFrame = new Class({
 		if (this.options.size) this.resize(this.options.size.width, this.options.size.height);
 		if (this.options.size) this.resize(this.options.size.width, this.options.size.height);
 		this.load({requestPath: path});
 		this.load({requestPath: path});
 	},
 	},
+        
+        /*
+                configureRequest - configures a passed in request to be have its response rendered within JFrame..
+                request - (* request object *) request object to be configured
+        */
+        configureRequest: function(request){
+                this._setRequestOptions(request, {
+                        onSuccess: function(nodes, elements, text){
+                                this._requestSuccessHandler(request, text);
+                        }.bind(this)
+                });
+        },
+
 
 
 	toElement: function(){
 	toElement: function(){
 		return this.element;
 		return this.element;
@@ -358,15 +364,16 @@ CCS.JFrame = new Class({
 			title - (*string*) the title of the content
 			title - (*string*) the title of the content
 			view - (*string*; optional) if defined, the view of the content
 			view - (*string*; optional) if defined, the view of the content
 			viewElement - (*element*; optional) if defined, the element for the view
 			viewElement - (*element*; optional) if defined, the element for the view
+                behavior - (*behavior object*; optional) if defined, the behavior instance to use
 		
 		
 	*/
 	*/
 
 
-	fill: function(target, content){
+	fill: function(target, content, behavior){
 		target.empty().adopt(content.elements);
 		target.empty().adopt(content.elements);
 		if (content.links && content.links.length && this.options.includeLinkTags) target.adopt(content.links);
 		if (content.links && content.links.length && this.options.includeLinkTags) target.adopt(content.links);
 		if (this.options.evaluateJs && content.js) $exec(content.js);
 		if (this.options.evaluateJs && content.js) $exec(content.js);
 		this.applyDelegates(target);
 		this.applyDelegates(target);
-		this.applyFilters(target, content);
+		this.applyFilters(target, content, behavior || this.behavior);
 	},
 	},
 
 
 	resize: function(x, y){
 	resize: function(x, y){
@@ -449,9 +456,10 @@ CCS.JFrame = new Class({
 
 
 	//Applies all the behavior filters for an element.
 	//Applies all the behavior filters for an element.
 	//element - (element) an element to apply the filters registered with this Behavior instance to.
 	//element - (element) an element to apply the filters registered with this Behavior instance to.
+        //behavior - (behavior object) behavior instance to use 
 	//force - (boolean; optional) passed through to applyBehavior (see it for docs)
 	//force - (boolean; optional) passed through to applyBehavior (see it for docs)
-	applyBehaviors: function(element, force){
-		this.behavior.apply(element, force);
+	applyBehaviors: function(element, behavior, force){
+		behavior.apply(element, force);
 	},
 	},
 
 
 	//garbage collects all applied filters for the specified element
 	//garbage collects all applied filters for the specified element
@@ -463,14 +471,15 @@ CCS.JFrame = new Class({
 		applyFilters:
 		applyFilters:
 		container - (*element*) applies all the filters on this instance of jFrame to the contents of the container.
 		container - (*element*) applies all the filters on this instance of jFrame to the contents of the container.
 		content - (*object*) optional object containing various metadata about the content; js tags, meta tags, title, view, etc. See the "notes" section of the renderContent method comments in this file.
 		content - (*object*) optional object containing various metadata about the content; js tags, meta tags, title, view, etc. See the "notes" section of the renderContent method comments in this file.
-		
+                behavior - (*behavior object*) optional behavior instance to be used for application of behaviors
+	        	
 	*/
 	*/
 
 
-	applyFilters: function(container, content){
-		for (var name in this.filters) {
+	applyFilters: function(container, content, behavior){
+                for (var name in this.filters) {
 			this.applyFilter(name, container, content);
 			this.applyFilter(name, container, content);
 		}
 		}
-		this.applyBehaviors(container);
+		this.applyBehaviors(container, behavior || this.behavior);
 	},
 	},
 
 
 
 

+ 8 - 2
desktop/core/static/js/Source/JFrameRenderers/CCS.JFrame.Alert.js

@@ -34,11 +34,16 @@ CCS.JFrame.addGlobalRenderers({
 		var jframe_renders = popup.hasClass('jframe_renders');
 		var jframe_renders = popup.hasClass('jframe_renders');
 
 
 		var target = new Element('div', {'class': 'jframe_alert'}).hide().inject($(this));
 		var target = new Element('div', {'class': 'jframe_alert'}).hide().inject($(this));
+                var popupBehavior = new Behavior({
+                        onError: function(){
+                                dbug.warn.apply(dbug, arguments);
+                        }
+                });
 		var fillAndShow = function() {
 		var fillAndShow = function() {
 			if (!jframe_renders) {
 			if (!jframe_renders) {
 				//if we aren't rendering the jframe, fill the popup
 				//if we aren't rendering the jframe, fill the popup
 				//and remove the toolbar
 				//and remove the toolbar
-				this.fill(target, content);
+				this.fill(target, content, popupBehavior);
 				var toolbar = content.elements.filter('.toolbar');
 				var toolbar = content.elements.filter('.toolbar');
 				if (toolbar.length) toolbar.hide();
 				if (toolbar.length) toolbar.hide();
 			} else {
 			} else {
@@ -46,7 +51,7 @@ CCS.JFrame.addGlobalRenderers({
 				//the popup, hiding the original
 				//the popup, hiding the original
 				this.fill(target, {
 				this.fill(target, {
 					elements: $$(popup.clone())
 					elements: $$(popup.clone())
-				});
+				}, popupBehavior);
 				popup.hide();
 				popup.hide();
 			}
 			}
 			target.show();
 			target.show();
@@ -72,6 +77,7 @@ CCS.JFrame.addGlobalRenderers({
 						}.bind(this));
 						}.bind(this));
 					}
 					}
 				}
 				}
+                                alert.addEvent('destroy', function() {popupBehavior.cleanup(target);});
 				alert.position().show();
 				alert.position().show();
 				
 				
 				//if jframe is rendering we remove this event which we're going to add a few lines down
 				//if jframe is rendering we remove this event which we're going to add a few lines down

+ 15 - 3
desktop/core/static/js/Source/JFrameRenderers/CCS.JFrame.Prompt.js

@@ -2,7 +2,7 @@
 ---
 ---
 description: Any JFrame response that has a root-level child element with the class .prompt_popup is displayed in a prompt overlaying the previous state which is restored when the prompt is canceled.
 description: Any JFrame response that has a root-level child element with the class .prompt_popup is displayed in a prompt overlaying the previous state which is restored when the prompt is canceled.
 provides: [CCS.JFrame.Prompt]
 provides: [CCS.JFrame.Prompt]
-requires: [/CCS.JFrame, Widgets/ART.Alerts]
+requires: [/CCS.JFrame, Widgets/ART.Alerts, Widgets/Behavior]
 script: CCS.JFrame.Prompt.js
 script: CCS.JFrame.Prompt.js
 
 
 ...
 ...
@@ -31,11 +31,20 @@ CCS.JFrame.addGlobalRenderers({
 		var popup = content.elements.filter('.prompt_popup')[0];
 		var popup = content.elements.filter('.prompt_popup')[0];
 		if (!popup) return;
 		if (!popup) return;
 		var target = new Element('div', {'class': 'jframe_prompt'}).hide().inject($(this));
 		var target = new Element('div', {'class': 'jframe_prompt'}).hide().inject($(this));
+                var popupBehavior = new Behavior({
+                        onError: function(){
+                                dbug.warn.apply(dbug, arguments);
+                        }
+                });
+                popupBehavior.passMethods({
+                        getContentElement: $lambda(target),
+                        configureRequest: this.configureRequest.bind(this)
+                });
                 var fillAndShow = function() {
                 var fillAndShow = function() {
-                        this.fill(target, content);
+                        this.fill(target, content, popupBehavior);
                         target.show();
                         target.show();
                 }.bind(this);
                 }.bind(this);
-                //VML in IE doesn't like being hidden and redisplayed.  Delaying filling and showing the target for IE.
+                //VML in IE doesn't like being hidden and redisplayed.  Delaying filling and showing the target for 
                 if(!Browser.Engine.trident) {
                 if(!Browser.Engine.trident) {
                         fillAndShow();
                         fillAndShow();
                 }
                 }
@@ -51,6 +60,9 @@ CCS.JFrame.addGlobalRenderers({
                         detectInput: !hasInput,
                         detectInput: !hasInput,
 			resizable: true
 			resizable: true
 		});
 		});
+                prompt.addEvent('resize', function() {popupBehavior.resize.bind(popupBehavior);});
+                prompt.addEvent('destroy', function() {popupBehavior.cleanup(target); });
+                
                 if(Browser.Engine.trident) {
                 if(Browser.Engine.trident) {
                         fillAndShow();
                         fillAndShow();
                 }
                 }