Advertisement
Guest User

CheckedMultiSelect.js

a guest
Jan 26th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
  3.     Available via Academic Free License >= 2.1 OR the modified BSD license.
  4.     see: http://dojotoolkit.org/license for details
  5. */
  6.  
  7.  
  8. if(!dojo._hasResource["dojox.form.CheckedMultiSelect"]){
  9. dojo._hasResource["dojox.form.CheckedMultiSelect"]=true;
  10. dojo.provide("dojox.form.CheckedMultiSelect");
  11. dojo.require("dijit.form.CheckBox");
  12. dojo.require("dijit.form._FormSelectWidget");
  13. dojo.declare("dojox.form._CheckedMultiSelectItem",[dijit._Widget,dijit._Templated],{widgetsInTemplate:true,templateString:dojo.cache("dojox.form","resources/_CheckedMultiSelectItem.html","<div class=\"dijitReset ${baseClass}\"\n\t><input class=\"${baseClass}Box\" dojoType=\"dijit.form.CheckBox\" dojoAttachPoint=\"checkBox\" \n\t\tdojoAttachEvent=\"_onClick:_changeBox\" type=\"${_type.type}\" baseClass=\"${_type.baseClass}\"\n\t/><div class=\"dijitInline ${baseClass}Label\" dojoAttachPoint=\"labelNode\" dojoAttachEvent=\"onclick:_onClick\"></div\n></div>\n"),baseClass:"dojoxMultiSelectItem",option:null,parent:null,disabled:false,readOnly:false,postMixInProperties:function(){
  14. if(this.parent.multiple){
  15. this._type={type:"checkbox",baseClass:"dijitCheckBox"};
  16. }else{
  17. this._type={type:"radio",baseClass:"dijitRadio"};
  18. }
  19. this.disabled=this.option.disabled=this.option.disabled||false;
  20. this.inherited(arguments);
  21. },postCreate:function(){
  22. this.inherited(arguments);
  23. this.labelNode.innerHTML=this.option.label;
  24. },_changeBox:function(){
  25. if(this.get("disabled")||this.get("readOnly")){
  26. return;
  27. }
  28. if(this.parent.multiple){
  29. this.option.selected=this.checkBox.attr("value")&&true;
  30. }else{
  31. this.parent.attr("value",this.option.value);
  32. }
  33. this.parent._updateSelection();
  34. this.parent.focus();
  35. },_onClick:function(e){
  36. if(this.get("disabled")||this.get("readOnly")){
  37. dojo.stopEvent(e);
  38. }else{
  39. this.checkBox._onClick(e);
  40. }
  41. },_updateBox:function(){
  42. this.checkBox.attr("value",this.option.selected);
  43. },_setDisabledAttr:function(_1){
  44. this.disabled=_1||this.option.disabled;
  45. this.checkBox.attr("disabled",this.disabled);
  46. dojo.toggleClass(this.domNode,"dojoxMultiSelectDisabled",this.disabled);
  47. },_setReadOnlyAttr:function(_2){
  48. this.checkBox.attr("readOnly",_2);
  49. this.readOnly=_2;
  50. }});
  51. dojo.declare("dojox.form.CheckedMultiSelect",dijit.form._FormSelectWidget,{templateString:dojo.cache("dojox.form","resources/CheckedMultiSelect.html","<div class=\"dijit dijitReset dijitInline\" dojoAttachEvent=\"onmousedown:_onMouseDown,onclick:focus\"\n\t><input dojoAttachPoint=\"containerNode,focusNode,valueNode\" type=\"hidden\" ${!nameAttrSetting}\n/><div dojoAttachPoint=\"wrapperDiv\"></div\n></div>\n"),baseClass:"dojoxMultiSelect",_onMouseDown:function(e){
  52. dojo.stopEvent(e);
  53. },_addOptionItem:function(_3){
  54. this.wrapperDiv.appendChild(new dojox.form._CheckedMultiSelectItem({option:_3,parent:this}).domNode);
  55. },_updateSelection:function(){
  56. this.inherited(arguments);
  57. dojo.forEach(this._getChildren(),function(c){
  58. c._updateBox();
  59. });
  60. this.valueNode.value = this.value;
  61. },_getChildren:function(){
  62. return dojo.map(this.wrapperDiv.childNodes,function(n){
  63. return dijit.byNode(n);
  64. });
  65. },invertSelection:function(_4){
  66. dojo.forEach(this.options,function(i){
  67. i.selected=!i.selected;
  68. });
  69. this._updateSelection();
  70. },_setDisabledAttr:function(_5){
  71. this.inherited(arguments);
  72. dojo.forEach(this._getChildren(),function(_6){
  73. if(_6&&_6.attr){
  74. _6.attr("disabled",_5);
  75. }
  76. });
  77. },_setReadOnlyAttr:function(_7){
  78. if("readOnly" in this.attributeMap){
  79. this._attrToDom("readOnly",_7);
  80. }
  81. this.readOnly=_7;
  82. dojo.forEach(this._getChildren(),function(_8){
  83. if(_8&&_8.attr){
  84. _8.attr("readOnly",_7);
  85. }
  86. });
  87. },uninitialize:function(){
  88. dojo.forEach(this._getChildren(),function(_9){
  89. _9.destroyRecursive();
  90. });
  91. this.inherited(arguments);
  92. }});
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement