buildoldform.html.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <?php
  2. /**
  3. * The buildform view of search module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package search
  9. * @version $Id: buildform.html.php 4129 2013-01-18 01:58:14Z wwccss $
  10. * @link https://www.zentao.net
  11. */
  12. ?>
  13. <?php
  14. $jsRoot = $this->app->getWebRoot() . "js/";
  15. include '../../common/view/datepicker.html.php';
  16. include '../../common/view/chosen.html.php';
  17. $formId = 'searchForm-' . uniqid('');
  18. $groupItems = $config->search->groupItems;
  19. ?>
  20. <style>
  21. #save-query .text {font-weight: 400; font-size: 14px;}
  22. #selectPeriod {padding: 4px 0; height: 197px; min-width: 120px}
  23. #selectPeriod > .dropdown-header {background: #f1f1f1; display: block; text-align: center; padding: 4px 0; line-height: 20px; margin: 5px 10px; font-size: 14px; border-radius: 2px; color: #333; font-size: 12px}
  24. #groupAndOr {display: inline-block;}
  25. #<?php echo $formId;?> > table {margin: 0 auto;}
  26. #<?php echo $formId;?> > table > tbody > tr > td {padding: 8px;}
  27. #<?php echo $formId;?> .form-actions {padding-bottom: 20px; padding-top: 0;}
  28. <?php if(common::checkNotCN()):?>
  29. #<?php echo $formId;?> [id^="valueBox"] .chosen-container .chosen-single {min-width: 70px;}
  30. <?php else:?>
  31. #<?php echo $formId;?> [id^="valueBox"] .chosen-container .chosen-single {min-width: 100px;}
  32. <?php endif;?>
  33. #<?php echo $formId;?> .chosen-container .chosen-drop ul.chosen-results li {white-space:normal}
  34. #<?php echo $formId;?> input.date::-webkit-input-placeholder {color: #838A9D; opacity: 1;}
  35. #<?php echo $formId;?> input.date::-moz-placeholder {color: #838A9D; opacity: 1;}
  36. #<?php echo $formId;?> input.date:-ms-input-placeholder {color: #838A9D; opacity: 1;}
  37. #<?php echo $formId;?> .btn-expand-form {background: transparent;}
  38. #<?php echo $formId;?> .btn-expand-form:hover {background: #e9f2fb;}
  39. .showmore .btn-expand-form .icon-chevron-double-down:before {content: '\e959';}
  40. #queryBox select[id^="operator"] {padding-right:2px; padding-left:5px;}
  41. #queryBox select#groupAndOr {padding-right:2px; padding-left:5px;}
  42. #queryBox .chosen-container-single .chosen-single > span {margin-right:5px;}
  43. #queryBox .form-actions .btn {margin-right: 5px;}
  44. @media screen and (max-width: 1366px) { #userQueries {width: 130px!important;} }
  45. #userQueries {border-left: 1px solid #eee; vertical-align: top;}
  46. #userQueries > h4 {margin: 0 0 6px;}
  47. #userQueries ul {list-style: none; padding-left: 0; margin: 0; max-height:75px; overflow:auto;}
  48. .showmore #userQueries ul {max-height:170px;}
  49. #userQueries ul li + li {margin-top: 5px;}
  50. #userQueries .label {line-height: 24px; padding: 0 20px 0 8px; display: inline-block; background-color: #EEEEEE; color: #A6AAB8; border-radius: 12px; max-width: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; position: relative;}
  51. #userQueries .label:hover {background-color: #aaa; color: #fff;}
  52. #userQueries .label > .icon-close {position: absolute; top: 2px; right: 2px; border-radius: 9px; font-size: 12px; line-height: 18px; width: 18px; display: inline-block;}
  53. #userQueries .label > .icon-close:hover {background-color: #ff5d5d; color: #fff;}
  54. @media (max-width: 1050px) {#userQueries, #toggle-queries {display: none}}
  55. <?php if($style == 'simple'):?>
  56. #<?php echo $formId;?> .form-actions {text-align: left; padding: 0!important; max-width: 200px; vertical-align: middle; width: 100px;}
  57. #queryBox.show {min-height: 66px;}
  58. <?php endif;?>
  59. #toggle-queries {position: absolute; right: 0px; top: 40px; width: 13px; background: #79cdfb; border-radius: 6px; height: 30px;cursor: pointer}
  60. #toggle-queries .icon {position: absolute; top: 6px; right: -2px; color: #fff;}
  61. .fieldWidth {width: 130px !important;}
  62. .operatorWidth {width: 110px !important;}
  63. html[lang^='zh-'] .fieldWidth {width: 110px !important;}
  64. html[lang^='zh-'] .operatorWidth {width: 90px !important;}
  65. .table tbody tr td input {display: block !important;}
  66. #save-query {float: unset !important; position: absolute; right: 50px;}
  67. #save-query .text {top: 0px;}
  68. #save-query .text:after {border-bottom: 0px solid #0c64eb;}
  69. #<?php echo $formId;?> [id^='valueBox'] > div.picker span.picker-selection-text {padding-right: 10px;}
  70. </style>
  71. <?php if($style != 'simple'):?>
  72. <div id='toggle-queries'>
  73. <i class='icon icon-angle-left'></i>
  74. </div>
  75. <?php endif;?>
  76. <form method='post' action='<?php echo $this->createLink('search', 'buildOldQuery');?>' target='hiddenwin' id='<?php echo $formId;?>' class='search-form no-stash<?php if($style == 'simple') echo ' search-form-simple';?>'>
  77. <div class='hidden'>
  78. <?php
  79. /* Print every field as an html object, select or input. Thus when setFiled is called, copy it's html to build the search form. */
  80. foreach($fieldParams as $fieldName => $param)
  81. {
  82. echo "<div id='box$fieldName'>";
  83. if($param['control'] == 'select') echo html::select('field' . $fieldName, $param['values'], '', "class='form-control searchSelect'");
  84. if($param['control'] == 'input') echo html::input('field' . $fieldName, '', "class='form-control searchInput'");
  85. echo '</div>';
  86. }
  87. ?>
  88. </div>
  89. <?php
  90. $printGroup = function(&$formSession, &$fieldNO, $group) use ($lang, $config, $module, $fields, $fieldParams, $groupItems)
  91. {
  92. for($i = 1; $i <= $groupItems; $i ++)
  93. {
  94. $spanClass = $i == 1 ? '' : 'hidden';
  95. echo "<tr id='searchbox$fieldNO' class='$spanClass'>";
  96. /* Get params of current field. */
  97. $currentField = $formSession["field$fieldNO"];
  98. if(!isset($fieldParams[$currentField]))
  99. {
  100. $currentField = key($fields);
  101. $formSession["field$fieldNO"] = $currentField;
  102. $formSession["operator$fieldNO"] = isset($fieldParams[$currentField]['operator']) ? $fieldParams[$currentField]['operator'] : '=';
  103. $formSession["value$fieldNO"] = '';
  104. }
  105. $param = $fieldParams[$currentField];
  106. /* Print and or. */
  107. echo "<td class='text-right w-80px'>";
  108. if($i == 1) echo "<span id='search{$group}'><strong>{$lang->search->$group}</strong></span>" . html::hidden("andOr$fieldNO", 'AND');
  109. if($i > 1) echo html::select("andOr$fieldNO", $lang->search->andor, $formSession["andOr$fieldNO"], "class='form-control'");
  110. echo '</td>';
  111. /* Print field. */
  112. echo "<td class='fieldWidth' style='overflow: visible'>" . html::select("field$fieldNO", $fields, $formSession["field$fieldNO"], "onchange='setField(this, $fieldNO, {$module}params)' class='form-control chosen'") . '</td>';
  113. /* Print operator. */
  114. echo "<td class='operatorWidth'>" . html::select("operator$fieldNO", $lang->search->operators, $formSession["operator$fieldNO"], "class='form-control' onchange='setPlaceHolder($fieldNO)'") . '</td>';
  115. /* Print value. */
  116. echo "<td id='valueBox$fieldNO' style='overflow: visible'>";
  117. if(isset($config->moreLinks["field{$currentField}"]))
  118. {
  119. $selected = $formSession["value$fieldNO"];
  120. if(!isset($param['values'][$selected])) $config->moreLinks["value$fieldNO"] = $config->moreLinks["field{$currentField}"];
  121. }
  122. if($param['control'] == 'select') echo html::select("value$fieldNO", $param['values'], $formSession["value$fieldNO"], "class='form-control searchSelect chosen' data-max_drop_width='0'");
  123. if($param['control'] == 'input')
  124. {
  125. $fieldName = $formSession["field$fieldNO"];
  126. $fieldValue = $formSession["value$fieldNO"];
  127. $extraClass = isset($param['class']) ? $param['class'] : '';
  128. $placeholder = '';
  129. if($fieldValue && strpos('$lastWeek,$thisWeek,$today,$yesterday,$thisMonth,$lastMonth',$fieldValue) !== false)
  130. {
  131. $placeholder = "placeholder='{$fieldValue}'";
  132. }
  133. elseif($fieldName == 'id' and $formSession["operator$fieldNO"] == '=')
  134. {
  135. $placeholder = "placeholder='{$lang->search->queryTips}'";;
  136. }
  137. echo html::input("value$fieldNO", $fieldValue, "class='form-control $extraClass searchInput' $placeholder data-max_drop_width='0'");
  138. }
  139. echo '</td>';
  140. $fieldNO ++;
  141. echo '</tr>';
  142. }
  143. };
  144. ?>
  145. <table class='table table-condensed table-form' id='<?php echo "{$module}-search";?>'>
  146. <tbody>
  147. <tr>
  148. <td class='w-400px'>
  149. <table class='table table-form table-fixed'>
  150. <tbody>
  151. <?php
  152. $formSessionName = $module . 'Form';
  153. $formSession = $_SESSION[$formSessionName];
  154. $fieldNO = 1;
  155. $printGroup($formSession, $fieldNO, 'group1');
  156. ?>
  157. </tbody>
  158. </table>
  159. </td>
  160. <td class='text-center nobr w-70px'><?php echo html::select('groupAndOr', $lang->search->andor, $formSession['groupAndOr'], "class='form-control'")?></td>
  161. <td class='w-400px'>
  162. <table class='table table-form'>
  163. <tbody>
  164. <?php $printGroup($formSession, $fieldNO, 'group2');?>
  165. </tbody>
  166. </table>
  167. </td>
  168. <?php if($style != 'simple'):?>
  169. <td class='w-160px hidden' rowspan='2' id='userQueries'>
  170. <h4><?php echo $lang->search->savedQuery;?></h4>
  171. <ul>
  172. <?php foreach($queries as $query):?>
  173. <?php if(empty($query->id)) continue;?>
  174. <li><?php echo html::a("javascript:executeQuery($query->id)", $query->title . ((common::hasPriv('search', 'deleteQuery') and $this->app->user->account == $query->account) ? '<i class="icon icon-close"></i>' : ''), '', "class='label user-query' data-query-id='$query->id' title='{$query->title}'");?></li>
  175. <?php endforeach;?>
  176. </ul>
  177. </td>
  178. </tr>
  179. <tr>
  180. <?php endif;?>
  181. <td colspan='3' class='text-center form-actions'>
  182. <?php
  183. echo html::hidden('module', $module);
  184. echo html::hidden('actionURL', $actionURL);
  185. echo html::hidden('groupItems', $groupItems);
  186. echo html::submitButton($lang->search->common, '', 'btn btn-primary') . " &nbsp; ";
  187. if($style != 'simple') echo html::commonButton($lang->search->reset, '', 'btn-reset-form btn');
  188. echo html::commonButton('<i class="icon icon-chevron-double-down"></i>', '', 'btn-expand-form btn btn-info pull-right');
  189. if($style != 'simple' and common::hasPriv('search', 'saveQuery')) echo html::a($this->createLink('search', 'saveOldQuery', "module=$module&onMenuBar=$onMenuBar"), '<span class="text"><i class="icon-bug-confirm icon-save"></i> ' . $lang->search->saveCondition . '</span>', '', "class='btn-save-form btn btn-link btn-active-text text iframe' id='save-query'");
  190. echo html::hidden('formType', zget($formSession, 'formType', 'lite'));
  191. ?>
  192. </td>
  193. </tr>
  194. </tbody>
  195. </table>
  196. </form>
  197. <?php js::set('searchCustom', $lang->search->custom);?>
  198. <?php js::set('canSaveQuery', !empty($_SESSION[$module . 'Query']));?>
  199. <script>
  200. var dtOptions =
  201. {
  202. language: '<?php echo $this->app->getClientLang();?>',
  203. weekStart: 1,
  204. todayBtn: 1,
  205. autoclose: 1,
  206. todayHighlight: 1,
  207. startView: 2,
  208. minView: 2,
  209. forceParse: 0,
  210. format: 'yyyy-mm-dd'
  211. };
  212. var <?php echo $module . 'params'?> = <?php echo empty($fieldParams) ? '{}' : json_encode($fieldParams);?>;
  213. var groupItems = <?php echo $groupItems;?>;
  214. var setQueryTitle = '<?php echo $lang->search->setQueryTitle;?>';
  215. var module = '<?php echo $module;?>';
  216. var actionURL = '<?php echo $actionURL;?>';
  217. function executeQuery(queryID)
  218. {
  219. if(!queryID) return;
  220. location.href = actionURL.replace('myQueryID', queryID);
  221. }
  222. $(function()
  223. {
  224. if(!canSaveQuery)
  225. {
  226. $('.btn-save-form').attr('disabled', 'disabled');
  227. $('.btn-save-form').css('pointer-events', 'none');
  228. }
  229. var $searchForm = $('#<?php echo $formId;?>');
  230. $searchForm.find('select.chosen').chosen().on('chosen:showing_dropdown', function()
  231. {
  232. var $this = $(this);
  233. var $chosen = $this.next('.chosen-container').removeClass('chosen-up');
  234. var $drop = $chosen.find('.chosen-drop');
  235. if($this.data('drop_direction') === 'auto') $chosen.toggleClass('chosen-up', $drop.height() + $drop.offset().top - $(document).scrollTop() > $(window).height());
  236. });
  237. $searchForm.find('.picker-select').each(function()
  238. {
  239. var $select = $(this);
  240. var pickerOptions = {chosenMode: true}
  241. if($select.attr('data-pickertype') == 'remote') pickerOptions.remote = $select.attr('data-pickerremote');
  242. $select.picker(pickerOptions);
  243. });
  244. $('#queryBox select, #queryBox input').change(function()
  245. {
  246. $('#save-query').attr("disabled", "disabled");
  247. })
  248. /* Toggle user queries action. */
  249. $('#toggle-queries').click(function()
  250. {
  251. $('#userQueries').toggleClass('hidden');
  252. if(!$('#userQueries').hasClass('hidden'))
  253. {
  254. $('#toggle-queries .icon').removeClass('icon-angle-left');
  255. $('#toggle-queries .icon').addClass('icon-angle-right');
  256. $('#toggle-queries').css('right', $('#userQueries').outerWidth());
  257. $('#save-query').css('right', $('#userQueries').outerWidth() + 50);
  258. }
  259. else
  260. {
  261. $('#toggle-queries .icon').removeClass('icon-angle-right');
  262. $('#toggle-queries .icon').addClass('icon-angle-left');
  263. $('#toggle-queries').css('right', '0px');
  264. $('#save-query').css('right', 50);
  265. }
  266. });
  267. $('.sidebar-toggle').click(function()
  268. {
  269. if(!$('#userQueries').hasClass('hidden')) $('#toggle-queries').click();
  270. })
  271. $(window).resize(function()
  272. {
  273. if(!$('#userQueries').hasClass('hidden'))
  274. {
  275. $('#toggle-queries').css('right', $('#userQueries').outerWidth());
  276. $('#save-query').css('right', $('#userQueries').outerWidth() + 50);
  277. }
  278. })
  279. /*
  280. * Load queries form
  281. */
  282. var loadQueries = window.loadQueries = function(queryID, shortcut, name)
  283. {
  284. $('#userQueries ul').load($.createLink('search', 'ajaxGetQuery', 'module=' + module + '&queryID=' + queryID));
  285. if(shortcut)
  286. {
  287. if($('#mainMenu .btn-toolbar.pull-left #query').size() == 0)
  288. {
  289. var html = '<div class="btn-group" id="query"><a href="javascript:;" data-toggle="dropdown" class="btn btn-link " style="border-radius: 2px;">' + searchCustom + ' <span class="caret"></span></a><ul class="dropdown-menu"></ul></div>';
  290. html += '<style>#mainMenu #query.btn-group li {position: relative;} #mainMenu #query.btn-group li a{margin-right:20px;} #mainMenu #query.btn-group li .btn-delete{ padding:0 7px; position: absolute; right: -10px; top: -3px; display: block; width: 20px; text-align: center; } </style>';
  291. html += "<script> function removeQueryFromMenu(obj) { var $obj = $(obj); var link = createLink('search', 'ajaxRemoveMenu', 'queryID=' + $obj.data('id')); $.get(link, function() { $obj.closest('li').remove(); if($('#mainMenu #query.btn-group').find('li').length == 0) $('#mainMenu #query.btn-group').remove(); })}<\/script>";
  292. $('#mainMenu .btn-toolbar.pull-left #bysearchTab').before(html);
  293. }
  294. html = "<li><a href='" + actionURL.replace('myQueryID', queryID) + "'>" + name + "</a>";
  295. html += "<a href='###' class='btn-delete' data-id='" + queryID + "' onclick='removeQueryFromMenu(this)'><i class='icon icon-close'></i></a></li>";
  296. $('#mainMenu .btn-toolbar.pull-left #query ul.dropdown-menu').append(html);
  297. }
  298. };
  299. /*
  300. * Expand or collapse form
  301. *
  302. * @param expand true for expand form, false for collapse form
  303. */
  304. var expandForm = function(expand)
  305. {
  306. if (expand === undefined) expand = !$searchForm.hasClass('showmore');
  307. $searchForm.toggleClass('showmore', expand);
  308. for(i = 1; i <= groupItems * 2; i ++)
  309. {
  310. if(i != 1 && i != groupItems + 1 )
  311. {
  312. $searchForm.find('#searchbox' + i).toggleClass('hidden', !expand);
  313. }
  314. }
  315. $searchForm.find('#formType').val(expand ? 'more' : 'lite');
  316. };
  317. /**
  318. * Set date field
  319. *
  320. * @param string $query
  321. * @return void
  322. */
  323. var setDateField = function(query, fieldNO)
  324. {
  325. var $period = $('#selectPeriod');
  326. <?php
  327. $selectPeriod = "<ul id='selectPeriod' class='dropdown-menu'>";
  328. $selectPeriod .= "<li class='dropdown-header'>{$lang->datepicker->dpText->TEXT_OR} {$lang->datepicker->dpText->TEXT_DATE}</li>";
  329. $selectPeriod .= "<li><a href='#lastWeek'>{$lang->datepicker->dpText->TEXT_PREV_WEEK}</a></li>";
  330. $selectPeriod .= "<li><a href='#thisWeek'>{$lang->datepicker->dpText->TEXT_THIS_WEEK}</a></li>";
  331. $selectPeriod .= "<li><a href='#yesterday'>{$lang->datepicker->dpText->TEXT_YESTERDAY}</a></li>";
  332. $selectPeriod .= "<li><a href='#today'>{$lang->datepicker->dpText->TEXT_TODAY}</a></li>";
  333. $selectPeriod .= "<li><a href='#lastMonth'>{$lang->datepicker->dpText->TEXT_PREV_MONTH}</a></li>";
  334. $selectPeriod .= "<li><a href='#thisMonth'>{$lang->datepicker->dpText->TEXT_THIS_MONTH}</a></li></ul>";
  335. ?>
  336. $period = $(<?php echo json_encode($selectPeriod);?>).appendTo('body');
  337. $period.find('li > a').click(function(event)
  338. {
  339. var target = $(query).closest('form').find('#' + $period.data('target'));
  340. if(target.length)
  341. {
  342. if(target.next('input[type=hidden]').length)
  343. {
  344. target.next('input[type=hidden]').val($(this).attr('href').replace('#', '$'));
  345. }
  346. else
  347. {
  348. target.val($(this).attr('href').replace('#', '$'));
  349. }
  350. target.attr('placeholder', $(this).attr('href').replace('#', '$'));
  351. $(query).closest('form').find('#operator' + $period.data('fieldNO')).val('between');
  352. $period.hide();
  353. }
  354. event.stopPropagation();
  355. return false;
  356. });
  357. $(query).datetimepicker('remove').datepicker(dtOptions).on('show', function(e)
  358. {
  359. var $e = $(e.target);
  360. var ePos = $e.offset();
  361. $period.css({'left': ePos.left - 120, 'top': ePos.top + 29, 'min-height': $('.datetimepicker').outerHeight()}).show().data('target', $e.attr('id')).data('fieldNO', fieldNO).find('li.active').removeClass('active');
  362. if($e.attr('placeholder'))
  363. {
  364. $period.find("li > a[href='" + $e.attr('placeholder').replace('$', '#') + "']").closest('li').addClass('active');
  365. }
  366. else
  367. {
  368. $period.find("li > a[href='" + $e.val().replace('$', '#') + "']").closest('li').addClass('active');
  369. }
  370. }).on('changeDate', function()
  371. {
  372. var opt = $(query).closest('form').find('#operator' + $period.data('fieldNO'));
  373. var target = $('#' + $period.data('target'));
  374. if(target.length)
  375. {
  376. if(target.next('input[type=hidden]').length)
  377. {
  378. target.next('input[type=hidden]').val(target.val());
  379. }
  380. }
  381. if(opt.val() == 'between') opt.val('<=');
  382. $period.hide();
  383. }).on('hide', function(){setTimeout(function(){$period.hide();}, 200);});
  384. }
  385. /**
  386. * When the value of the fields select changed, set the operator and value of the new field.
  387. *
  388. * @param string $obj
  389. * @param int $fieldNO
  390. * @access public
  391. * @return void
  392. */
  393. var setField = window.setField = function(obj, fieldNO, moduleparams)
  394. {
  395. var params = moduleparams;
  396. var $obj = $(obj);
  397. var fieldName = $obj.val();
  398. $searchForm.find('#operator' + fieldNO).val(params[fieldName]['operator']); // Set the operator according the param setting.
  399. $searchForm.find('#valueBox' + fieldNO).html($searchForm.find('#box' + fieldName).children().clone());
  400. $searchForm.find('#valueBox' + fieldNO).children().attr({name : 'value' + fieldNO, id : 'value' + fieldNO});
  401. if(fieldName == 'id') setPlaceHolder(fieldNO);
  402. if(typeof(params[fieldName]['class']) != undefined && params[fieldName]['class'] == 'date')
  403. {
  404. setDateField($searchForm.find("#value" + fieldNO), fieldNO);
  405. $searchForm.find("#value" + fieldNO).addClass('date'); // Shortcut the width of the datepicker to make sure align with others.
  406. var maxNO = 2 * groupItems;
  407. var nextNO = fieldNO > groupItems ? fieldNO - groupItems + 1 : fieldNO + groupItems;
  408. var nextValue = $searchForm.find('#value' + nextNO).val();
  409. var operator = $searchForm.find("#operator" + fieldNO).val();
  410. if(nextNO <= maxNO && fieldNO < maxNO && (nextValue == '' || nextValue == 0) && operator == ">=")
  411. {
  412. $searchForm.find('#field' + nextNO).val($searchForm.find('#field' + fieldNO).val());
  413. $searchForm.find('#operator' + nextNO).val('<=');
  414. $searchForm.find('#valueBox' + nextNO).html($searchForm.find('#box' + fieldName).children().clone());
  415. $searchForm.find('#valueBox' + nextNO).children().attr({name : 'value' + nextNO, id : 'value' + nextNO});
  416. setDateField($searchForm.find("#value" + nextNO), nextNO);
  417. $searchForm.find("#value" + nextNO).addClass('date');
  418. }
  419. }
  420. else if(params[fieldName]['control'] == 'select')
  421. {
  422. $searchForm.find(".picker#value" + fieldNO).remove();
  423. if($searchForm.find("#value" + fieldNO).attr('data-pickertype') == 'remote')
  424. {
  425. $searchForm.find("#value" + fieldNO).picker(
  426. {
  427. chosenMode: true,
  428. dropWidth: 'auto',
  429. minAutoDropWidth: '100%',
  430. maxAutoDropWidth: 350,
  431. remote: $searchForm.find("#value" + fieldNO).attr('data-pickerremote')
  432. });
  433. }
  434. else
  435. {
  436. $searchForm.find("#value" + fieldNO).picker(
  437. {
  438. chosenMode: true,
  439. dropWidth: '100%'
  440. });
  441. }
  442. }
  443. };
  444. /**
  445. * When the value of the operator select changed, set the placeholder for the valueBox.
  446. *
  447. * @param int $fieldNO
  448. * @access public
  449. * @return void
  450. */
  451. var setPlaceHolder = window.setPlaceHolder = function(fieldNO)
  452. {
  453. var operator = $('#operator' + fieldNO).val();
  454. var fieldName = $('#field' + fieldNO).val();
  455. if(operator == '=' && fieldName == 'id')
  456. {
  457. $('#value' + fieldNO).attr("placeholder","<?php echo $lang->search->queryTips;?>");
  458. }
  459. else
  460. {
  461. $('#value' + fieldNO).attr("placeholder","");
  462. }
  463. }
  464. /*
  465. * Reset form
  466. */
  467. window.resetForm = function()
  468. {
  469. for(i = 1; i <= groupItems * 2; i ++)
  470. {
  471. if(!$searchForm.find('#value' + i).hasClass('picker-select')) $searchForm.find('#value' + i).val('').trigger('chosen:updated');
  472. if($searchForm.find('#value' + i).hasClass('picker-select')) $searchForm.find('#value' + i).data('zui.picker').setValue('');
  473. $searchForm.find('#value' + i + '.date').val('').attr('placeholder', '');
  474. }
  475. };
  476. $searchForm.on('click', '.btn-expand-form', function() {expandForm();});
  477. $searchForm.on('click', '.btn-reset-form', function() {resetForm();});
  478. $searchForm.on('change', 'select[id^="operator"]', function()
  479. {
  480. var $select = $(this);
  481. var value = $select.val();
  482. var $tr = $select.closest('tr');
  483. if(value == '>=' && $tr.find('input[id^="value"].date').length)
  484. {
  485. var fieldNO = parseInt($(this).attr('id').replace('operator', ''));
  486. var fieldName = $tr.find("select[id^='field']").val();
  487. var maxNO = 2 * groupItems;
  488. var nextNO = fieldNO > groupItems ? fieldNO - groupItems + 1 : fieldNO + groupItems;
  489. var nextValue = searchForm.find('#value' + nextNO).val();
  490. if(nextNO <= maxNO && fieldNO < maxNO && (nextValue == '' || nextValue == 0))
  491. {
  492. searchForm.find('#field' + nextNO).val(searchForm.find('#field' + fieldNO).val());
  493. searchForm.find('#operator' + nextNO).val('<=');
  494. searchForm.find('#valueBox' + nextNO).html(searchForm.find('#box' + fieldName).children().clone());
  495. searchForm.find('#valueBox' + nextNO).children().attr({name : 'value' + nextNO, id : 'value' + nextNO});
  496. setDateField(searchForm.find("#value" + nextNO), nextNO);
  497. searchForm.find("#value" + nextNO).addClass('date');
  498. }
  499. }
  500. });
  501. $searchForm.find('.btn-save-form').modalTrigger({width:650, type:'iframe', title: setQueryTitle});
  502. if($('#formType').val() == 'more') expandForm(true);
  503. $searchForm.on('click', '.user-query .icon-close', function(e)
  504. {
  505. e.preventDefault(); // Fix bug #21572.
  506. var $query = $(this).closest('.user-query');
  507. var queryId = $query.data('queryId');
  508. var deleteQueryLink = $.createLink('search', 'deleteQuery', 'queryID=' + queryId);
  509. $.getJSON(deleteQueryLink, function(data)
  510. {
  511. if(data.result == 'success') $query.remove();
  512. });
  513. e.stopPropagation();
  514. });
  515. /* Init datepicker for search. */
  516. $searchForm.find('.table-condensed input.date').each(function()
  517. {
  518. setDateField($(this), $(this).attr('id').substr(5));
  519. });
  520. });
  521. </script>