Skip to content
This repository has been archived by the owner on Oct 27, 2019. It is now read-only.

Commit

Permalink
HUE-139. Changing JFrame to allow Alert and Prompt to use their own B…
Browse files Browse the repository at this point in the history
…ehavior instances
  • Loading branch information
Marcus McLaughlin committed Aug 11, 2010
1 parent 0b84495 commit 7501423
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
41 changes: 25 additions & 16 deletions desktop/core/static/js/Source/CCS/CCS.JFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,11 @@ CCS.JFrame = new Class({
});
if(this.options.size) this.behavior.resize(this.options.size.width, this.options.size.height);
['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);
this.behavior.passMethods({
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){
this.keyboard.manage(keyboard);
}.bind(this),
Expand All @@ -160,6 +153,19 @@ CCS.JFrame = new Class({
if (this.options.size) this.resize(this.options.size.width, this.options.size.height);
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(){
return this.element;
Expand Down Expand Up @@ -358,15 +364,16 @@ CCS.JFrame = new Class({
title - (*string*) the title of the content
view - (*string*; optional) if defined, the view of the content
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);
if (content.links && content.links.length && this.options.includeLinkTags) target.adopt(content.links);
if (this.options.evaluateJs && content.js) $exec(content.js);
this.applyDelegates(target);
this.applyFilters(target, content);
this.applyFilters(target, content, behavior || this.behavior);
},

resize: function(x, y){
Expand Down Expand Up @@ -449,9 +456,10 @@ CCS.JFrame = new Class({

//Applies all the behavior filters for an element.
//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)
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
Expand All @@ -463,14 +471,15 @@ CCS.JFrame = new Class({
applyFilters:
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.
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.applyBehaviors(container);
this.applyBehaviors(container, behavior || this.behavior);
},


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,24 @@ CCS.JFrame.addGlobalRenderers({
var jframe_renders = popup.hasClass('jframe_renders');

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() {
if (!jframe_renders) {
//if we aren't rendering the jframe, fill the popup
//and remove the toolbar
this.fill(target, content);
this.fill(target, content, popupBehavior);
var toolbar = content.elements.filter('.toolbar');
if (toolbar.length) toolbar.hide();
} else {
//otherwise we're going to leave the content object alone and clone
//the popup, hiding the original
this.fill(target, {
elements: $$(popup.clone())
});
}, popupBehavior);
popup.hide();
}
target.show();
Expand All @@ -72,6 +77,7 @@ CCS.JFrame.addGlobalRenderers({
}.bind(this));
}
}
alert.addEvent('destroy', function() {popupBehavior.cleanup(target);});
alert.position().show();

//if jframe is rendering we remove this event which we're going to add a few lines down
Expand Down
18 changes: 15 additions & 3 deletions desktop/core/static/js/Source/JFrameRenderers/CCS.JFrame.Prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
provides: [CCS.JFrame.Prompt]
requires: [/CCS.JFrame, Widgets/ART.Alerts]
requires: [/CCS.JFrame, Widgets/ART.Alerts, Widgets/Behavior]
script: CCS.JFrame.Prompt.js
...
Expand Down Expand Up @@ -31,11 +31,20 @@ CCS.JFrame.addGlobalRenderers({
var popup = content.elements.filter('.prompt_popup')[0];
if (!popup) return;
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() {
this.fill(target, content);
this.fill(target, content, popupBehavior);
target.show();
}.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) {
fillAndShow();
}
Expand All @@ -51,6 +60,9 @@ CCS.JFrame.addGlobalRenderers({
detectInput: !hasInput,
resizable: true
});
prompt.addEvent('resize', function() {popupBehavior.resize.bind(popupBehavior);});
prompt.addEvent('destroy', function() {popupBehavior.cleanup(target); });

if(Browser.Engine.trident) {
fillAndShow();
}
Expand Down

0 comments on commit 7501423

Please sign in to comment.