superedit-TREEJS.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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. $out_id = ($r->ID < 10)? '&nbsp;'.$r->ID.'' : $r->ID;
  149. $htmlTreeId = $tree->get_param('htmlTreeId');
  150. $idLink = "index.php?MENU_INIT=TREEJS&ZASOB_ID={$zasobID}&filtr_id={$r->ID}#TREE{$r->ID}";
  151. $editLink = "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobID}#EDIT/{$r->ID}";
  152. //if ($r->has_childrens) {
  153. // if (!$tree->get_param('rozwin')) {
  154. // $js = "return " . $tree->js_tree_open_rec_fun . "(this," . $r->ID . ");";
  155. // echo'<a href="'."#".'" title="'."Rozwin wszystko".'" onclick="'.$js.'" class="btn open-rec">'."L".'</a>';
  156. // }
  157. //}
  158. // TODO: edycja nie działa - bierze ostatni edytowany rekord
  159. //echo' <a href="'."?FUNCTION_INIT=IN7_MK_BAZA_DYSTRYBUCJI_EDIT&ARG1=EDIT&ARG1_VAL={$r->ID}".'" class="btn-box">'."E".'</a>';
  160. $st_status_bg = '';
  161. if ($r->A_STATUS == 'NORMAL') {
  162. $st_status_bg = '#8F8;';
  163. } else if ($r->A_STATUS == 'WAITING') {
  164. $st_status_bg = '#F8F;';
  165. } else if ($r->A_STATUS == 'DELETED') {
  166. $st_status_bg = '#ccc;';
  167. } else if ($r->A_STATUS == 'OFF_SOFT') {
  168. $st_status_bg = '#F99;';
  169. } else if ($r->A_STATUS == 'OFF_HARD') {
  170. $st_status_bg = '#eee;';
  171. }
  172. $st_status_bg = ($st_status_bg)? 'background-color:'.$st_status_bg : '';
  173. ?>
  174. <dl<?php echo $cls; ?>>
  175. <dt>
  176. <a href="<?php echo $idLink; ?>"
  177. onClick="return <?php echo $htmlTreeId; ?>_filtr_id(<?php echo $r->ID; ?>);"
  178. class="item_id btn-box"><?php echo $out_id; ?></a>
  179. <a href="<?php echo $editLink; ?>"
  180. title="Edit"
  181. class="btn btn-xs btn-link">E</a>
  182. <span class="desc">
  183. <span class="btn-box" style="<?php echo $st_status_bg; ?>"><?php echo $r->A_STATUS; ?></span>
  184. <em title="<?php echo $r->M_DIST_TYPE; ?>"
  185. style="color:#666;"><?php echo V::strShortUtf8($r->M_DIST_TYPE, 5); ?></em>
  186. <i style="color:red"><?php echo $r->M_DIST_DESC; ?></i>
  187. <span><?php echo $r->M_DISTRIBUTOR; ?></span>
  188. <font size="-1"><?php echo $r->M_DIST_INVENTOR; ?></font>
  189. </span>
  190. <button onclick="return <?php echo $htmlTreeId; ?>_ids(this, <?php echo $r->ID; ?>);"
  191. class="btn btn-xs btn-link">IDS</button>
  192. </dt>
  193. </dl>
  194. <?php
  195. }
  196. {// tree filter
  197. $tbl = $tblName;
  198. $tree_filter = new Filter($_GET, $tbl, 'session');
  199. if ($tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') {
  200. { // filtr_status
  201. $filtr = array();
  202. $filtr['WSZYSTKIE'] = 'WSZYSTKIE';
  203. $filtr['WAITING'] = 'WAITING';
  204. $filtr['NORMAL'] = 'NORMAL';
  205. // TODO: add js search without page reload, add #TREE{ID}
  206. $tree_filter->add_filter('filtr_status', $filtr, 'WSZYSTKIE', 'Status');
  207. }
  208. {// filtr_id
  209. $filtr = array('search');
  210. $tree_filter->add_filter('filtr_id', $filtr, '', 'Filtruj ID');
  211. }
  212. { // filtr_search_id
  213. $filtr = array('search');
  214. // TODO: add js search without page reload, add #TREE{ID}
  215. $tree_filter->add_filter('filtr_search_id', $filtr, '', 'Wyszukaj ID');
  216. }
  217. { // filtr_ids
  218. $filtr = array();
  219. $filtr['SHOW'] = '0';
  220. $filtr['HIDE'] = '1';
  221. $tree_filter->add_filter('filtr_ids', $filtr, 'HIDE', 'IDS');
  222. }
  223. }
  224. }// tree filter
  225. $tree_filter->_save_args();
  226. session_write_close();// End the current session and store session data. Below $_SESSION is read-only.
  227. $htmlTreeId = "tree" . md5(time());
  228. echo '<div id="' . $htmlTreeId . '">';
  229. if(0){// RMME
  230. echo'<div class="filters">';
  231. echo'<form action="'."".'" method="get" onsubmit="return false;" id="' . $htmlTreeId . '_filters" style="margin:0;padding:0;">';
  232. //echo'<input type="hidden" name="'."FUNCTION_INIT".'" value="'."TREEJS".'" />';
  233. echo'<input type="hidden" name="'."MENU_INIT".'" value="'."TREEJS".'" />';
  234. echo'<input type="hidden" name="'."ZASOB_ID".'" value="'."{$zasobID}".'" />';
  235. //$tree_filter->show_filters(array('submit_function'=>$htmlTreeId . '_filters(this)'));
  236. echo'</form>';
  237. echo'</div>';
  238. }
  239. ?>
  240. <div class="filters">
  241. <form action="" method="get" onsubmit="return false;" id="<?php echo "{$htmlTreeId}_filters"; ?>" style="margin:0;padding:0;">
  242. <input type="hidden" name="MENU_INIT" value="TREEJS">
  243. <input type="hidden" name="ZASOB_ID" value="636">
  244. <nobr style="float:right;margin:-9999px 0 0 -9999px;">
  245. <input type="submit" value="submit">
  246. </nobr>
  247. <nobr> Status
  248. <select name="filtr_status" onchange="<?php echo "{$htmlTreeId}_filters(this);"; ?>">
  249. <option value="WSZYSTKIE">WSZYSTKIE</option>
  250. <option value="WAITING">WAITING .. NORMAL</option>
  251. <option value="NORMAL">NORMAL</option>
  252. </select>
  253. </nobr>
  254. <div class="btnseparator"></div>
  255. <nobr>Filtruj ID
  256. <input type="text" id="<?php echo "{$htmlTreeId}_filters_filtr_id"; ?>" name="filtr_id" value="" class="i" size="4" onchange="<?php echo "return {$htmlTreeId}_filters(this);"; ?>">
  257. <input type="image" src="icon/search.png" ale="Szukaj" title="Szukaj" onclick="<?php echo "return {$htmlTreeId}_filters(this);"; ?>">
  258. </nobr>
  259. <div class="btnseparator"></div>
  260. <nobr>
  261. <input type="hidden" name="filtr_clear" value="0">
  262. <input type="reset" value="Wyczyść filtr" onclick="<?php echo "{$htmlTreeId}_filters(this, {clear:true});"; ?>">
  263. </nobr>
  264. </form>
  265. </div>
  266. <?php
  267. if ($TEST_TREE_LAZY_LOAD) {
  268. $dbgExecTime->log('start-lazy-load');
  269. $items = array();
  270. $db = DB::getDB();
  271. $sql = "select p.ID, p.P_ID
  272. , p.`A_STATUS`
  273. , p.`M_DIST_TYPE`
  274. , p.`M_DIST_DESC`
  275. , p.`M_DISTRIBUTOR`
  276. , p.`M_DIST_INVENTOR`
  277. from `{$tblName}` as p
  278. where
  279. p.P_ID!='-1'
  280. -- and p.P_ID!=''
  281. and p.P_ID>=0
  282. ";
  283. $res = $db->query($sql);
  284. $dbgExecTime->log('lazy-execute-sql', array('lazy-load'));
  285. while ($r = $db->fetch($res)) {
  286. $r->sub = array();
  287. $r->P_ID = trim($r->P_ID);
  288. $r->P_ID = str_replace(' ', ',', $r->P_ID);
  289. $v_parents = array();
  290. $v_parents_test = explode(',', $r->P_ID);
  291. foreach ($v_parents_test as $v_id) {
  292. $v_id = intval(trim($v_id));
  293. if ($v_id > 0) {
  294. $v_parents[] = $v_id;
  295. }
  296. }
  297. if (empty($v_parents)) {
  298. $r->P_ID = 0;
  299. } else {
  300. $r->P_ID = $v_parents;
  301. }
  302. $items[$r->ID] = $r;
  303. }
  304. $dbgExecTime->log('lazy-load-sql', array('lazy-load'));
  305. // set root for tree $pro_tree
  306. $pro_tree = array();
  307. foreach ($items as $k_id => $r) {
  308. if ($r->P_ID == 0) {
  309. $pro_tree[$r->ID] = array();
  310. $v_id = $r->P_ID;
  311. if (array_key_exists($v_id, $items)) {
  312. $items[$v_id]->sub[$r->ID] = true;
  313. }
  314. } else {// array
  315. foreach ($r->P_ID as $v_id) {
  316. if (array_key_exists($v_id, $items)) {
  317. $items[$v_id]->sub[$r->ID] = true;
  318. }
  319. }
  320. }
  321. }
  322. ksort($pro_tree);
  323. // set up has_childrens
  324. foreach ($items as $k_id => $r) {
  325. $items[$k_id]->has_childrens = !empty($r->sub);
  326. }
  327. // build tree by P_ID - array or 0
  328. function TREEJS_create_project_tree_rec($p_id, &$items) {
  329. static $rec_ind;
  330. $rec_ind++;
  331. $ret = array();
  332. if (!array_key_exists($p_id, $items)) {
  333. return false;
  334. } else {
  335. $r = $items[$p_id];
  336. if (empty($r->sub)) {
  337. return false;
  338. }
  339. foreach ($r->sub as $k_id => $v) {
  340. $ret[$k_id] = TREEJS_create_project_tree_rec($k_id, $items);
  341. }
  342. return $ret;
  343. }
  344. }
  345. //$pro_tree = TREEJS_create_project_tree_rec($pro_tree, $items);
  346. foreach ($pro_tree as $k_id => $v_childrens) {
  347. if (array_key_exists($k_id, $items)) {
  348. $pro_tree[$k_id] = TREEJS_create_project_tree_rec($k_id, $items);
  349. }
  350. }
  351. $dbgExecTime->log('end-lazy-load', array('lazy-load'));
  352. }
  353. $tree = new Tree($tblName);
  354. $tree->set_param('htmlTreeId', $htmlTreeId);
  355. $tree->setProfiler($dbgExecTime);
  356. if (($p_id_col = V::get('set_parent_id_col', '', $conf)) != '') {
  357. $tree->set_parent_id_col($p_id_col);
  358. }
  359. if (!empty($conf['params'])) {
  360. foreach ($conf['params'] as $k_param => $v_param) {
  361. $tree->set_param($k_param, $v_param);
  362. }
  363. }
  364. $tree->set_param('filtr_status', $tree_filter->get_arg('filtr_status'));
  365. $dbgExecTime->log('start-show-tree');
  366. if ($TEST_TREE_LAZY_LOAD) {
  367. $tree->show_css();
  368. $tree->show_js();
  369. echo "\n".'<div class="tree-wrap">'."\n";
  370. $tree->show_rec_by_tree($pro_tree, $items);
  371. echo '</div>'."\n";
  372. }
  373. else {
  374. if ($tree_filter->get_arg('filtr_id') != 0) {
  375. $tree->showSubTree($tree_filter->get_arg('filtr_id'));
  376. } else if ($tree_filter->get_arg('filtr_search_id') > 0) {
  377. $tree->showSearchNode($tree_filter->get_arg('filtr_search_id'));
  378. } else {
  379. $tree->show();
  380. }
  381. }
  382. $dbgExecTime->log('end-show-tree', array('show-tree'));
  383. echo '</div>';
  384. ?>
  385. <script>
  386. window['<?php echo $htmlTreeId; ?>TreeStruct'] = <?php echo json_encode($pro_tree); ?>;
  387. window['<?php echo $htmlTreeId; ?>TreeItems'] = <?php echo json_encode($items); ?>;
  388. // show/hide ids list - btn state txt
  389. var BTN_TXT_LOADING = 'IDS (loading...)',
  390. BTN_TXT_SHOW = 'IDS (pokaż)',
  391. BTN_TXT_HIDE = 'IDS (ukryj)';
  392. BTN_TXT_NO_DATA = 'IDS (brak danych)';
  393. function <?php echo $htmlTreeId; ?>_reload(fltrs) {
  394. var tree = jQuery('#<?php echo $htmlTreeId; ?>').find('.tree-wrap');
  395. if (fltrs.filtr_status) {
  396. if (-1 == _.indexOf(['NORMAL', 'WAITING'], fltrs.filtr_status)) {
  397. fltrs.filtr_status = null;
  398. }
  399. }
  400. var isFltrsActive = false;
  401. if (!_.isEmpty(fltrs.filtr_id)) isFltrsActive = true;
  402. if (fltrs.filtr_status) isFltrsActive = true;
  403. if (!isFltrsActive) {
  404. tree.find('li').removeClass('hide');
  405. return;
  406. } else {
  407. tree.find('li').addClass('hide');
  408. }
  409. var treeStruct = window['<?php echo $htmlTreeId; ?>TreeStruct'];
  410. var treeItems = window['<?php echo $htmlTreeId; ?>TreeItems'];
  411. if (fltrs.filtr_id) {
  412. var j, ids = [], idsTmp = fltrs.filtr_id.replace(' ', '').split(',');
  413. for (var i = 0; i < idsTmp.length; i++) {
  414. j = _.parseInt(idsTmp[i], 10);
  415. if (_.isNumber(j) && j > 0 && !_.isNaN(j)) {
  416. ids.push(j);
  417. }
  418. }
  419. fltrs.filtr_id = ids;
  420. }
  421. filteredIds = [];
  422. if (!_.isEmpty(fltrs.filtr_id)) {
  423. var curId, item, itemIsOk,
  424. todoStack = _.map(fltrs.filtr_id, function(num) { return num; });
  425. var limit = 1000;
  426. while (!_.isEmpty(todoStack)) {
  427. curId = todoStack.shift();
  428. if (curId in filteredIds) continue;
  429. item = (curId in treeItems)? treeItems[curId] : null;
  430. if (!item) continue;
  431. filteredIds[curId] = true;
  432. var pid = _.parseInt(item['P_ID'], 10);
  433. if (pid > 0) {
  434. todoStack.push(pid);
  435. }
  436. if (limit-- < 1) break;
  437. }
  438. var limit = 10000;
  439. todoStack = _.map(fltrs.filtr_id, function(num) { return num; });
  440. while (!_.isEmpty(todoStack)) {
  441. curId = todoStack.shift();
  442. if (curId in filteredIds && -1 == fltrs.filtr_id.indexOf(curId)) {
  443. continue;
  444. }
  445. item = (curId in treeItems)? treeItems[curId] : null;
  446. if (!item) continue;
  447. itemIsOk = false;
  448. if (fltrs.filtr_status) {
  449. if ('NORMAL' == fltrs.filtr_status) {
  450. if ('NORMAL' === item['A_STATUS']) {
  451. itemIsOk = true;
  452. }
  453. }
  454. else if ('WAITING' == fltrs.filtr_status) {
  455. if ('WAITING' === item['A_STATUS']) {
  456. itemIsOk = true;
  457. }
  458. else if ('NORMAL' === item['A_STATUS']) {
  459. itemIsOk = true;
  460. }
  461. }
  462. }
  463. else {
  464. itemIsOk = true;
  465. }
  466. filteredIds[curId] = itemIsOk;
  467. var toAdd = [];
  468. if (true === item['has_childrens']) {
  469. for (i in item['sub']) {
  470. //if (id in filteredIds) continue;
  471. //if (-1 !== toAdd.indexOf(id)) continue;
  472. //if (-1 !== todoStack.indexOf(id)) continue;
  473. toAdd.push(i);
  474. }
  475. }
  476. if (_.isEmpty(toAdd)) {
  477. continue;
  478. }
  479. todoStack = _.union(todoStack, toAdd);
  480. if (limit-- < 1) break;
  481. }
  482. }
  483. if (_.isEmpty(fltrs.filtr_id)) {
  484. if (fltrs.filtr_status) {
  485. var item, itemIsOk;
  486. for (var curId in treeItems) {
  487. item = treeItems[curId];
  488. if (item) {
  489. itemIsOk = false;
  490. if ('NORMAL' === item['A_STATUS']) {
  491. itemIsOk = true;
  492. }
  493. if ('WAITING' == fltrs.filtr_status) {
  494. if ('WAITING' === item['A_STATUS']) {
  495. itemIsOk = true;
  496. }
  497. }
  498. filteredIds[curId] = itemIsOk;
  499. }
  500. }
  501. }
  502. }
  503. for (var i in filteredIds) {
  504. if (filteredIds[i]) {
  505. jQuery('#TREE' + i)
  506. .removeClass('hide')
  507. .removeClass('tree-close');
  508. }
  509. }
  510. }
  511. function <?php echo $htmlTreeId; ?>_filters(el, params) {
  512. if (!el || !el.form) return false;
  513. var params = params || {};
  514. if (params.clear) {
  515. <?php echo $htmlTreeId; ?>_reload({});
  516. return;
  517. }
  518. var frm = el.form;
  519. var fltrs = {};
  520. if (frm['filtr_status'] && frm['filtr_status'].value) {
  521. fltrs['filtr_status'] = frm['filtr_status'].value;
  522. }
  523. if (frm['filtr_id'] && frm['filtr_id'].value) {
  524. fltrs['filtr_id'] = frm['filtr_id'].value;
  525. }
  526. <?php echo $htmlTreeId; ?>_reload(fltrs);
  527. return false;
  528. }
  529. function <?php echo $htmlTreeId; ?>_setIds(btnNode, id, idsList) {
  530. var idsList = idsList || [];
  531. var ddNode = btnNode.parentNode.nextSibling;
  532. if (!ddNode || ddNode.nodeType != 1) {
  533. ddNode = document.createElement('dd');
  534. btnNode.parentNode.parentNode.insertBefore(ddNode, btnNode.parentNode.nextSibling);
  535. }
  536. if (_.isEmpty(idsList)) {
  537. btnNode.innerHTML = BTN_TXT_NO_DATA;
  538. ddNode.innerHTML = '';
  539. return;
  540. }
  541. var ulNode = document.createElement('ul');
  542. _.each(idsList, function(item) {
  543. var liNode = document.createElement('li');
  544. var pNode = document.createElement('p');
  545. if (!_.isEmpty(item.table)) {
  546. var spanNode = document.createElement('span');
  547. spanNode.className = 'btn-box btn-box-silver';
  548. spanNode.appendChild(document.createTextNode(item.table));
  549. pNode.appendChild(spanNode);
  550. }
  551. var bNode = document.createElement('b');
  552. bNode.appendChild(document.createTextNode(item.name));
  553. pNode.appendChild(bNode);
  554. liNode.appendChild(pNode);
  555. ulNode.appendChild(liNode);
  556. })
  557. if (ulNode.lastChild) {
  558. ulNode.lastChild.className = 'tree-last';
  559. }
  560. btnNode.innerHTML = BTN_TXT_HIDE;
  561. ddNode.innerHTML = '';
  562. ddNode.appendChild(ulNode);
  563. }
  564. function <?php echo $htmlTreeId; ?>_ids(btnNode, id) {
  565. var item = (id in window['<?php echo $htmlTreeId; ?>TreeItems'])? window['<?php echo $htmlTreeId; ?>TreeItems'][id] : null;
  566. if (!item) return;
  567. if (null == btnNode.parentNode.nextSibling) {
  568. var ddNode = document.createElement('dd');
  569. btnNode.parentNode.parentNode.insertBefore(ddNode, btnNode.parentNode.nextSibling);
  570. }
  571. if (BTN_TXT_HIDE === btnNode.innerHTML) {
  572. btnNode.innerHTML = BTN_TXT_SHOW;
  573. btnNode.parentNode.nextSibling.className='hide';
  574. } else if (BTN_TXT_SHOW === btnNode.innerHTML) {
  575. btnNode.innerHTML = BTN_TXT_HIDE;
  576. btnNode.parentNode.nextSibling.className='';
  577. } else if (BTN_TXT_LOADING === btnNode.innerHTML) {
  578. } else if (BTN_TXT_NO_DATA === btnNode.innerHTML) {
  579. } else {// INIT is default state
  580. btnNode.innerHTML = BTN_TXT_LOADING;
  581. superagent
  582. .get('index.php')
  583. .query({FUNCTION_INIT: '<?php echo __FUNCTION__; ?>'})
  584. .query({ZASOB_ID: '<?php echo V::get('ZASOB_ID', 0, $_GET, 'int'); ?>'})
  585. .query({HEADER_NOT_INIT: 'YES'})
  586. .query({_ajaxTask: 'idsList'})
  587. .query({id: id})
  588. .end(function(error, res) {
  589. if (res.ok && 'ids' in res.body) {
  590. <?php echo $htmlTreeId; ?>_setIds(btnNode, id, res.body.ids);
  591. } else {
  592. <?php echo $htmlTreeId; ?>_setIds(btnNode, id, {ids: []});
  593. }
  594. });
  595. }
  596. return false;
  597. }
  598. function <?php echo $htmlTreeId; ?>_filtr_id(id) {
  599. if (id > 0) {
  600. var filtrIdNode = jQuery('#<?php echo "{$htmlTreeId}_filters_filtr_id"; ?>').get(0);
  601. if (!filtrIdNode) return;
  602. filtrIdNode.value = id;
  603. <?php echo $htmlTreeId; ?>_filters(filtrIdNode);
  604. return false;
  605. }
  606. }
  607. <?php if ($tree_filter->get_arg('filtr_id') > 0) : ?>
  608. jQuery(document).ready(function() {
  609. <?php echo $htmlTreeId; ?>_filtr_id(<?php echo $tree_filter->get_arg('filtr_id'); ?>);
  610. });
  611. <?php endif; ?>
  612. </script>
  613. <?php
  614. if($DBG_TIME){
  615. $dbgExecTime->log('end');
  616. $dbgExecTime->printDebug();
  617. }
  618. }