Builder.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2010
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. //----------------------------------------------------------
  13. com.cognos.admin.ObjectFactory("com.cognos.admin.widget");
  14. /**
  15. * J2HTML Builder class is to prepare the recipes for event class,
  16. * and traverse the DOM of the input element and attach event handlers
  17. * according to the recipes.
  18. *
  19. * @param elt: target container element will be attached with J2HTML events.
  20. * @param frg: fragment container
  21. *
  22. */
  23. com.cognos.admin.widget.Builder = function (elt,frg){
  24. if (!elt) throw new Error("You cannot create a J2HTML Table widget without input element");
  25. this.fragment = frg;
  26. this.table = elt;
  27. this.publicVariables = {}; //TODO
  28. this.recipe = new com.cognos.admin.util.Tools.Recipe();
  29. this.fragmentRecipe = new com.cognos.admin.util.Tools.Recipe();
  30. this._initDefaultFunc();
  31. this.event = new com.cognos.admin.widget.Event(this);
  32. };
  33. com.cognos.admin.widget.Builder.VERSION = "0.1.0";
  34. com.cognos.admin.widget.Builder.prototype = {
  35. /*
  36. *
  37. */
  38. _initDefaultFunc : function (){
  39. //init recipe for cogTable
  40. this.recipe.add("table_init","initTable","init");
  41. this.recipe.add("table_unload","unloadTable","unload");
  42. this.recipe.add("tooltip","showTooltip","mouseover");
  43. this.recipe.add("tooltip","showTooltip","focus");
  44. this.recipe.add("tooltip","hideTooltip","mouseout");
  45. this.recipe.add("tooltip","hideTooltip","blur");
  46. this.recipe.add("toggler","toggle","click");
  47. this.recipe.add("toggler","defaultCursor","init");
  48. this.recipe.add("checkbox_toggler","toggleCheckbox","click");
  49. this.recipe.add("all_toggler","toggleAll","click");
  50. this.recipe.add("all_toggler","defaultCursor","init");
  51. this.recipe.add("sort_column","sortColumn","keypress");
  52. this.recipe.add("sort_column","sortColumn","click");
  53. this.recipe.add("sort_column","mouseOverLink","init");
  54. this.recipe.add("mask","maskElement","init");
  55. this.recipe.add("sort_test","sortTest","click");
  56. this.recipe.add("filter_column","filterColumn","click");
  57. this.recipe.add("filter_column","initFilter","init");
  58. this.recipe.enableAction("action");
  59. //for client side silter summary widget only
  60. //r.add("filter_summary","filterSummary","init");
  61. //init recipe for fragment event
  62. this.fragmentRecipe.add("fragment","fgmtCreate","fragment.create");
  63. this.fragmentRecipe.add("fragment","fgmtDestroy","fragment.destroy");
  64. this.fragmentRecipe.add("fragment","fgmtError","fragment.error");
  65. this.fragmentRecipe.add("fragment","fgmtRefresh","fragment.refresh");
  66. this.fragmentRecipe.add("fragment","fgmtResize","fragment.resize");
  67. this.fragmentRecipe.add("fragment","fgmtLoad","fragment.load");
  68. this.fragmentRecipe.add("fragment","fgmtUnload","fragment.unload");
  69. this.fragmentRecipe.add("fragment","fgmtRetrieveBefore","fragment.retrieve.before");
  70. this.fragmentRecipe.add("fragment","fgmtRetrieveAfter","fragment.retrieve.after");
  71. this.fragmentRecipe.add("fragment","fgmtTitleChange","fragment.title.change");
  72. this.fragmentRecipe.add("fragment","fgmtWindowstateChange","fragment.windowstate.change");
  73. this.fragmentRecipe.add("fragment","fgmtModeChange","fragment.mode.change");
  74. this.fragmentRecipe.add("fragment","menuSelect","cognos.ui.menu.select");
  75. //init recipe for j2html customized event
  76. this.fragmentRecipe.add("fragment","cadminFragRefresh","com.cognos.cogadmin.load");
  77. this.fragmentRecipe.add("fragment","distCadminFragWschange","cogadmin.fragment.windowstate.change");
  78. this.fragmentRecipe.add("fragment","doAction","cogadmin.fragment.action.execute");
  79. },
  80. /* walk through the element and hook the behavior for the element accordingly
  81. *
  82. */
  83. populateTable : function(){
  84. //protect the event handler from dup loaded.
  85. if((!_F_getFragmentByID(this.fragment.id)) || com.cognos.admin.publicParam.evtLoaded[this.fragment.id]) return;
  86. com.cognos.admin.publicParam.evtLoaded[this.fragment.id] = true;
  87. var ce = this.event;
  88. function walk (elt) {
  89. if (elt){
  90. if (elt.nodeType == 1) {
  91. if (elt.getAttribute("cogType")) {
  92. ce.mountEvent(elt);
  93. }
  94. if (elt.childNodes){
  95. var children = elt.childNodes;
  96. for (var i = 0; i < children.length; i++){
  97. walk (children[i]);
  98. }
  99. }
  100. }
  101. }
  102. };
  103. //walk through
  104. walk (this.table);
  105. //load any extension handlers
  106. for (var obj in com.cognos.admin.extension) {
  107. this.event.extensionFuncs[obj] = new com.cognos.admin.extension[obj](this.event);
  108. }
  109. //unregister event handler when window/frament unload, fix IE leaking
  110. ce.unregisterEvent();
  111. },
  112. /*
  113. * add a customized function to the event class as an event handler
  114. */
  115. addFunction : function (cogType,func,evt,cap){
  116. var capturing = cap || false;
  117. var funcName = "function"+com.cognos.admin.util.Tools.uniqueID();
  118. this.add(cogType,funcName,evt,capturing);
  119. if (typeof func == "function")
  120. this.event.addCogEvent(funcName,func);
  121. },
  122. /*
  123. *
  124. */
  125. setPublicVariables : function (vName,vValue){
  126. if (vName in this.publicVariables)
  127. throw new Error("Variable "+vName+" has already existed.");
  128. this.publicVariables[vName] = vValue;
  129. },
  130. /*
  131. *
  132. */
  133. getPublicVariables : function (vName){
  134. if (this.publicVariables[vName] != undefined)
  135. return this.publicVariables[vName];
  136. else
  137. return;
  138. }
  139. };