/public/scripts/jqgrid/src/jquery.searchFilter.js

http://zfdatagrid.googlecode.com/ · JavaScript · 605 lines · 285 code · 54 blank · 266 comment · 73 complexity · 2fed5e98576917fa95fe18bb709a288c MD5 · raw file

  1. /* Plugin: searchFilter v1.2.9
  2. * Author: Kasey Speakman (kasey@cornerspeed.com)
  3. * License: Dual Licensed, MIT and GPL v2 (http://www.gnu.org/copyleft/gpl.html)
  4. *
  5. * REQUIREMENTS:
  6. * jQuery 1.3+ (http://jquery.com/)
  7. * A Themeroller Theme (http://jqueryui.com/themeroller/)
  8. *
  9. * SECURITY WARNING
  10. * You should always implement server-side checking to ensure that
  11. * the query will fail when forged/invalid data is received.
  12. * Clever users can send any value they want through JavaScript and HTTP POST/GET.
  13. *
  14. * THEMES
  15. * Simply include the CSS file for your Themeroller theme.
  16. *
  17. * DESCRIPTION
  18. * This plugin creates a new searchFilter object in the specified container
  19. *
  20. * INPUT TYPE
  21. * fields: an array of field objects. each object has the following properties:
  22. * text: a string containing the display name of the field (e.g. "Field 1")
  23. * itemval: a string containing the actual field name (e.g. "field1")
  24. * optional properties:
  25. * ops: an array of operators in the same format as jQuery.fn.searchFilter.defaults.operators
  26. * that is: [ { op: 'gt', text: 'greater than'}, { op:'lt', text: 'less than'}, ... ]
  27. * if not specified, the passed-in options used, and failting that, jQuery.fn.searchFilter.defaults.operators will be used
  28. * *** NOTE ***
  29. * Specifying a dataUrl or dataValues property means that a <select ...> (drop-down-list) will be generated
  30. * instead of a text input <input type='text'.../> where the user would normally type in their search data
  31. * ************
  32. * dataUrl: a url that will return the html select for this field, this url will only be called once for this field
  33. * dataValues: the possible values for this field in the form [ { text: 'Data Display Text', value: 'data_actual_value' }, { ... } ]
  34. * dataInit: a function that you can use to initialize the data field. this function is passed the jQuery-fied data element
  35. * dataEvents: list of events to apply to the data element. uses $("#id").bind(type, [data], fn) to bind events to data element
  36. * *** JSON of this object could look like this: ***
  37. * var fields = [
  38. * {
  39. * text: 'Field Display Name',
  40. * itemval: 'field_actual_name',
  41. * // below this are optional values
  42. * ops: [ // this format is the same as jQuery.fn.searchFilter.defaults.operators
  43. * { op: 'gt', text: 'greater than' },
  44. * { op: 'lt', text: 'less than' }
  45. * ],
  46. * dataUrl: 'http://server/path/script.php?propName=propValue', // using this creates a select for the data input instead of an input type='text'
  47. * dataValues: [ // using this creates a select for the data input instead of an input type='text'
  48. * { text: 'Data Value Display Name', value: 'data_actual_value' },
  49. * { ... }
  50. * ],
  51. * dataInit: function(jElem) { jElem.datepicker(options); },
  52. * dataEvents: [ // these are the same options that you pass to $("#id").bind(type, [data], fn)
  53. * { type: 'click', data: { i: 7 }, fn: function(e) { console.log(e.data.i); } },
  54. * { type: 'keypress', fn: function(e) { console.log('keypress'); } }
  55. * ]
  56. * },
  57. * { ... }
  58. * ]
  59. * options: name:value properties containing various creation options
  60. * see jQuery.fn.searchFilter.defaults for the overridable options
  61. *
  62. * RETURN TYPE: This plugin returns a SearchFilter object, which has additional SearchFilter methods:
  63. * Methods
  64. * add: Adds a filter. added to the end of the list unless a jQuery event object or valid row number is passed.
  65. * del: Removes a filter. removed from the end of the list unless a jQuery event object or valid row number is passed.
  66. * reset: resets filters back to original state (only one blank filter), and calls onReset
  67. * search: puts the search rules into an object and calls onSearch with it
  68. * close: calls the onClose event handler
  69. *
  70. * USAGE
  71. * HTML
  72. * <head>
  73. * ...
  74. * <script src="path/to/jquery.min.js" type="text/javascript"></script>
  75. * <link href="path/to/themeroller.css" rel="Stylesheet" type="text/css" />
  76. * <script src="path/to/jquery.searchFilter.js" type="text/javascript"></script>
  77. * <link href="path/to/jquery.searchFilter.css" rel="Stylesheet" type="text/css" />
  78. * ...
  79. * </head>
  80. * <body>
  81. * ...
  82. * <div id='mySearch'></div>
  83. * ...
  84. * </body>
  85. * JQUERY
  86. * Methods
  87. * initializing: $("#mySearch").searchFilter([{text: "Field 1", value: "field1"},{text: "Field 2", value: "field2"}], {onSearch: myFilterRuleReceiverFn, onReset: myFilterResetFn });
  88. * Manual Methods (there's no need to call these methods unless you are trying to manipulate searchFilter with script)
  89. * add: $("#mySearch").searchFilter().add(); // appends a blank filter
  90. * $("#mySearch").searchFilter().add(0); // copies the first filter as second
  91. * del: $("#mySearch").searchFilter().del(); // removes the bottom filter
  92. * $("#mySearch").searchFilter().del(1); // removes the second filter
  93. * search: $("#mySearch").searchFilter().search(); // invokes onSearch, passing it a ruleGroup object
  94. * reset: $("#mySearch").searchFilter().reset(); // resets rules and invokes onReset
  95. * close: $("#mySearch").searchFilter().close(); // without an onClose handler, equivalent to $("#mySearch").hide();
  96. *
  97. * NOTE: You can get the jQuery object back from the SearchFilter object by chaining .$
  98. * Example
  99. * $("#mySearch").searchFilter().add().add().reset().$.hide();
  100. * Verbose Example
  101. * $("#mySearch") // gets jQuery object for the HTML element with id="mySearch"
  102. * .searchFilter() // gets the SearchFilter object for an existing search filter
  103. * .add() // adds a new filter to the end of the list
  104. * .add() // adds another new filter to the end of the list
  105. * .reset() // resets filters back to original state, triggers onReset
  106. * .$ // returns jQuery object for $("#mySearch")
  107. * .hide(); // equivalent to $("#mySearch").hide();
  108. */
  109. jQuery.fn.searchFilter = function(fields, options) {
  110. function SearchFilter(jQ, fields, options) {
  111. //---------------------------------------------------------------
  112. // PUBLIC VARS
  113. //---------------------------------------------------------------
  114. this.$ = jQ; // makes the jQuery object available as .$ from the return value
  115. //---------------------------------------------------------------
  116. // PUBLIC FUNCTIONS
  117. //---------------------------------------------------------------
  118. this.add = function(i) {
  119. if (i == null) jQ.find(".ui-add-last").click();
  120. else jQ.find(".sf:eq(" + i + ") .ui-add").click();
  121. return this;
  122. };
  123. this.del = function(i) {
  124. if (i == null) jQ.find(".sf:last .ui-del").click();
  125. else jQ.find(".sf:eq(" + i + ") .ui-del").click();
  126. return this;
  127. };
  128. this.search = function(e) {
  129. jQ.find(".ui-search").click();
  130. return this;
  131. };
  132. this.reset = function(e) {
  133. jQ.find(".ui-reset").click();
  134. return this;
  135. };
  136. this.close = function() {
  137. jQ.find(".ui-closer").click();
  138. return this;
  139. };
  140. //---------------------------------------------------------------
  141. // "CONSTRUCTOR" (in air quotes)
  142. //---------------------------------------------------------------
  143. if (fields != null) { // type coercion matches undefined as well as null
  144. //---------------------------------------------------------------
  145. // UTILITY FUNCTIONS
  146. //---------------------------------------------------------------
  147. function hover() {
  148. jQuery(this).toggleClass("ui-state-hover");
  149. return false;
  150. }
  151. function active(e) {
  152. jQuery(this).toggleClass("ui-state-active", (e.type == "mousedown"));
  153. return false;
  154. }
  155. function buildOpt(value, text) {
  156. return "<option value='" + value + "'>" + text + "</option>";
  157. }
  158. function buildSel(className, options, isHidden) {
  159. return "<select class='" + className + "'" + (isHidden ? " style='display:none;'" : "") + ">" + options + "</select>";
  160. }
  161. function initData(selector, fn) {
  162. var jElem = jQ.find("tr.sf td.data " + selector);
  163. if (jElem[0] != null)
  164. fn(jElem);
  165. }
  166. function bindDataEvents(selector, events) {
  167. var jElem = jQ.find("tr.sf td.data " + selector);
  168. if (jElem[0] != null) {
  169. jQuery.each(events, function() {
  170. if (this.data != null)
  171. jElem.bind(this.type, this.data, this.fn);
  172. else
  173. jElem.bind(this.type, this.fn);
  174. });
  175. }
  176. }
  177. //---------------------------------------------------------------
  178. // SUPER IMPORTANT PRIVATE VARS
  179. //---------------------------------------------------------------
  180. // copies jQuery.fn.searchFilter.defaults.options properties onto an empty object, then options onto that
  181. var opts = jQuery.extend({}, jQuery.fn.searchFilter.defaults, options);
  182. // this is keeps track of the last asynchronous setup
  183. var highest_late_setup = -1;
  184. //---------------------------------------------------------------
  185. // CREATION PROCESS STARTS
  186. //---------------------------------------------------------------
  187. // generate the global ops
  188. var gOps_html = "";
  189. jQuery.each(opts.groupOps, function() { gOps_html += buildOpt(this.op, this.text); });
  190. gOps_html = "<select name='groupOp'>" + gOps_html + "</select>";
  191. /* original content - doesn't minify very well
  192. jQ
  193. .html("") // clear any old content
  194. .addClass("ui-searchFilter") // add classes
  195. .append( // add content
  196. "\
  197. <div class='ui-widget-overlay' style='z-index: -1'>&nbsp;</div>\
  198. <table class='ui-widget-content ui-corner-all'>\
  199. <thead>\
  200. <tr>\
  201. <td colspan='5' class='ui-widget-header ui-corner-all' style='line-height: 18px;'>\
  202. <div class='ui-closer ui-state-default ui-corner-all ui-helper-clearfix' style='float: right;'>\
  203. <span class='ui-icon ui-icon-close'></span>\
  204. </div>\
  205. " + opts.windowTitle + "\
  206. </td>\
  207. </tr>\
  208. </thead>\
  209. <tbody>\
  210. <tr class='sf'>\
  211. <td class='fields'></td>\
  212. <td class='ops'></td>\
  213. <td class='data'></td>\
  214. <td><div class='ui-del ui-state-default ui-corner-all'><span class='ui-icon ui-icon-minus'></span></div></td>\
  215. <td><div class='ui-add ui-state-default ui-corner-all'><span class='ui-icon ui-icon-plus'></span></div></td>\
  216. </tr>\
  217. <tr>\
  218. <td colspan='5' class='divider'><div>&nbsp;</div></td>\
  219. </tr>\
  220. </tbody>\
  221. <tfoot>\
  222. <tr>\
  223. <td colspan='3'>\
  224. <span class='ui-reset ui-state-default ui-corner-all' style='display: inline-block; float: left;'><span class='ui-icon ui-icon-arrowreturnthick-1-w' style='float: left;'></span><span style='line-height: 18px; padding: 0 7px 0 3px;'>" + opts.resetText + "</span></span>\
  225. <span class='ui-search ui-state-default ui-corner-all' style='display: inline-block; float: right;'><span class='ui-icon ui-icon-search' style='float: left;'></span><span style='line-height: 18px; padding: 0 7px 0 3px;'>" + opts.searchText + "</span></span>\
  226. <span class='matchText'>" + opts.matchText + "</span> \
  227. " + gOps_html + " \
  228. <span class='rulesText'>" + opts.rulesText + "</span>\
  229. </td>\
  230. <td>&nbsp;</td>\
  231. <td><div class='ui-add-last ui-state-default ui-corner-all'><span class='ui-icon ui-icon-plusthick'></span></div></td>\
  232. </tr>\
  233. </tfoot>\
  234. </table>\
  235. ");
  236. /* end hard-to-minify code */
  237. /* begin easier to minify code */
  238. jQ.html("").addClass("ui-searchFilter").append("<div class='ui-widget-overlay' style='z-index: -1'>&#160;</div><table class='ui-widget-content ui-corner-all'><thead><tr><td colspan='5' class='ui-widget-header ui-corner-all' style='line-height: 18px;'><div class='ui-closer ui-state-default ui-corner-all ui-helper-clearfix' style='float: right;'><span class='ui-icon ui-icon-close'></span></div>" + opts.windowTitle + "</td></tr></thead><tbody><tr class='sf'><td class='fields'></td><td class='ops'></td><td class='data'></td><td><div class='ui-del ui-state-default ui-corner-all'><span class='ui-icon ui-icon-minus'></span></div></td><td><div class='ui-add ui-state-default ui-corner-all'><span class='ui-icon ui-icon-plus'></span></div></td></tr><tr><td colspan='5' class='divider'><div>&#160;</div></td></tr></tbody><tfoot><tr><td colspan='3'><span class='ui-reset ui-state-default ui-corner-all' style='display: inline-block; float: left;'><span class='ui-icon ui-icon-arrowreturnthick-1-w' style='float: left;'></span><span style='line-height: 18px; padding: 0 7px 0 3px;'>" + opts.resetText + "</span></span><span class='ui-search ui-state-default ui-corner-all' style='display: inline-block; float: right;'><span class='ui-icon ui-icon-search' style='float: left;'></span><span style='line-height: 18px; padding: 0 7px 0 3px;'>" + opts.searchText + "</span></span><span class='matchText'>" + opts.matchText + "</span> " + gOps_html + " <span class='rulesText'>" + opts.rulesText + "</span></td><td>&#160;</td><td><div class='ui-add-last ui-state-default ui-corner-all'><span class='ui-icon ui-icon-plusthick'></span></div></td></tr></tfoot></table>");
  239. /* end easier-to-minify code */
  240. var jRow = jQ.find("tr.sf");
  241. var jFields = jRow.find("td.fields");
  242. var jOps = jRow.find("td.ops");
  243. var jData = jRow.find("td.data");
  244. // generate the defaults
  245. var default_ops_html = "";
  246. jQuery.each(opts.operators, function() { default_ops_html += buildOpt(this.op, this.text); });
  247. default_ops_html = buildSel("default", default_ops_html, true);
  248. jOps.append(default_ops_html);
  249. var default_data_html = "<input type='text' class='default' style='display:none;' />";
  250. jData.append(default_data_html);
  251. // generate the field list as a string
  252. var fields_html = "";
  253. var has_custom_ops = false;
  254. var has_custom_data = false;
  255. jQuery.each(fields, function(i) {
  256. var field_num = i;
  257. fields_html += buildOpt(this.itemval, this.text);
  258. // add custom ops if they exist
  259. if (this.ops != null) {
  260. has_custom_ops = true;
  261. var custom_ops = "";
  262. jQuery.each(this.ops, function() { custom_ops += buildOpt(this.op, this.text); });
  263. custom_ops = buildSel("field" + field_num, custom_ops, true);
  264. jOps.append(custom_ops);
  265. }
  266. // add custom data if it is given
  267. if (this.dataUrl != null) {
  268. if (i > highest_late_setup) highest_late_setup = i;
  269. has_custom_data = true;
  270. var dEvents = this.dataEvents;
  271. var iEvent = this.dataInit;
  272. var bs = this.buildSelect;
  273. jQuery.ajax(jQuery.extend({
  274. url : this.dataUrl,
  275. complete: function(data) {
  276. var $d;
  277. if(bs != null) $d =jQuery("<div />").append(bs(data));
  278. else $d = jQuery("<div />").append(data.responseText);
  279. $d.find("select").addClass("field" + field_num).hide();
  280. jData.append($d.html());
  281. if (iEvent) initData(".field" + i, iEvent);
  282. if (dEvents) bindDataEvents(".field" + i, dEvents);
  283. if (i == highest_late_setup) { // change should get called no more than twice when this searchFilter is constructed
  284. jQ.find("tr.sf td.fields select[name='field']").change();
  285. }
  286. }
  287. },opts.ajaxSelectOptions));
  288. } else if (this.dataValues != null) {
  289. has_custom_data = true;
  290. var custom_data = "";
  291. jQuery.each(this.dataValues, function() { custom_data += buildOpt(this.value, this.text); });
  292. custom_data = buildSel("field" + field_num, custom_data, true);
  293. jData.append(custom_data);
  294. } else if (this.dataEvents != null || this.dataInit != null) {
  295. has_custom_data = true;
  296. var custom_data = "<input type='text' class='field" + field_num + "' />";
  297. jData.append(custom_data);
  298. }
  299. // attach events to data if they exist
  300. if (this.dataInit != null && i != highest_late_setup)
  301. initData(".field" + i, this.dataInit);
  302. if (this.dataEvents != null && i != highest_late_setup)
  303. bindDataEvents(".field" + i, this.dataEvents);
  304. });
  305. fields_html = "<select name='field'>" + fields_html + "</select>";
  306. jFields.append(fields_html);
  307. // setup the field select with an on-change event if there are custom ops or data
  308. var jFSelect = jFields.find("select[name='field']");
  309. if (has_custom_ops) jFSelect.change(function(e) {
  310. var index = e.target.selectedIndex;
  311. var td = jQuery(e.target).parents("tr.sf").find("td.ops");
  312. td.find("select").removeAttr("name").hide(); // disown and hide all elements
  313. var jElem = td.find(".field" + index);
  314. if (jElem[0] == null) jElem = td.find(".default"); // if there's not an element for that field, use the default one
  315. jElem.attr("name", "op").show();
  316. });
  317. else jOps.find(".default").attr("name", "op").show();
  318. if (has_custom_data) jFSelect.change(function(e) {
  319. var index = e.target.selectedIndex;
  320. var td = jQuery(e.target).parents("tr.sf").find("td.data");
  321. td.find("select,input").removeClass("vdata").hide(); // disown and hide all elements
  322. var jElem = td.find(".field" + index);
  323. if (jElem[0] == null) jElem = td.find(".default"); // if there's not an element for that field, use the default one
  324. jElem.show().addClass("vdata");
  325. });
  326. else jData.find(".default").show().addClass("vdata");
  327. // go ahead and call the change event and setup the ops and data values
  328. if (has_custom_ops || has_custom_data) jFSelect.change();
  329. // bind events
  330. jQ.find(".ui-state-default").hover(hover, hover).mousedown(active).mouseup(active); // add hover/active effects to all buttons
  331. jQ.find(".ui-closer").click(function(e) {
  332. opts.onClose(jQuery(jQ.selector));
  333. return false;
  334. });
  335. jQ.find(".ui-del").click(function(e) {
  336. var row = jQuery(e.target).parents(".sf");
  337. if (row.siblings(".sf").length > 0) { // doesn't remove if there's only one filter left
  338. if (opts.datepickerFix === true && jQuery.fn.datepicker !== undefined)
  339. row.find(".hasDatepicker").datepicker("destroy"); // clean up datepicker's $.data mess
  340. row.remove(); // also unbinds
  341. } else { // resets the filter if it's the last one
  342. row.find("select[name='field']")[0].selectedIndex = 0;
  343. row.find("select[name='op']")[0].selectedIndex = 0;
  344. row.find(".data input").val(""); // blank all input values
  345. row.find(".data select").each(function() { this.selectedIndex = 0; }); // select first option on all selects
  346. row.find("select[name='field']").change(); // trigger any change events
  347. }
  348. return false;
  349. });
  350. jQ.find(".ui-add").click(function(e) {
  351. var row = jQuery(e.target).parents(".sf");
  352. var newRow = row.clone(true).insertAfter(row);
  353. newRow.find(".ui-state-default").removeClass("ui-state-hover ui-state-active");
  354. if (opts.clone) {
  355. newRow.find("select[name='field']")[0].selectedIndex = row.find("select[name='field']")[0].selectedIndex;
  356. var stupid_browser = (newRow.find("select[name='op']")[0] == null); // true for IE6
  357. if (!stupid_browser)
  358. newRow.find("select[name='op']").focus()[0].selectedIndex = row.find("select[name='op']")[0].selectedIndex;
  359. var jElem = newRow.find("select.vdata");
  360. if (jElem[0] != null) // select doesn't copy it's selected index when cloned
  361. jElem[0].selectedIndex = row.find("select.vdata")[0].selectedIndex;
  362. } else {
  363. newRow.find(".data input").val(""); // blank all input values
  364. newRow.find("select[name='field']").focus();
  365. }
  366. if (opts.datepickerFix === true && jQuery.fn.datepicker !== undefined) { // using $.data to associate data with document elements is Not Good
  367. row.find(".hasDatepicker").each(function() {
  368. var settings = jQuery.data(this, "datepicker").settings;
  369. newRow.find("#" + this.id).unbind().removeAttr("id").removeClass("hasDatepicker").datepicker(settings);
  370. });
  371. }
  372. newRow.find("select[name='field']").change();
  373. return false;
  374. });
  375. jQ.find(".ui-search").click(function(e) {
  376. var ui = jQuery(jQ.selector);
  377. var ruleGroup;
  378. var group_op = ui.find("select[name='groupOp'] :selected").val();
  379. if (!opts.stringResult) {
  380. ruleGroup = {
  381. groupOp: group_op,
  382. rules: []
  383. };
  384. } else {
  385. ruleGroup = "{\"groupOp\":\"" + group_op + "\",\"rules\":[";
  386. }
  387. ui.find(".sf").each(function(i) {
  388. var tField = jQuery(this).find("select[name='field'] :selected").val();
  389. var tOp = jQuery(this).find("select[name='op'] :selected").val();
  390. var tData = jQuery(this).find("input.vdata,select.vdata :selected").val();
  391. tData += "";
  392. tData = tData.replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  393. if (!opts.stringResult) {
  394. ruleGroup.rules.push({
  395. field: tField,
  396. op: tOp,
  397. data: tData
  398. });
  399. } else {
  400. if (i > 0) ruleGroup += ",";
  401. ruleGroup += "{\"field\":\"" + tField + "\",";
  402. ruleGroup += "\"op\":\"" + tOp + "\",";
  403. ruleGroup += "\"data\":\"" + tData + "\"}";
  404. }
  405. });
  406. if (opts.stringResult) ruleGroup += "]}";
  407. opts.onSearch(ruleGroup);
  408. return false;
  409. });
  410. jQ.find(".ui-reset").click(function(e) {
  411. var ui = jQuery(jQ.selector);
  412. ui.find(".ui-del").click(); // removes all filters, resets the last one
  413. ui.find("select[name='groupOp']")[0].selectedIndex = 0; // changes the op back to the default one
  414. opts.onReset();
  415. return false;
  416. });
  417. jQ.find(".ui-add-last").click(function() {
  418. var row = jQuery(jQ.selector + " .sf:last");
  419. var newRow = row.clone(true).insertAfter(row);
  420. newRow.find(".ui-state-default").removeClass("ui-state-hover ui-state-active");
  421. newRow.find(".data input").val(""); // blank all input values
  422. newRow.find("select[name='field']").focus();
  423. if (opts.datepickerFix === true && jQuery.fn.datepicker !== undefined) { // using $.data to associate data with document elements is Not Good
  424. row.find(".hasDatepicker").each(function() {
  425. var settings = jQuery.data(this, "datepicker").settings;
  426. newRow.find("#" + this.id).unbind().removeAttr("id").removeClass("hasDatepicker").datepicker(settings);
  427. });
  428. }
  429. newRow.find("select[name='field']").change();
  430. return false;
  431. });
  432. }
  433. }
  434. return new SearchFilter(this, fields, options);
  435. };
  436. jQuery.fn.searchFilter.version = '1.2.9';
  437. /* This property contains the default options */
  438. jQuery.fn.searchFilter.defaults = {
  439. /*
  440. * PROPERTY
  441. * TYPE: boolean
  442. * DESCRIPTION: clone a row if it is added from an existing row
  443. * when false, any new added rows will be blank.
  444. */
  445. clone: true,
  446. /*
  447. * PROPERTY
  448. * TYPE: boolean
  449. * DESCRIPTION: current version of datepicker uses a data store,
  450. * which is incompatible with $().clone(true)
  451. */
  452. datepickerFix: true,
  453. /*
  454. * FUNCTION
  455. * DESCRIPTION: the function that will be called when the user clicks Reset
  456. * INPUT TYPE: JS object if stringResult is false, otherwise is JSON string
  457. */
  458. onReset: function(data) { alert("Reset Clicked. Data Returned: " + data) },
  459. /*
  460. * FUNCTION
  461. * DESCRIPTION: the function that will be called when the user clicks Search
  462. * INPUT TYPE: JS object if stringResult is false, otherwise is JSON string
  463. */
  464. onSearch: function(data) { alert("Search Clicked. Data Returned: " + data) },
  465. /*
  466. * FUNCTION
  467. * DESCRIPTION: the function that will be called when the user clicks the Closer icon
  468. * or the close() function is called
  469. * if left null, it simply does a .hide() on the searchFilter
  470. * INPUT TYPE: a jQuery object for the searchFilter
  471. */
  472. onClose: function(jElem) { jElem.hide(); },
  473. /*
  474. * PROPERTY
  475. * TYPE: array of objects, each object has the properties op and text
  476. * DESCRIPTION: the selectable operators that are applied between rules
  477. * e.g. for {op:"AND", text:"all"}
  478. * the search filter box will say: match all rules
  479. * the server should interpret this as putting the AND op between each rule:
  480. * rule1 AND rule2 AND rule3
  481. * text will be the option text, and op will be the option value
  482. */
  483. groupOps: [
  484. { op: "AND", text: "all" },
  485. { op: "OR", text: "any" }
  486. ],
  487. /*
  488. * PROPERTY
  489. * TYPE: array of objects, each object has the properties op and text
  490. * DESCRIPTION: the operators that will appear as drop-down options
  491. * text will be the option text, and op will be the option value
  492. */
  493. operators: [
  494. { op: "eq", text: "is equal to" },
  495. { op: "ne", text: "is not equal to" },
  496. { op: "lt", text: "is less than" },
  497. { op: "le", text: "is less or equal to" },
  498. { op: "gt", text: "is greater than" },
  499. { op: "ge", text: "is greater or equal to" },
  500. { op: "in", text: "is in" },
  501. { op: "ni", text: "is not in" },
  502. { op: "bw", text: "begins with" },
  503. { op: "bn", text: "does not begin with" },
  504. { op: "ew", text: "ends with" },
  505. { op: "en", text: "does not end with" },
  506. { op: "cn", text: "contains" },
  507. { op: "nc", text: "does not contain" }
  508. ],
  509. /*
  510. * PROPERTY
  511. * TYPE: string
  512. * DESCRIPTION: part of the phrase: _match_ ANY/ALL rules
  513. */
  514. matchText: "match",
  515. /*
  516. * PROPERTY
  517. * TYPE: string
  518. * DESCRIPTION: part of the phrase: match ANY/ALL _rules_
  519. */
  520. rulesText: "rules",
  521. /*
  522. * PROPERTY
  523. * TYPE: string
  524. * DESCRIPTION: the text that will be displayed in the reset button
  525. */
  526. resetText: "Reset",
  527. /*
  528. * PROPERTY
  529. * TYPE: string
  530. * DESCRIPTION: the text that will be displayed in the search button
  531. */
  532. searchText: "Search",
  533. /*
  534. * PROPERTY
  535. * TYPE: boolean
  536. * DESCRIPTION: a flag that, when set, will make the onSearch and onReset return strings instead of objects
  537. */
  538. stringResult: true,
  539. /*
  540. * PROPERTY
  541. * TYPE: string
  542. * DESCRIPTION: the title of the searchFilter window
  543. */
  544. windowTitle: "Search Rules",
  545. /*
  546. * PROPERTY
  547. * TYPE: object
  548. * DESCRIPTION: options to extend the ajax request
  549. */
  550. ajaxSelectOptions : {}
  551. }; /* end of searchFilter */