fork download
  1. var has_bubble_problem = (0 < Y.UA.ie && Y.UA.ie < 9);
  2. Y.QueryBuilder.Calendar = function(
  3. /* object */ query_builder,
  4. /* object */ config)
  5. {
  6. this.qb = query_builder;
  7.  
  8. this.op_menu_name_pattern = config.field_prefix + 'query_op_{i}';
  9. this.val_input_name_pattern = config.field_prefix + 'query_val_{i}_c{j}';
  10. };
  11.  
  12. Y.QueryBuilder.Calendar.prototype =
  13. {
  14. create: function(
  15. /* int */ query_index,
  16. /* object */ var_config,
  17. /* array */ op_list,
  18. /* array */ value)
  19. {
  20. var op_cell = this.qb._createContainer();
  21. op_cell.set('className', this.qb.getClassName('operator'));
  22. op_cell.set('innerHTML', this._operationsMenu(this.operationName(query_index)));
  23. this.op_menu = op_cell.one('select');
  24.  
  25. var options = Y.Node.getDOMNode(this.op_menu).options;
  26.  
  27. var isMultipleValue = op_list[0].multipleValue;
  28.  
  29. for (var i=0; i<op_list.length; i++)
  30. {
  31. options[i] = new Option(op_list[i].text, op_list[i].value);
  32. }
  33.  
  34. value = value || ['',''];
  35. if (value[0])
  36. {
  37. this.op_menu.set('value', value[0]);
  38. }
  39.  
  40. if (has_bubble_problem)
  41. {
  42. this.op_menu.on('change', this.qb._notifyChanged, this.qb);
  43. }
  44.  
  45. this.value_input = [];
  46. var value_cell_1 = this.qb._createContainer();
  47. value_cell_1.set('className', this.qb.getClassName('value'));
  48. value_cell_1.set('innerHTML', this._valueInput(this.valueName(query_index,0), var_config.validation));
  49. this.value_input[0] = value_cell_1.one('input');
  50. this.value_input[0].set('value', value[1]); // avoid formatting
  51. this._createDatePicker(0)
  52.  
  53.  
  54.  
  55. var value_cell_2 = this.qb._createContainer();
  56. value_cell_2.set('className', this.qb.getClassName('value'));
  57. value_cell_2.set('innerHTML', this._valueInput(this.valueName(query_index,1), var_config.validation));
  58. this.value_input[1] = value_cell_2.one('input');
  59. this.value_input[1].set('value', value[1]); // avoid formatting
  60. this._createDatePicker(1)
  61. if(!isMultipleValue){
  62. value_cell_2.setStyle("display","none");
  63. this.hasMultipleSelection=false;
  64. }
  65. var self = this;
  66.  
  67. this.op_menu.on('change', function()
  68. {
  69. var operationSelected=this.get("value");
  70. for(i=0;i<op_list.length;i++)
  71. {
  72. if(operationSelected===op_list[i].value)
  73. {
  74. if(op_list[i].multipleValue)
  75. {
  76. value_cell_2.setStyle("display","block");
  77. self.hasMultipleSelection=true;
  78. }
  79. else
  80. {
  81. value_cell_2.setStyle("display","none");
  82. self.hasMultipleSelection=false;
  83. }
  84. }
  85. }
  86. });
  87.  
  88. return [ op_cell, value_cell_1, value_cell_2 ];
  89. },
  90.  
  91. postCreate: function(
  92. /* int */ query_index,
  93. /* object */ var_config,
  94. /* array */ op_list,
  95. /* array */ value)
  96. {
  97. },
  98.  
  99. destroy: function()
  100. {
  101. this.op_menu = null;
  102. for(i=0;i<this.value_input;i++){
  103. this.value_input[i] = null;
  104. }
  105. },
  106.  
  107. updateName: function(
  108. /* int */ new_index)
  109. {
  110. this.op_menu.setAttribute('name', this.operationName(new_index));
  111. for(i=0;i<this.value_input;i++){
  112. this.value_input[i].setAttribute('name', this.valueName(new_index,i));
  113. }
  114.  
  115. },
  116.  
  117. set: function(
  118. /* int */ query_index,
  119. /* map */ data)
  120. {
  121. this.op_menu.set('value', data[ this.operationName(query_index) ]);
  122. for(i=0;i<this.value_input;i++){
  123. this.value_input[i].set('value', data[ this.valueName(query_index,1) ]);
  124. }
  125.  
  126. },
  127.  
  128. toDatabaseQuery: function()
  129. {
  130. var values=[this.value_input[0].get('value')];
  131. if(this.hasMultipleSelection){
  132. values.push(this.value_input[1].get('value'));
  133. }
  134. return [ [ this.op_menu.get('value'), values ] ];
  135. },
  136.  
  137. /* *********************************************************************
  138.   * Form element names.
  139.   */
  140.  
  141. operationName: function(
  142. /* int */ i)
  143. {
  144. return Y.Lang.sub(this.op_menu_name_pattern, {i:i});
  145. },
  146.  
  147. valueName: function(
  148. /* int */ i,
  149. /* int */ j)
  150. {
  151. return Y.Lang.sub(this.val_input_name_pattern, {i:i,j:j});
  152. },
  153.  
  154. //
  155. // Markup
  156. //
  157.  
  158. _operationsMenu: function(
  159. /* string */ menu_name)
  160. {
  161. // This must use a select tag!
  162.  
  163. var markup = '<select name="{n}" class="{f} {c}" />';
  164.  
  165. return Y.Lang.sub(markup,
  166. {
  167. n: menu_name,
  168. f: Y.FormManager.field_marker_class,
  169. c: this.qb.getClassName('field')
  170. });
  171. },
  172.  
  173. _valueInput: function(
  174. /* string */ input_name,
  175. /* string */ validation_class)
  176. {
  177. // This must use an input tag!
  178.  
  179. var markup = '<input type="text" name="{n}" class="yiv-required {f} {c}"/>';
  180.  
  181. return Y.Lang.sub(markup,
  182. {
  183. n: input_name,
  184. f: Y.FormManager.field_marker_class,
  185. c: validation_class + ' ' + this.qb.getClassName('field')
  186. });
  187. },
  188. _createDatePicker:function(
  189. /* int */index)
  190. {
  191. var WidgetPositionAlign = Y.WidgetPositionAlign;
  192. var dtdate = Y.DataType.Date;
  193. this.qb.datePicker = this.qb.datePicker || [];
  194. this.qb.dt_input = this.qb.dt_input || [];
  195.  
  196. /* We don't need multiple instance of calendar for each criterion row
  197.   * */
  198. if(!this.qb.datePicker[index])
  199. {
  200. var WIDTH = "150px";
  201. var HEIGHT = "150px"
  202. var overlay = new Y.Overlay({
  203. height:HEIGHT,
  204. width:WIDTH,
  205. visible:false
  206. });
  207. overlay.render("#workspace");
  208. overlay.get("boundingBox").addClass("yui3-skin-sam");
  209. overlay.plug(Y.Plugin.OverlayAutohide);
  210. var calendar = new Y.Calendar({
  211. height:HEIGHT,
  212. width:WIDTH,
  213. visible:true,
  214. showPrevMonth: true,
  215. showNextMonth: true
  216. }).render();
  217. overlay.set("bodyContent",calendar.get("boundingBox"));
  218. this.qb.datePicker[index]={overlay:overlay,calendar:calendar};
  219. }
  220. this.value_input[index].on("click",function(e){
  221. var overlay = this.qb.datePicker[index].overlay;
  222. overlay.show();
  223. overlay.set("align", {node:this.value_input[index], points:[WidgetPositionAlign.TC, WidgetPositionAlign.RC]});
  224. this.qb.dt_input[index] = this.value_input[index];
  225. },this);
  226.  
  227. this.qb.datePicker[index].calendar.on("selectionChange", function (ev) {
  228. var newDate = ev.newSelection[0];
  229. this.qb.dt_input[index].set("value",dtdate.format(newDate,{format:"%m/%d/%Y"}));
  230. this.qb.datePicker[index].overlay.hide();
  231. },this);
  232. }
  233. };
  234.  
  235. Y.QueryBuilder.plugin_mapping.calendar=Y.QueryBuilder.Calendar;
  236.  
Runtime error #stdin #stdout 0.34s 213888KB
stdin
Standard input is empty
stdout
Standard output is empty