Changeset 5401

Show
Ignore:
Timestamp:
08/27/06 12:36:34 (2 years ago)
Author:
liucougar
Message:

subwidgets support for widget
migrate editor2dialog to use subwidgets
(reviewed by Bill)

Location:
trunk/src/widget
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/widget/DomWidget.js

    r5384 r5401  
    143143                // FIXME: is this going to have capitalization problems?  Could use getAttribute(name, 0); to get attributes case-insensitve 
    144144                var attachPoint = []; 
    145                 for(var y=0; y<this.attachProperties.length; y++){ 
    146                         var tmpAttachPoint = baseNode.getAttribute(this.attachProperties[y]); 
    147                         if(tmpAttachPoint){ 
    148                                 attachPoint = tmpAttachPoint.split(";"); 
    149                                 for(var z=0; z<attachPoint.length; z++){ 
    150                                         if(dojo.lang.isArray(targetObj[attachPoint[z]])){ 
    151                                                 targetObj[attachPoint[z]].push(baseNode); 
    152                                         }else{ 
    153                                                 targetObj[attachPoint[z]]=baseNode; 
    154                                         } 
    155                                 } 
    156                                 break; 
     145                if(!targetObj.enableSubWidgets || !baseNode.getAttribute('dojoType')){ 
     146                        for(var y=0; y<this.attachProperties.length; y++){ 
     147                                var tmpAttachPoint = baseNode.getAttribute(this.attachProperties[y]); 
     148                                if(tmpAttachPoint){ 
     149                                        attachPoint = tmpAttachPoint.split(";"); 
     150                                        for(var z=0; z<attachPoint.length; z++){ 
     151                                                if(dojo.lang.isArray(targetObj[attachPoint[z]])){ 
     152                                                        targetObj[attachPoint[z]].push(baseNode); 
     153                                                }else{ 
     154                                                        targetObj[attachPoint[z]]=baseNode; 
     155                                                } 
     156                                        } 
     157                                        break; 
     158                                } 
     159                        } 
     160 
     161                        var attachEvent = baseNode.getAttribute(this.eventAttachProperty); 
     162                        if(attachEvent){ 
     163                                // NOTE: we want to support attributes that have the form 
     164                                // "domEvent: nativeEvent; ..." 
     165                                var evts = attachEvent.split(";"); 
     166                                for(var y=0; y<evts.length; y++){ 
     167                                        if((!evts[y])||(!evts[y].length)){ continue; } 
     168                                        var thisFunc = null; 
     169                                        var tevt = trim(evts[y]); 
     170                                        if(evts[y].indexOf(":") >= 0){ 
     171                                                // oh, if only JS had tuple assignment 
     172                                                var funcNameArr = tevt.split(":"); 
     173                                                tevt = trim(funcNameArr[0]); 
     174                                                thisFunc = trim(funcNameArr[1]); 
     175                                        } 
     176                                        if(!thisFunc){ 
     177                                                thisFunc = tevt; 
     178                                        } 
     179         
     180                                        var tf = function(){  
     181                                                var ntf = new String(thisFunc); 
     182                                                return function(evt){ 
     183                                                        if(_this[ntf]){ 
     184                                                                _this[ntf](dojo.event.browser.fixEvent(evt, this)); 
     185                                                        } 
     186                                                }; 
     187                                        }(); 
     188                                        dojo.event.browser.addListener(baseNode, tevt, tf, false, true); 
     189                                        // dojo.event.browser.addListener(baseNode, tevt, dojo.lang.hitch(_this, thisFunc)); 
     190                                } 
     191                        } 
     192         
     193                        for(var y=0; y<events.length; y++){ 
     194                                //alert(events[x]); 
     195                                var evtVal = baseNode.getAttribute(events[y]); 
     196                                if((evtVal)&&(evtVal.length)){ 
     197                                        var thisFunc = null; 
     198                                        var domEvt = events[y].substr(4); // clober the "dojo" prefix 
     199                                        thisFunc = trim(evtVal); 
     200                                        var funcs = [thisFunc]; 
     201                                        if(thisFunc.indexOf(";")>=0){ 
     202                                                funcs = dojo.lang.map(thisFunc.split(";"), trim); 
     203                                        } 
     204                                        for(var z=0; z<funcs.length; z++){ 
     205                                                if(!funcs[z].length){ continue; } 
     206                                                var tf = function(){  
     207                                                        var ntf = new String(funcs[z]); 
     208                                                        return function(evt){ 
     209                                                                if(_this[ntf]){ 
     210                                                                        _this[ntf](dojo.event.browser.fixEvent(evt, this)); 
     211                                                                } 
     212                                                        } 
     213                                                }(); 
     214                                                dojo.event.browser.addListener(baseNode, domEvt, tf, false, true); 
     215                                                // dojo.event.browser.addListener(baseNode, domEvt, dojo.lang.hitch(_this, funcs[z])); 
     216                                        } 
     217                                } 
    157218                        } 
    158219                } 
     
    179240                        } 
    180241                }, this); 
    181  
    182                 var attachEvent = baseNode.getAttribute(this.eventAttachProperty); 
    183                 if(attachEvent){ 
    184                         // NOTE: we want to support attributes that have the form 
    185                         // "domEvent: nativeEvent; ..." 
    186                         var evts = attachEvent.split(";"); 
    187                         for(var y=0; y<evts.length; y++){ 
    188                                 if((!evts[y])||(!evts[y].length)){ continue; } 
    189                                 var thisFunc = null; 
    190                                 var tevt = trim(evts[y]); 
    191                                 if(evts[y].indexOf(":") >= 0){ 
    192                                         // oh, if only JS had tuple assignment 
    193                                         var funcNameArr = tevt.split(":"); 
    194                                         tevt = trim(funcNameArr[0]); 
    195                                         thisFunc = trim(funcNameArr[1]); 
    196                                 } 
    197                                 if(!thisFunc){ 
    198                                         thisFunc = tevt; 
    199                                 } 
    200  
    201                                 var tf = function(){  
    202                                         var ntf = new String(thisFunc); 
    203                                         return function(evt){ 
    204                                                 if(_this[ntf]){ 
    205                                                         _this[ntf](dojo.event.browser.fixEvent(evt, this)); 
    206                                                 } 
    207                                         }; 
    208                                 }(); 
    209                                 dojo.event.browser.addListener(baseNode, tevt, tf, false, true); 
    210                                 // dojo.event.browser.addListener(baseNode, tevt, dojo.lang.hitch(_this, thisFunc)); 
    211                         } 
    212                 } 
    213  
    214                 for(var y=0; y<events.length; y++){ 
    215                         //alert(events[x]); 
    216                         var evtVal = baseNode.getAttribute(events[y]); 
    217                         if((evtVal)&&(evtVal.length)){ 
    218                                 var thisFunc = null; 
    219                                 var domEvt = events[y].substr(4); // clober the "dojo" prefix 
    220                                 thisFunc = trim(evtVal); 
    221                                 var funcs = [thisFunc]; 
    222                                 if(thisFunc.indexOf(";")>=0){ 
    223                                         funcs = dojo.lang.map(thisFunc.split(";"), trim); 
    224                                 } 
    225                                 for(var z=0; z<funcs.length; z++){ 
    226                                         if(!funcs[z].length){ continue; } 
    227                                         var tf = function(){  
    228                                                 var ntf = new String(funcs[z]); 
    229                                                 return function(evt){ 
    230                                                         if(_this[ntf]){ 
    231                                                                 _this[ntf](dojo.event.browser.fixEvent(evt, this)); 
    232                                                         } 
    233                                                 } 
    234                                         }(); 
    235                                         dojo.event.browser.addListener(baseNode, domEvt, tf, false, true); 
    236                                         // dojo.event.browser.addListener(baseNode, domEvt, dojo.lang.hitch(_this, funcs[z])); 
    237                                 } 
    238                         } 
    239                 } 
    240242 
    241243                var onBuild = baseNode.getAttribute(this.onBuildProperty); 
     
    287289        domNode: null, // this is our visible representation of the widget! 
    288290        containerNode: null, // holds child elements 
     291 
     292        enableSubWidgets: false, //by default, widgets defined in templates are ignored 
    289293 
    290294        // Process the given child widget, inserting it's dom node as a child of our dom node 
     
    488492                                                                                        // from properties, remote data 
    489493                                                                                        // sets, etc. 
     494 
     495                if(this.enableSubWidgets){ 
     496                        var parser = new dojo.xml.Parse(); 
     497         
     498                        var frag = parser.parseElement(this.domNode, null, true); 
     499                        // createSubComponents not createComponents because frag has already been created 
     500                        dojo.widget.getParser().createSubComponents(frag, this); 
     501         
     502                        //connect event to this widget/attach dom node 
     503                        for(var i = 0; i < this.children.length; i++){ 
     504                                var widget = this.children[i]; 
     505                                if(widget.extraArgs['dojoattachevent']){ 
     506                                        var evts = widget.extraArgs['dojoattachevent'].split(";"); 
     507                                        for(var j=0; j<evts.length; j++){ 
     508                                                var thisFunc = null; 
     509                                                var tevt = dojo.string.trim(evts[j]); 
     510                                                if(tevt.indexOf(":") >= 0){ 
     511                                                        // oh, if only JS had tuple assignment 
     512                                                        var funcNameArr = tevt.split(":"); 
     513                                                        tevt = dojo.string.trim(funcNameArr[0]); 
     514                                                        thisFunc = dojo.string.trim(funcNameArr[1]); 
     515                                                } 
     516                                                if(!thisFunc){ 
     517                                                        thisFunc = tevt; 
     518                                                } 
     519                                                if(dojo.lang.isFunction(widget[tevt])){ 
     520                                                        dojo.event.connect(widget, tevt, this, thisFunc); 
     521                                                }else{ 
     522                                                        alert(tevt+" is not a function in widget "+widget); 
     523                                                } 
     524                                        } 
     525                                } 
     526                                if(widget.extraArgs['dojoattachpoint']){ 
     527                                        //don't attach widget.domNode here, as we do not know which 
     528                                        //dom node we should connect to (in checkbox widget case,  
     529                                        //it is inputNode). So we make the widget itself available 
     530                                        this[widget.extraArgs['dojoattachpoint']] = widget; 
     531                                } 
     532                        } 
     533                } 
    490534        }, 
    491535 
  • trunk/src/widget/Editor2.js

    r5381 r5401  
    210210                                dojo.require(this.contentFile); 
    211211                        } 
    212                         if(this.contentClass){ 
    213                                 this.contentWidget = dojo.widget.createWidget(this.contentClass, {parent: this}); 
    214                                 this.containerNode.appendChild(this.contentWidget.domNode); 
    215                                 dojo.event.connect(this, "destroy", this.contentWidget, "destroy"); 
    216                         } 
    217212                        if(this.modal){ 
    218213                                dojo.widget.ModalDialogBase.prototype.postCreate.call(this); 
     
    232227                        } 
    233228                }, 
     229                createContent: function(){ 
     230                        if(!this.contentWidget && this.contentClass){ 
     231                                this.contentWidget = dojo.widget.createWidget(this.contentClass, {parent: this}); 
     232                                this.containerNode.appendChild(this.contentWidget.domNode); 
     233                                dojo.event.connect(this, "destroy", this.contentWidget, "destroy"); 
     234                        } 
     235                }, 
    234236                show: function(){ 
     237                        if(!this.contentWidget){ 
     238                                //buggy IE: if the dialog is hidden, the button widgets 
     239                                //in the dialog can not be shown, so show it temporary (as the 
     240                                //dialog may decide not to show it in loadContent() later) 
     241                                dojo.widget.Editor2Dialog.superclass.show.apply(this, arguments); 
     242                                this.createContent(); 
     243                                dojo.widget.Editor2Dialog.superclass.hide.call(this); 
     244                        } 
     245 
     246                        if(!this.contentWidget || !this.contentWidget.loadContent()){ 
     247                                return; 
     248                        } 
    235249                        this.showFloatingPane(); 
    236250                        dojo.widget.Editor2Dialog.superclass.show.apply(this, arguments); 
     
    265279        dojo.widget.HtmlWidget, 
    266280{ 
    267         buildRendering: function(args, frag){ 
    268                 dojo.widget.Editor2DialogContent.superclass.buildRendering.apply(this, arguments); 
    269                 var parser = new dojo.xml.Parse(); 
    270  
    271                 var frag = parser.parseElement(this.domNode, null, true); 
    272                 // createSubComponents not createComponents because frag has already been created 
    273                 dojo.widget.getParser().createSubComponents(frag, this); 
    274  
    275                 //connect event to this widget/attach dom node 
    276                 for(var i = 0; i < this.children.length; i++){ 
    277                         var widget = this.children[i]; 
    278                         if(widget.extraArgs['dojoattachchildevent']){ 
    279                                 var evts = widget.extraArgs['dojoattachchildevent'].split(";"); 
    280                                 for(var j=0; j<evts.length; j++){ 
    281                                         var thisFunc = null; 
    282                                         var tevt = dojo.string.trim(evts[j]); 
    283                                         if(tevt.indexOf(":") >= 0){ 
    284                                                 // oh, if only JS had tuple assignment 
    285                                                 var funcNameArr = tevt.split(":"); 
    286                                                 tevt = dojo.string.trim(funcNameArr[0]); 
    287                                                 thisFunc = dojo.string.trim(funcNameArr[1]); 
    288                                         } 
    289                                         if(!thisFunc){ 
    290                                                 thisFunc = tevt; 
    291                                         } 
    292                                         if(dojo.lang.isFunction(widget[tevt])){ 
    293                                                 dojo.event.connect(widget, tevt, this, thisFunc); 
    294                                         }else{ 
    295                                                 alert(tevt+" is not a function in widget "+widget); 
    296                                         } 
    297                                 } 
    298                         } 
    299                         if(widget.extraArgs['dojoattachchildpoint']){ 
    300                                 //don't attach widget.domNode here, as we do not know which 
    301                                 //dom node we should connect to (in checkbox widget case,  
    302                                 //it is inputNode). So we make the widget itself available 
    303                                 this[widget.extraArgs['dojoattachchildpoint']] = widget; 
    304                         } 
    305                 } 
    306         }, 
    307         postCreate: function(){ 
    308                 dojo.event.connect("around", this.parent, "show", this, "initConent"); 
    309                 dojo.widget.Editor2DialogContent.superclass.postCreate.apply(this, arguments); 
    310         }, 
    311         initConent: function(mi){ 
    312                 if(this.loadContent()){ 
    313                         mi.proceed(); 
    314                 } 
    315         }, 
     281        enableSubWidgets: true, 
     282 
    316283        loadContent:function(){ 
    317284                return true; 
     
    375342 
    376343                editorOnLoad: function(){ 
    377                         dojo.profile.start("dojo.widget.Editor2::editorOnLoad"); 
     344//                      dojo.profile.start("dojo.widget.Editor2::editorOnLoad"); 
    378345 
    379346                        dojo.event.topic.publish("dojo.widget.Editor2::preLoadingToolbar", this); 
     
    409376 
    410377                        dojo.event.topic.publish("dojo.widget.Editor2::onLoad", this); 
    411                         dojo.profile.end("dojo.widget.Editor2::editorOnLoad"); 
     378//                      dojo.profile.end("dojo.widget.Editor2::editorOnLoad"); 
    412379                }, 
    413380 
     
    578545                        } 
    579546                        this._htmlEditNode = null; 
    580                         this.document = null; 
    581                         this.window = null; 
    582                         this.object = null; 
    583547                        dojo.widget.Editor2.superclass.destroy.call(this); 
    584548                }, 
  • trunk/src/widget/templates/Editor2/Dialog/createlink.html

    r5381 r5401  
    99<tr><td colspan="2"> 
    1010        <table><tr> 
    11         <td><button dojoType='Button' dojoAttachChildEvent='onClick:ok'>OK</button></td> 
    12         <td><button dojoType='Button' dojoAttachChildEvent='onClick:cancel'>Cancel</button></td> 
     11        <td><button dojoType='Button' dojoAttachEvent='onClick:ok'>OK</button></td> 
     12        <td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Cancel</button></td> 
    1313        </tr></table> 
    1414        </td></tr> 
  • trunk/src/widget/templates/Editor2/Dialog/find.html

    r5381 r5401  
    11<table style="white-space: nowrap;"> 
    22<tr><td colspan='2'>Find: <input type="text" dojoAttachPoint="find_text" /></td></tr> 
    3 <tr><td><input type="checkbox" dojoType="CheckBox" dojoAttachChildPoint="find_option_casesens" /> 
     3<tr><td><input type="checkbox" dojoType="CheckBox" dojoAttachPoint="find_option_casesens" /> 
    44                <label for="find_option_casesens">Case Sensitive</label></td> 
    5                         <td><input type="checkbox" dojoType="CheckBox" dojoAttachChildPoint="find_option_backwards" /> 
     5                        <td><input type="checkbox" dojoType="CheckBox" dojoAttachPoint="find_option_backwards" /> 
    66                <label for="find_option_backwards">Search Backwards</label></td></tr> 
    7 <tr><td style="display: none;"><input type="checkbox" dojoType="CheckBox" dojoAttachChildPoint="find_option_wholeword" /> 
     7<tr><td style="display: none;"><input type="checkbox" dojoType="CheckBox" dojoAttachPoint="find_option_wholeword" /> 
    88                <label for="find_option_wholeword">Whole Word</label></td> 
    99<tr><td colspan="1"> 
    1010        <table><tr> 
    11         <td><button dojoType='Button' dojoAttachChildEvent='onClick:find'>Find</button></td> 
    12         <td><button dojoType='Button' dojoAttachChildEvent='onClick:cancel'>Close</button></td> 
     11        <td><button dojoType='Button' dojoAttachEvent='onClick:find'>Find</button></td> 
     12        <td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Close</button></td> 
    1313        </tr></table> 
    1414        </td></tr> 
  • trunk/src/widget/templates/Editor2/Dialog/insertimage.html

    r5381 r5401  
    108108        <tr><td> 
    109109                <table><tr> 
    110                 <td><button dojoType='Button' dojoAttachChildEvent='onClick:ok'>OK</button></td> 
    111                 <td><button dojoType='Button' dojoAttachChildEvent='onClick:cancel'>Cancel</button></td> 
     110                <td><button dojoType='Button' dojoAttachEvent='onClick:ok'>OK</button></td> 
     111                <td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Cancel</button></td> 
    112112                </tr></table> 
    113113        </td></tr> 
  • trunk/src/widget/templates/Editor2/Dialog/inserttable.html

    r5381 r5401  
    8686</table> 
    8787<table><tr> 
    88 <td><button dojoType='Button' dojoAttachChildEvent='onClick:ok'>Ok</button></td> 
    89 <td><button dojoType='Button' dojoAttachChildEvent='onClick:cancel'>Cancel</button></td> 
     88<td><button dojoType='Button' dojoAttachEvent='onClick:ok'>Ok</button></td> 
     89<td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Cancel</button></td> 
    9090</tr></table> 
    9191</div> 
  • trunk/src/widget/templates/Editor2/Dialog/replace.html

    r5381 r5401  
    22<tr><td>Find: </td><td> <input type="text" dojoAttachPoint="replace_text" /></td></tr> 
    33<tr><td>Replace with: </td><td> <input type="text" dojoAttachPoint="replace_text" /></td></tr> 
    4 <tr><td colspan='2'><table><tr><td><input type="checkbox" dojoType="CheckBox" dojoAttachChildPoint="replace_option_casesens" id="dojo_replace_option_casesens" /> 
     4<tr><td colspan='2'><table><tr><td><input type="checkbox" dojoType="CheckBox" dojoAttachPoint="replace_option_casesens" id="dojo_replace_option_casesens" /> 
    55                <label for="dojo_replace_option_casesens">Case Sensitive</label></td> 
    6                         <td><input type="checkbox" dojoType="CheckBox" dojoAttachChildPoint="replace_option_backwards" id="dojo_replace_option_backwards" /> 
     6                        <td><input type="checkbox" dojoType="CheckBox" dojoAttachPoint="replace_option_backwards" id="dojo_replace_option_backwards" /> 
    77                <label for="dojo_replace_option_backwards">Search Backwards</label></td></tr></table></td></tr> 
    88<tr><td colspan=2"> 
    99        <table><tr> 
    10         <td><button dojoType='Button' dojoAttachChildEvent='onClick:replace'>Replace</button></td> 
    11         <td><button dojoType='Button' dojoAttachChildEvent='onClick:replaceAll'>Replace All</button></td> 
    12         <td><button dojoType='Button' dojoAttachChildEvent='onClick:cancel'>Close</button></td> 
     10        <td><button dojoType='Button' dojoAttachEvent='onClick:replace'>Replace</button></td> 
     11        <td><button dojoType='Button' dojoAttachEvent='onClick:replaceAll'>Replace All</button></td> 
     12        <td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Close</button></td> 
    1313        </tr></table> 
    1414        </td></tr>