superedit-TREEJS.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. Lib::loadClass('ProcesHelper');
  3. Lib::loadClass('DebugExecutionTime');
  4. Lib::loadClass('Tree');
  5. Lib::loadClass('TreeHelper');
  6. Lib::loadClass('App');
  7. Lib::loadClass('Filter');
  8. function TREEJS__ajaxTask__idsList($args) {
  9. $zasobID = V::get('ZASOB_ID', 0, $args, 'int');
  10. if ($zasobID <= 0) {
  11. throw new HttpException("Wrong param ZASOB_ID", 400);
  12. }
  13. $id = V::get('id', 0, $args, 'int');
  14. if ($id <= 0) {
  15. throw new HttpException("Wrong param id", 400);
  16. }
  17. $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
  18. if (!$zasobObj) {
  19. throw new HttpException("Zasob TABELA ID={$zasobID} nie istnieje", 404);
  20. }
  21. $tblName = $zasobObj->DESC;
  22. $db = DB::getDB();
  23. $r = $db->get_by_id($tblName, $id);
  24. if (!$r) {
  25. throw new HttpException("Rekord ID={$id} nie istnieje", 404);
  26. }
  27. $wsk = array();
  28. $ids_conf_arr = array();
  29. $ids_conf_arr['DEVICES'] = array('id_col'=>"T_DEVICE_SERIAL",'allowed_cols'=>"ID,CRM_LISTA_ZASOBOW_ID:CLZ_ID,T_TELBOX_NEIGHBOUR_IN,T_DEVICE_SERIAL,T_DEVICE_INFO,A_STATUS,S_OTHER_INFO");
  30. $ids_conf_arr['TELBOXES'] = array('id_col'=>"T_TELBOX_NAME",'allowed_cols'=>"ID,CRM_LISTA_ZASOBOW_ID:CLZ_ID,T_TELBOX_NEIGHBOUR_IN,T_TELBOX_NEIGHBOUR_OUT,T_TELBOX_NAME,A_STATUS,S_OTHER_INFO");
  31. if (!empty($ids_conf_arr)) {
  32. $external_ids = array();
  33. foreach ($ids_conf_arr as $k_table_name => $v_cnf) {
  34. $cur_cnf = new stdClass();
  35. $cur_cnf->id_col = V::get('id_col', 'ID', $v_cnf);
  36. $cur_cnf->search_col = V::get('search_col', 'ID_PROJECT', $v_cnf);
  37. $cur_cnf->search_col_regex = V::get('search_col_regex', '', $v_cnf);
  38. $sql_id_col = $cur_cnf->id_col;
  39. $sql_where = "";
  40. if ($cur_cnf->search_col_regex) {
  41. $sql_where = "`{$cur_cnf->search_col}` like '".str_replace('$ID', $r->ID, $cur_cnf->search_col_regex)."'";
  42. } else {
  43. $sql_where = "`{$cur_cnf->search_col}`='{$r->ID}'";
  44. }
  45. $db = DB::getDB();
  46. $sql = "select t.`{$sql_id_col}`
  47. from `{$k_table_name}` as t
  48. where {$sql_where}
  49. ";
  50. $res = $db->query($sql);
  51. while ($r_wsk = $db->fetch($res)) {
  52. $wsk[] = (object)array('name'=>$r_wsk->$sql_id_col, 'table'=>$k_table_name);
  53. }
  54. }
  55. }
  56. $response = new stdClass();
  57. $response->ids = $wsk;
  58. return $response;
  59. }
  60. function TREEJS() {
  61. global $result,$thiss;
  62. $ajaxTask = V::get('_ajaxTask', '', $_GET);
  63. $funName = "TREEJS__ajaxTask__{$ajaxTask}";
  64. if (function_exists($funName)) {
  65. try {
  66. $response = $funName($_GET);
  67. }
  68. catch (HttpException $e) {
  69. $response = new stdClass();
  70. $response->type = 'error';
  71. $response->msg = $e->getMessage();
  72. $response->errorCode = $e->getCode();
  73. Http::sendHeaderByCode($e->getCode());
  74. }
  75. catch (Exception $e) {
  76. $response = new stdClass();
  77. $response->type = 'error';
  78. $response->msg = $e->getMessage();
  79. $response->errorCode = $e->getCode();
  80. }
  81. header('Content-type: application/json');
  82. if (!$response) $response = new stdClass();
  83. echo json_encode($response);
  84. exit;
  85. }
  86. $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int');
  87. if ($zasobID <= 0) {
  88. echo 'Wrong param ZASOB_ID';
  89. return;
  90. }
  91. $TEST_TREE_LAZY_LOAD = 1;
  92. $DBG_TIME = ('1' == V::get('DBG_TIME', '', $_GET));
  93. $dbgExecTime = new DebugExecutionTime();
  94. if ($DBG_TIME) $dbgExecTime->activate();
  95. $dbgExecTime->log('start');
  96. echo "&lt;&lt;".'<a href="' . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobID}" . '" title="Powrot">Powrot do tabeli</a>';
  97. $conf = null;
  98. $tblName = '';
  99. $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
  100. if (!$zasobObj) {
  101. echo "Zasob TABELA ID={$zasobID} nie istnieje";
  102. return;
  103. }
  104. $tblName = $zasobObj->DESC;
  105. $allowed_tables_conf = array();
  106. $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI'] = array('set_parent_id_col'=>'P_ID');
  107. $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params'] = array();
  108. $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params']['show_item_callback'] = 'tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI';
  109. $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params']['ajax'] ='NIE';
  110. if (!array_key_exists($tblName, $allowed_tables_conf)) {
  111. echo'<p>'."Brak dostepu".'</p>';
  112. }
  113. $conf = $allowed_tables_conf[$tblName];
  114. echo'<style type="text/css">'."
  115. .btn-box{margin:0 2px 0 0;padding:0 3px;background:#bbb;color:#fff;text-decoration:none;border:0;font-weight:bold;}
  116. .btn-box-blue{background:#3A3AFF;color:#fff;}
  117. .btn-box-green{background:#008A00;color:#fff;}
  118. .btn-box-lgreen{background:#97CF97;color:#fff;}
  119. .btn-box-red{background:#FF4646;color:#fff;}
  120. .btn-box-group1{background-color:#9F9FCB;color:#fff;}
  121. .btn-box-group2{background-color:#B8B879;color:#fff;}
  122. /*.tree-wrap .btn{border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;}*/
  123. /*.btn-box{border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;}*/
  124. .filters{margin:0;padding:2px;background:#F0F0F0 url(./stuff/flexigrid/css/images/bg.gif) repeat-x top;border:1px solid #ccc;border-style:solid solid none solid;clear:both;overflow:hidden;}
  125. .filters .btnseparator{float:left;height:22px;border-left:1px solid #CCC;border-right:1px solid #fff;margin:1px;}
  126. .filters form{margin:0;padding:0;}
  127. .filters nobr{display:block;float:left;margin:0;padding:2px;font-weight:normal;font-size:13px;}
  128. .filters nobr:hover{text-decoration:underline;}
  129. .filters nobr.active{color:#f00;font-weight:normal;}
  130. .filters nobr input,
  131. .filters nobr select,
  132. .filters nobr button{margin:0 1px;padding:0 2px;font-size:13px;}
  133. .tree-wrap li.tree-close dd ul {display:block;}
  134. .tree-wrap li.tree-close dd ul,
  135. .tree-wrap dd ul { background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y; }
  136. .tree-wrap .btn {outline:none;}
  137. ".'</style>'."\n";
  138. App::show_head_css();
  139. App::show_head_js();
  140. function tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI(&$r, &$tree) {
  141. $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int');
  142. // TODO: btn-box zasob type from PARENT_ID
  143. $cls = array();
  144. if (($search_id = $tree->get_param('search_id')) > 0 && $search_id == $r->ID) {
  145. $cls[] = 'search_id';
  146. }
  147. $cls = (!empty($cls))? ' class="'.implode(' ', $cls).'"' : '';
  148. echo'<dl'.$cls.'>';
  149. echo'<dt>';
  150. $out_id = ($r->ID < 10)? '&nbsp;'.$r->ID.'' : $r->ID;
  151. echo'<a href="'."index.php?MENU_INIT=TREEJS&ZASOB_ID={$zasobID}&filtr_id={$r->ID}#TREE{$r->ID}" . '" class="item_id btn-box">'.$out_id.'</a>';
  152. echo'<a href="'."index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobID}#EDIT/{$r->ID}".'" class="btn btn-mini btn-link" title="'."Edit".'">'."E".'</a>';
  153. //if ($r->has_childrens) {
  154. // if (!$tree->get_param('rozwin')) {
  155. // $js = "return " . $tree->js_tree_open_rec_fun . "(this," . $r->ID . ");";
  156. // echo'<a href="'."#".'" title="'."Rozwin wszystko".'" onclick="'.$js.'" class="btn open-rec">'."L".'</a>';
  157. // }
  158. //}
  159. // TODO: edycja nie działa - bierze ostatni edytowany rekord
  160. //echo' <a href="'."?FUNCTION_INIT=IN7_MK_BAZA_DYSTRYBUCJI_EDIT&ARG1=EDIT&ARG1_VAL={$r->ID}".'" class="btn-box">'."E".'</a>';
  161. $st_status_bg = '';
  162. if ($r->A_STATUS == 'NORMAL') {
  163. $st_status_bg = '#8F8;';
  164. } else if ($r->A_STATUS == 'WAITING') {
  165. $st_status_bg = '#F8F;';
  166. } else if ($r->A_STATUS == 'DELETED') {
  167. $st_status_bg = '#ccc;';
  168. } else if ($r->A_STATUS == 'OFF_SOFT') {
  169. $st_status_bg = '#F99;';
  170. } else if ($r->A_STATUS == 'OFF_HARD') {
  171. $st_status_bg = '#eee;';
  172. }
  173. $st_status_bg = ($st_status_bg)? 'background-color:'.$st_status_bg : '';
  174. echo'<span class="desc">';
  175. echo'<span class="btn-box" style="'.$st_status_bg.'">'.$r->A_STATUS.'</span>';
  176. echo' <em style="color:#666;" title="'.$r->M_DIST_TYPE.'">'.((strlen($r->M_DIST_TYPE) > 5)? substr($r->M_DIST_TYPE, 0, 5).'...' : $r->M_DIST_TYPE).'</em>';
  177. echo' <i style="color:red">'.$r->M_DIST_DESC.'</i>';
  178. echo' <span>'.$r->M_DISTRIBUTOR.'</span>';
  179. echo' <font size="-1">'.$r->M_DIST_INVENTOR.'</font>';
  180. echo'</span>';
  181. $htmlTreeId = $tree->get_param('htmlTreeId');
  182. echo ' <button class="btn btn-mini btn-link" onclick="' . "return {$htmlTreeId}_ids(this, {$r->ID});" . '">IDS</button>';
  183. echo'</dt>';
  184. echo'</dl>'."\n";
  185. }
  186. {// tree filter
  187. $tbl = $tblName;
  188. $tree_filter = new Filter($_GET, $tbl, 'session');
  189. if ($tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') {
  190. { // filtr_status
  191. $filtr = array();
  192. $filtr['WSZYSTKIE'] = 'WSZYSTKIE';
  193. $filtr['WAITING'] = 'WAITING';
  194. $filtr['NORMAL'] = 'NORMAL';
  195. // TODO: add js search without page reload, add #TREE{ID}
  196. $tree_filter->add_filter('filtr_status', $filtr, 'WSZYSTKIE', 'Status');
  197. }
  198. {// filtr_id
  199. $filtr = array('search');
  200. $tree_filter->add_filter('filtr_id', $filtr, '', 'Filtruj ID');
  201. }
  202. { // filtr_search_id
  203. $filtr = array('search');
  204. // TODO: add js search without page reload, add #TREE{ID}
  205. $tree_filter->add_filter('filtr_search_id', $filtr, '', 'Wyszukaj ID');
  206. }
  207. { // filtr_ids
  208. $filtr = array();
  209. $filtr['SHOW'] = '0';
  210. $filtr['HIDE'] = '1';
  211. $tree_filter->add_filter('filtr_ids', $filtr, 'HIDE', 'IDS');
  212. }
  213. }
  214. }// tree filter
  215. $tree_filter->_save_args();
  216. session_write_close();// End the current session and store session data. Below $_SESSION is read-only.
  217. $htmlTreeId = "tree" . md5(time());
  218. echo '<div id="' . $htmlTreeId . '">';
  219. if(0){// RMME
  220. echo'<div class="filters">';
  221. echo'<form action="'."".'" method="get" onsubmit="return false;" id="' . $htmlTreeId . '_filters" style="margin:0;padding:0;">';
  222. //echo'<input type="hidden" name="'."FUNCTION_INIT".'" value="'."TREEJS".'" />';
  223. echo'<input type="hidden" name="'."MENU_INIT".'" value="'."TREEJS".'" />';
  224. echo'<input type="hidden" name="'."ZASOB_ID".'" value="'."{$zasobID}".'" />';
  225. //$tree_filter->show_filters(array('submit_function'=>$htmlTreeId . '_filters(this)'));
  226. echo'</form>';
  227. echo'</div>';
  228. }
  229. ?>
  230. <div class="filters">
  231. <form action="" method="get" onsubmit="return false;" id="<?php echo "{$htmlTreeId}_filters"; ?>" style="margin:0;padding:0;">
  232. <input type="hidden" name="MENU_INIT" value="TREEJS">
  233. <input type="hidden" name="ZASOB_ID" value="636">
  234. <nobr style="float:right;margin:-9999px 0 0 -9999px;">
  235. <input type="submit" value="submit">
  236. </nobr>
  237. <nobr> Status
  238. <select name="filtr_status" onchange="<?php echo "{$htmlTreeId}_filters(this);"; ?>">
  239. <option value="WSZYSTKIE">WSZYSTKIE</option>
  240. <option value="WAITING">WAITING .. NORMAL</option>
  241. <option value="NORMAL">NORMAL</option>
  242. </select>
  243. </nobr>
  244. <div class="btnseparator"></div>
  245. <nobr>Filtruj ID
  246. <input type="text" name="filtr_id" value="" class="i" size="4" onchange="<?php echo "return {$htmlTreeId}_filters(this);"; ?>">
  247. <input type="image" src="icon/search.png" ale="Szukaj" title="Szukaj" onclick="<?php echo "return {$htmlTreeId}_filters(this);"; ?>">
  248. </nobr>
  249. <div class="btnseparator"></div>
  250. <nobr>
  251. <input type="hidden" name="filtr_clear" value="0">
  252. <input type="reset" value="Wyczyść filtr" onclick="<?php echo "{$htmlTreeId}_filters(this, {clear:true});"; ?>">
  253. </nobr>
  254. </form>
  255. </div>
  256. <?php
  257. if ($TEST_TREE_LAZY_LOAD) {
  258. $dbgExecTime->log('start-lazy-load');
  259. $items = array();
  260. $db = DB::getDB();
  261. $sql = "select p.ID, p.P_ID
  262. , p.`A_STATUS`
  263. , p.`M_DIST_TYPE`
  264. , p.`M_DIST_DESC`
  265. , p.`M_DISTRIBUTOR`
  266. , p.`M_DIST_INVENTOR`
  267. from `{$tblName}` as p
  268. where
  269. p.P_ID!='-1' and p.P_ID!=''
  270. ";
  271. $res = $db->query($sql);
  272. $dbgExecTime->log('lazy-execute-sql', array('lazy-load'));
  273. while ($r = $db->fetch($res)) {
  274. $r->sub = array();
  275. $r->P_ID = trim($r->P_ID);
  276. $r->P_ID = str_replace(' ', ',', $r->P_ID);
  277. $v_parents = array();
  278. $v_parents_test = explode(',', $r->P_ID);
  279. foreach ($v_parents_test as $v_id) {
  280. $v_id = intval(trim($v_id));
  281. if ($v_id > 0) {
  282. $v_parents[] = $v_id;
  283. }
  284. }
  285. if (empty($v_parents)) {
  286. $r->P_ID = 0;
  287. } else {
  288. $r->P_ID = $v_parents;
  289. }
  290. $items[$r->ID] = $r;
  291. }
  292. $dbgExecTime->log('lazy-load-sql', array('lazy-load'));
  293. // set root for tree $pro_tree
  294. $pro_tree = array();
  295. foreach ($items as $k_id => $r) {
  296. if ($r->P_ID == 0) {
  297. $pro_tree[$r->ID] = array();
  298. $v_id = $r->P_ID;
  299. if (array_key_exists($v_id, $items)) {
  300. $items[$v_id]->sub[$r->ID] = true;
  301. }
  302. } else {// array
  303. foreach ($r->P_ID as $v_id) {
  304. if (array_key_exists($v_id, $items)) {
  305. $items[$v_id]->sub[$r->ID] = true;
  306. }
  307. }
  308. }
  309. }
  310. ksort($pro_tree);
  311. // set up has_childrens
  312. foreach ($items as $k_id => $r) {
  313. $items[$k_id]->has_childrens = !empty($r->sub);
  314. }
  315. // build tree by P_ID - array or 0
  316. function TREEJS_create_project_tree_rec($p_id, &$items) {
  317. static $rec_ind;
  318. $rec_ind++;
  319. $ret = array();
  320. if (!array_key_exists($p_id, $items)) {
  321. return false;
  322. } else {
  323. $r = $items[$p_id];
  324. if (empty($r->sub)) {
  325. return false;
  326. }
  327. foreach ($r->sub as $k_id => $v) {
  328. $ret[$k_id] = TREEJS_create_project_tree_rec($k_id, $items);
  329. }
  330. return $ret;
  331. }
  332. }
  333. //$pro_tree = TREEJS_create_project_tree_rec($pro_tree, $items);
  334. foreach ($pro_tree as $k_id => $v_childrens) {
  335. if (array_key_exists($k_id, $items)) {
  336. $pro_tree[$k_id] = TREEJS_create_project_tree_rec($k_id, $items);
  337. }
  338. }
  339. $dbgExecTime->log('end-lazy-load', array('lazy-load'));
  340. }
  341. $tree = new Tree($tblName);
  342. $tree->set_param('htmlTreeId', $htmlTreeId);
  343. $tree->setProfiler($dbgExecTime);
  344. if (($p_id_col = V::get('set_parent_id_col', '', $conf)) != '') {
  345. $tree->set_parent_id_col($p_id_col);
  346. }
  347. if (!empty($conf['params'])) {
  348. foreach ($conf['params'] as $k_param => $v_param) {
  349. $tree->set_param($k_param, $v_param);
  350. }
  351. }
  352. $tree->set_param('filtr_status', $tree_filter->get_arg('filtr_status'));
  353. $dbgExecTime->log('start-show-tree');
  354. if ($TEST_TREE_LAZY_LOAD) {
  355. $tree->show_css();
  356. $tree->show_js();
  357. echo "\n".'<div class="tree-wrap">'."\n";
  358. $tree->show_rec_by_tree($pro_tree, $items);
  359. echo '</div>'."\n";
  360. }
  361. else {
  362. if ($tree_filter->get_arg('filtr_id') != 0) {
  363. $tree->showSubTree($tree_filter->get_arg('filtr_id'));
  364. } else if ($tree_filter->get_arg('filtr_search_id') > 0) {
  365. $tree->showSearchNode($tree_filter->get_arg('filtr_search_id'));
  366. } else {
  367. $tree->show();
  368. }
  369. }
  370. $dbgExecTime->log('end-show-tree', array('show-tree'));
  371. echo '</div>';
  372. ?>
  373. <script>
  374. window['<?php echo $htmlTreeId; ?>TreeStruct'] = <?php echo json_encode($pro_tree); ?>;
  375. window['<?php echo $htmlTreeId; ?>TreeItems'] = <?php echo json_encode($items); ?>;
  376. // show/hide ids list - btn state txt
  377. var BTN_TXT_LOADING = 'IDS (loading...)',
  378. BTN_TXT_SHOW = 'IDS (pokaż)',
  379. BTN_TXT_HIDE = 'IDS (ukryj)';
  380. BTN_TXT_NO_DATA = 'IDS (brak danych)';
  381. function <?php echo $htmlTreeId; ?>_reload(fltrs) {
  382. var tree = jQuery('#<?php echo $htmlTreeId; ?>').find('.tree-wrap');
  383. if (fltrs.filtr_status) {
  384. if (-1 == _.indexOf(['NORMAL', 'WAITING'], fltrs.filtr_status)) {
  385. fltrs.filtr_status = null;
  386. }
  387. }
  388. var isFltrsActive = false;
  389. if (!_.isEmpty(fltrs.filtr_id)) isFltrsActive = true;
  390. if (fltrs.filtr_status) isFltrsActive = true;
  391. if (!isFltrsActive) {
  392. tree.find('li').removeClass('hide');
  393. return;
  394. } else {
  395. tree.find('li').addClass('hide');
  396. }
  397. var treeStruct = window['<?php echo $htmlTreeId; ?>TreeStruct'];
  398. var treeItems = window['<?php echo $htmlTreeId; ?>TreeItems'];
  399. if (fltrs.filtr_id) {
  400. var j, ids = [], idsTmp = fltrs.filtr_id.replace(' ', '').split(',');
  401. for (var i = 0; i < idsTmp.length; i++) {
  402. j = _.parseInt(idsTmp[i], 10);
  403. if (_.isNumber(j) && j > 0 && !_.isNaN(j)) {
  404. ids.push(j);
  405. }
  406. }
  407. fltrs.filtr_id = ids;
  408. }
  409. filteredIds = [];
  410. if (!_.isEmpty(fltrs.filtr_id)) {
  411. var curId, item, itemIsOk,
  412. todoStack = _.map(fltrs.filtr_id, function(num) { return num; });
  413. var limit = 1000;
  414. while (!_.isEmpty(todoStack)) {
  415. curId = todoStack.shift();
  416. if (curId in filteredIds) continue;
  417. item = (curId in treeItems)? treeItems[curId] : null;
  418. if (!item) continue;
  419. filteredIds[curId] = true;
  420. var pid = _.parseInt(item['P_ID'], 10);
  421. if (pid > 0) {
  422. todoStack.push(pid);
  423. }
  424. if (limit-- < 1) break;
  425. }
  426. var limit = 10000;
  427. todoStack = _.map(fltrs.filtr_id, function(num) { return num; });
  428. while (!_.isEmpty(todoStack)) {
  429. curId = todoStack.shift();
  430. if (curId in filteredIds && -1 == fltrs.filtr_id.indexOf(curId)) {
  431. continue;
  432. }
  433. item = (curId in treeItems)? treeItems[curId] : null;
  434. if (!item) continue;
  435. itemIsOk = false;
  436. if (fltrs.filtr_status) {
  437. if ('NORMAL' == fltrs.filtr_status) {
  438. if ('NORMAL' === item['A_STATUS']) {
  439. itemIsOk = true;
  440. }
  441. }
  442. else if ('WAITING' == fltrs.filtr_status) {
  443. if ('WAITING' === item['A_STATUS']) {
  444. itemIsOk = true;
  445. }
  446. else if ('NORMAL' === item['A_STATUS']) {
  447. itemIsOk = true;
  448. }
  449. }
  450. }
  451. else {
  452. itemIsOk = true;
  453. }
  454. filteredIds[curId] = itemIsOk;
  455. var toAdd = [];
  456. if (true === item['has_childrens']) {
  457. for (i in item['sub']) {
  458. //if (id in filteredIds) continue;
  459. //if (-1 !== toAdd.indexOf(id)) continue;
  460. //if (-1 !== todoStack.indexOf(id)) continue;
  461. toAdd.push(i);
  462. }
  463. }
  464. if (_.isEmpty(toAdd)) {
  465. continue;
  466. }
  467. todoStack = _.union(todoStack, toAdd);
  468. if (limit-- < 1) break;
  469. }
  470. }
  471. if (_.isEmpty(fltrs.filtr_id)) {
  472. if (fltrs.filtr_status) {
  473. var item, itemIsOk;
  474. for (var curId in treeItems) {
  475. item = treeItems[curId];
  476. if (item) {
  477. itemIsOk = false;
  478. if ('NORMAL' === item['A_STATUS']) {
  479. itemIsOk = true;
  480. }
  481. if ('WAITING' == fltrs.filtr_status) {
  482. if ('WAITING' === item['A_STATUS']) {
  483. itemIsOk = true;
  484. }
  485. }
  486. filteredIds[curId] = itemIsOk;
  487. }
  488. }
  489. }
  490. }
  491. for (var i in filteredIds) {
  492. if (filteredIds[i]) {
  493. jQuery('#TREE' + i)
  494. .removeClass('hide')
  495. .removeClass('tree-close');
  496. }
  497. }
  498. }
  499. function <?php echo $htmlTreeId; ?>_filters(el, params) {
  500. if (!el || !el.form) return false;
  501. var params = params || {};
  502. if (params.clear) {
  503. <?php echo $htmlTreeId; ?>_reload({});
  504. return;
  505. }
  506. var frm = el.form;
  507. var fltrs = {};
  508. if (frm['filtr_status'] && frm['filtr_status'].value) {
  509. fltrs['filtr_status'] = frm['filtr_status'].value;
  510. }
  511. if (frm['filtr_id'] && frm['filtr_id'].value) {
  512. fltrs['filtr_id'] = frm['filtr_id'].value;
  513. }
  514. <?php echo $htmlTreeId; ?>_reload(fltrs);
  515. return false;
  516. }
  517. function <?php echo $htmlTreeId; ?>_setIds(btnNode, id, idsList) {
  518. var idsList = idsList || [];
  519. var ddNode = btnNode.parentNode.nextSibling;
  520. if (!ddNode) {
  521. ddNode = document.createElement('dd');
  522. btnNode.parentNode.parentNode.insertBefore(ddNode, btnNode.parentNode.nextSibling);
  523. }
  524. if (_.isEmpty(idsList)) {
  525. btnNode.innerHTML = BTN_TXT_NO_DATA;
  526. ddNode.innerHTML = '';
  527. return;
  528. }
  529. var ulNode = document.createElement('ul');
  530. _.each(idsList, function(item) {
  531. var liNode = document.createElement('li');
  532. var pNode = document.createElement('p');
  533. if (!_.isEmpty(item.table)) {
  534. var spanNode = document.createElement('span');
  535. spanNode.className = 'btn-box btn-box-silver';
  536. spanNode.appendChild(document.createTextNode(item.table));
  537. pNode.appendChild(spanNode);
  538. }
  539. var bNode = document.createElement('b');
  540. bNode.appendChild(document.createTextNode(item.name));
  541. pNode.appendChild(bNode);
  542. liNode.appendChild(pNode);
  543. ulNode.appendChild(liNode);
  544. })
  545. if (ulNode.lastChild) {
  546. ulNode.lastChild.className = 'tree-last';
  547. }
  548. btnNode.innerHTML = BTN_TXT_HIDE;
  549. ddNode.innerHTML = '';
  550. ddNode.appendChild(ulNode);
  551. }
  552. function <?php echo $htmlTreeId; ?>_ids(btnNode, id) {
  553. var item = (id in window['<?php echo $htmlTreeId; ?>TreeItems'])? window['<?php echo $htmlTreeId; ?>TreeItems'][id] : null;
  554. if (!item) return;
  555. if (null == btnNode.parentNode.nextSibling) {
  556. var ddNode = document.createElement('dd');
  557. btnNode.parentNode.parentNode.insertBefore(ddNode, btnNode.parentNode.nextSibling);
  558. }
  559. if (BTN_TXT_HIDE === btnNode.innerHTML) {
  560. btnNode.innerHTML = BTN_TXT_SHOW;
  561. btnNode.parentNode.nextSibling.className='hide';
  562. } else if (BTN_TXT_SHOW === btnNode.innerHTML) {
  563. btnNode.innerHTML = BTN_TXT_HIDE;
  564. btnNode.parentNode.nextSibling.className='';
  565. } else if (BTN_TXT_LOADING === btnNode.innerHTML) {
  566. } else if (BTN_TXT_NO_DATA === btnNode.innerHTML) {
  567. } else {// INIT is default state
  568. btnNode.innerHTML = BTN_TXT_LOADING;
  569. superagent
  570. .get('index.php')
  571. .query({FUNCTION_INIT: '<?php echo __FUNCTION__; ?>'})
  572. .query({ZASOB_ID: '<?php echo V::get('ZASOB_ID', 0, $_GET, 'int'); ?>'})
  573. .query({HEADER_NOT_INIT: 'YES'})
  574. .query({_ajaxTask: 'idsList'})
  575. .query({id: id})
  576. .end(function(error, res) {
  577. if (res.ok && 'ids' in res.body) {
  578. <?php echo $htmlTreeId; ?>_setIds(btnNode, id, res.body.ids);
  579. } else {
  580. <?php echo $htmlTreeId; ?>_setIds(btnNode, id, {ids: []});
  581. }
  582. });
  583. }
  584. return false;
  585. }
  586. </script>
  587. <?php
  588. if($DBG_TIME){
  589. $dbgExecTime->log('end');
  590. $dbgExecTime->printDebug();
  591. }
  592. }