| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- <?php
- Lib::loadClass('ProcesHelper');
- Lib::loadClass('DebugExecutionTime');
- Lib::loadClass('Tree');
- Lib::loadClass('TreeHelper');
- Lib::loadClass('App');
- Lib::loadClass('Filter');
- function TREEJS__ajaxTask__idsList($args) {
- $zasobID = V::get('ZASOB_ID', 0, $args, 'int');
- if ($zasobID <= 0) {
- throw new HttpException("Wrong param ZASOB_ID", 400);
- }
- $id = V::get('id', 0, $args, 'int');
- if ($id <= 0) {
- throw new HttpException("Wrong param id", 400);
- }
- $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
- if (!$zasobObj) {
- throw new HttpException("Zasob TABELA ID={$zasobID} nie istnieje", 404);
- }
- $tblName = $zasobObj->DESC;
- $db = DB::getDB();
- $r = $db->get_by_id($tblName, $id);
- if (!$r) {
- throw new HttpException("Rekord ID={$id} nie istnieje", 404);
- }
- $wsk = array();
- $ids_conf_arr = array();
- $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");
- $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");
- if (!empty($ids_conf_arr)) {
- $external_ids = array();
- foreach ($ids_conf_arr as $k_table_name => $v_cnf) {
- $cur_cnf = new stdClass();
- $cur_cnf->id_col = V::get('id_col', 'ID', $v_cnf);
- $cur_cnf->search_col = V::get('search_col', 'ID_PROJECT', $v_cnf);
- $cur_cnf->search_col_regex = V::get('search_col_regex', '', $v_cnf);
- $sql_id_col = $cur_cnf->id_col;
- $sql_where = "";
- if ($cur_cnf->search_col_regex) {
- $sql_where = "`{$cur_cnf->search_col}` like '".str_replace('$ID', $r->ID, $cur_cnf->search_col_regex)."'";
- } else {
- $sql_where = "`{$cur_cnf->search_col}`='{$r->ID}'";
- }
- $db = DB::getDB();
- $sql = "select t.`{$sql_id_col}`
- from `{$k_table_name}` as t
- where {$sql_where}
- ";
- $res = $db->query($sql);
- while ($r_wsk = $db->fetch($res)) {
- $wsk[] = (object)array('name'=>$r_wsk->$sql_id_col, 'table'=>$k_table_name);
- }
- }
- }
- $response = new stdClass();
- $response->ids = $wsk;
- return $response;
- }
- function TREEJS() {
- global $result,$thiss;
- $ajaxTask = V::get('_ajaxTask', '', $_GET);
- $funName = "TREEJS__ajaxTask__{$ajaxTask}";
- if (function_exists($funName)) {
- try {
- $response = $funName($_GET);
- }
- catch (HttpException $e) {
- $response = new stdClass();
- $response->type = 'error';
- $response->msg = $e->getMessage();
- $response->errorCode = $e->getCode();
- Http::sendHeaderByCode($e->getCode());
- }
- catch (Exception $e) {
- $response = new stdClass();
- $response->type = 'error';
- $response->msg = $e->getMessage();
- $response->errorCode = $e->getCode();
- }
- header('Content-type: application/json');
- if (!$response) $response = new stdClass();
- echo json_encode($response);
- exit;
- }
- $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int');
- if ($zasobID <= 0) {
- echo 'Wrong param ZASOB_ID';
- return;
- }
- $TEST_TREE_LAZY_LOAD = 1;
- $DBG_TIME = ('1' == V::get('DBG_TIME', '', $_GET));
- $dbgExecTime = new DebugExecutionTime();
- if ($DBG_TIME) $dbgExecTime->activate();
- $dbgExecTime->log('start');
- echo "<<".'<a href="' . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobID}" . '" title="Powrot">Powrot do tabeli</a>';
- $conf = null;
- $tblName = '';
- $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
- if (!$zasobObj) {
- echo "Zasob TABELA ID={$zasobID} nie istnieje";
- return;
- }
- $tblName = $zasobObj->DESC;
- $allowed_tables_conf = array();
- $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI'] = array('set_parent_id_col'=>'P_ID');
- $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params'] = array();
- $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params']['show_item_callback'] = 'tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI';
- $allowed_tables_conf['IN7_MK_BAZA_DYSTRYBUCJI']['params']['ajax'] ='NIE';
- if (!array_key_exists($tblName, $allowed_tables_conf)) {
- echo'<p>'."Brak dostepu".'</p>';
- }
- $conf = $allowed_tables_conf[$tblName];
- echo'<style type="text/css">'."
- .btn-box{margin:0 2px 0 0;padding:0 3px;background:#bbb;color:#fff;text-decoration:none;border:0;font-weight:bold;}
- .btn-box-blue{background:#3A3AFF;color:#fff;}
- .btn-box-green{background:#008A00;color:#fff;}
- .btn-box-lgreen{background:#97CF97;color:#fff;}
- .btn-box-red{background:#FF4646;color:#fff;}
- .btn-box-group1{background-color:#9F9FCB;color:#fff;}
- .btn-box-group2{background-color:#B8B879;color:#fff;}
- /*.tree-wrap .btn{border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;}*/
- /*.btn-box{border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;}*/
- .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;}
- .filters .btnseparator{float:left;height:22px;border-left:1px solid #CCC;border-right:1px solid #fff;margin:1px;}
- .filters form{margin:0;padding:0;}
- .filters nobr{display:block;float:left;margin:0;padding:2px;font-weight:normal;font-size:13px;}
- .filters nobr:hover{text-decoration:underline;}
- .filters nobr.active{color:#f00;font-weight:normal;}
- .filters nobr input,
- .filters nobr select,
- .filters nobr button{margin:0 1px;padding:0 2px;font-size:13px;}
- .tree-wrap li.tree-close dd ul {display:block;}
- .tree-wrap li.tree-close dd ul,
- .tree-wrap dd ul { background:url(stuff/i/t-ul-green.gif) 0 0 repeat-y; }
- .tree-wrap .btn {outline:none;}
- ".'</style>'."\n";
- App::show_head_css();
- App::show_head_js();
- function tree_callback__show_item_from_IN7_MK_BAZA_DYSTRYBUCJI(&$r, &$tree) {
- $zasobID = V::get('ZASOB_ID', 0, $_GET, 'int');
- // TODO: btn-box zasob type from PARENT_ID
- $cls = array();
- if (($search_id = $tree->get_param('search_id')) > 0 && $search_id == $r->ID) {
- $cls[] = 'search_id';
- }
- $cls = (!empty($cls))? ' class="'.implode(' ', $cls).'"' : '';
- echo'<dl'.$cls.'>';
- echo'<dt>';
- $out_id = ($r->ID < 10)? ' '.$r->ID.'' : $r->ID;
- 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>';
- 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>';
- //if ($r->has_childrens) {
- // if (!$tree->get_param('rozwin')) {
- // $js = "return " . $tree->js_tree_open_rec_fun . "(this," . $r->ID . ");";
- // echo'<a href="'."#".'" title="'."Rozwin wszystko".'" onclick="'.$js.'" class="btn open-rec">'."L".'</a>';
- // }
- //}
- // TODO: edycja nie działa - bierze ostatni edytowany rekord
- //echo' <a href="'."?FUNCTION_INIT=IN7_MK_BAZA_DYSTRYBUCJI_EDIT&ARG1=EDIT&ARG1_VAL={$r->ID}".'" class="btn-box">'."E".'</a>';
- $st_status_bg = '';
- if ($r->A_STATUS == 'NORMAL') {
- $st_status_bg = '#8F8;';
- } else if ($r->A_STATUS == 'WAITING') {
- $st_status_bg = '#F8F;';
- } else if ($r->A_STATUS == 'DELETED') {
- $st_status_bg = '#ccc;';
- } else if ($r->A_STATUS == 'OFF_SOFT') {
- $st_status_bg = '#F99;';
- } else if ($r->A_STATUS == 'OFF_HARD') {
- $st_status_bg = '#eee;';
- }
- $st_status_bg = ($st_status_bg)? 'background-color:'.$st_status_bg : '';
- echo'<span class="desc">';
- echo'<span class="btn-box" style="'.$st_status_bg.'">'.$r->A_STATUS.'</span>';
- 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>';
- echo' <i style="color:red">'.$r->M_DIST_DESC.'</i>';
- echo' <span>'.$r->M_DISTRIBUTOR.'</span>';
- echo' <font size="-1">'.$r->M_DIST_INVENTOR.'</font>';
- echo'</span>';
- $htmlTreeId = $tree->get_param('htmlTreeId');
- echo ' <button class="btn btn-mini btn-link" onclick="' . "return {$htmlTreeId}_ids(this, {$r->ID});" . '">IDS</button>';
- echo'</dt>';
- echo'</dl>'."\n";
- }
- {// tree filter
- $tbl = $tblName;
- $tree_filter = new Filter($_GET, $tbl, 'session');
- if ($tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') {
- { // filtr_status
- $filtr = array();
- $filtr['WSZYSTKIE'] = 'WSZYSTKIE';
- $filtr['WAITING'] = 'WAITING';
- $filtr['NORMAL'] = 'NORMAL';
- // TODO: add js search without page reload, add #TREE{ID}
- $tree_filter->add_filter('filtr_status', $filtr, 'WSZYSTKIE', 'Status');
- }
- {// filtr_id
- $filtr = array('search');
- $tree_filter->add_filter('filtr_id', $filtr, '', 'Filtruj ID');
- }
- { // filtr_search_id
- $filtr = array('search');
- // TODO: add js search without page reload, add #TREE{ID}
- $tree_filter->add_filter('filtr_search_id', $filtr, '', 'Wyszukaj ID');
- }
- { // filtr_ids
- $filtr = array();
- $filtr['SHOW'] = '0';
- $filtr['HIDE'] = '1';
- $tree_filter->add_filter('filtr_ids', $filtr, 'HIDE', 'IDS');
- }
- }
- }// tree filter
- $tree_filter->_save_args();
- session_write_close();// End the current session and store session data. Below $_SESSION is read-only.
- $htmlTreeId = "tree" . md5(time());
- echo '<div id="' . $htmlTreeId . '">';
- if(0){// RMME
- echo'<div class="filters">';
- echo'<form action="'."".'" method="get" onsubmit="return false;" id="' . $htmlTreeId . '_filters" style="margin:0;padding:0;">';
- //echo'<input type="hidden" name="'."FUNCTION_INIT".'" value="'."TREEJS".'" />';
- echo'<input type="hidden" name="'."MENU_INIT".'" value="'."TREEJS".'" />';
- echo'<input type="hidden" name="'."ZASOB_ID".'" value="'."{$zasobID}".'" />';
- //$tree_filter->show_filters(array('submit_function'=>$htmlTreeId . '_filters(this)'));
- echo'</form>';
- echo'</div>';
- }
- ?>
- <div class="filters">
- <form action="" method="get" onsubmit="return false;" id="<?php echo "{$htmlTreeId}_filters"; ?>" style="margin:0;padding:0;">
- <input type="hidden" name="MENU_INIT" value="TREEJS">
- <input type="hidden" name="ZASOB_ID" value="636">
- <nobr style="float:right;margin:-9999px 0 0 -9999px;">
- <input type="submit" value="submit">
- </nobr>
- <nobr> Status
- <select name="filtr_status" onchange="<?php echo "{$htmlTreeId}_filters(this);"; ?>">
- <option value="WSZYSTKIE">WSZYSTKIE</option>
- <option value="WAITING">WAITING .. NORMAL</option>
- <option value="NORMAL">NORMAL</option>
- </select>
- </nobr>
- <div class="btnseparator"></div>
- <nobr>Filtruj ID
- <input type="text" name="filtr_id" value="" class="i" size="4" onchange="<?php echo "return {$htmlTreeId}_filters(this);"; ?>">
- <input type="image" src="icon/search.png" ale="Szukaj" title="Szukaj" onclick="<?php echo "return {$htmlTreeId}_filters(this);"; ?>">
- </nobr>
- <div class="btnseparator"></div>
- <nobr>
- <input type="hidden" name="filtr_clear" value="0">
- <input type="reset" value="Wyczyść filtr" onclick="<?php echo "{$htmlTreeId}_filters(this, {clear:true});"; ?>">
- </nobr>
- </form>
- </div>
- <?php
- if ($TEST_TREE_LAZY_LOAD) {
- $dbgExecTime->log('start-lazy-load');
- $items = array();
- $db = DB::getDB();
- $sql = "select p.ID, p.P_ID
- , p.`A_STATUS`
- , p.`M_DIST_TYPE`
- , p.`M_DIST_DESC`
- , p.`M_DISTRIBUTOR`
- , p.`M_DIST_INVENTOR`
- from `{$tblName}` as p
- where
- p.P_ID!='-1' and p.P_ID!=''
- ";
- $res = $db->query($sql);
- $dbgExecTime->log('lazy-execute-sql', array('lazy-load'));
- while ($r = $db->fetch($res)) {
- $r->sub = array();
- $r->P_ID = trim($r->P_ID);
- $r->P_ID = str_replace(' ', ',', $r->P_ID);
- $v_parents = array();
- $v_parents_test = explode(',', $r->P_ID);
- foreach ($v_parents_test as $v_id) {
- $v_id = intval(trim($v_id));
- if ($v_id > 0) {
- $v_parents[] = $v_id;
- }
- }
- if (empty($v_parents)) {
- $r->P_ID = 0;
- } else {
- $r->P_ID = $v_parents;
- }
- $items[$r->ID] = $r;
- }
- $dbgExecTime->log('lazy-load-sql', array('lazy-load'));
- // set root for tree $pro_tree
- $pro_tree = array();
- foreach ($items as $k_id => $r) {
- if ($r->P_ID == 0) {
- $pro_tree[$r->ID] = array();
- $v_id = $r->P_ID;
- if (array_key_exists($v_id, $items)) {
- $items[$v_id]->sub[$r->ID] = true;
- }
- } else {// array
- foreach ($r->P_ID as $v_id) {
- if (array_key_exists($v_id, $items)) {
- $items[$v_id]->sub[$r->ID] = true;
- }
- }
- }
- }
- ksort($pro_tree);
- // set up has_childrens
- foreach ($items as $k_id => $r) {
- $items[$k_id]->has_childrens = !empty($r->sub);
- }
-
- // build tree by P_ID - array or 0
- function TREEJS_create_project_tree_rec($p_id, &$items) {
- static $rec_ind;
- $rec_ind++;
- $ret = array();
- if (!array_key_exists($p_id, $items)) {
- return false;
- } else {
- $r = $items[$p_id];
- if (empty($r->sub)) {
- return false;
- }
- foreach ($r->sub as $k_id => $v) {
- $ret[$k_id] = TREEJS_create_project_tree_rec($k_id, $items);
- }
- return $ret;
- }
- }
- //$pro_tree = TREEJS_create_project_tree_rec($pro_tree, $items);
- foreach ($pro_tree as $k_id => $v_childrens) {
- if (array_key_exists($k_id, $items)) {
- $pro_tree[$k_id] = TREEJS_create_project_tree_rec($k_id, $items);
- }
- }
- $dbgExecTime->log('end-lazy-load', array('lazy-load'));
- }
- $tree = new Tree($tblName);
- $tree->set_param('htmlTreeId', $htmlTreeId);
- $tree->setProfiler($dbgExecTime);
- if (($p_id_col = V::get('set_parent_id_col', '', $conf)) != '') {
- $tree->set_parent_id_col($p_id_col);
- }
- if (!empty($conf['params'])) {
- foreach ($conf['params'] as $k_param => $v_param) {
- $tree->set_param($k_param, $v_param);
- }
- }
- $tree->set_param('filtr_status', $tree_filter->get_arg('filtr_status'));
- $dbgExecTime->log('start-show-tree');
- if ($TEST_TREE_LAZY_LOAD) {
- $tree->show_css();
- $tree->show_js();
- echo "\n".'<div class="tree-wrap">'."\n";
- $tree->show_rec_by_tree($pro_tree, $items);
- echo '</div>'."\n";
- }
- else {
- if ($tree_filter->get_arg('filtr_id') != 0) {
- $tree->showSubTree($tree_filter->get_arg('filtr_id'));
- } else if ($tree_filter->get_arg('filtr_search_id') > 0) {
- $tree->showSearchNode($tree_filter->get_arg('filtr_search_id'));
- } else {
- $tree->show();
- }
- }
- $dbgExecTime->log('end-show-tree', array('show-tree'));
- echo '</div>';
- ?>
- <script>
- window['<?php echo $htmlTreeId; ?>TreeStruct'] = <?php echo json_encode($pro_tree); ?>;
- window['<?php echo $htmlTreeId; ?>TreeItems'] = <?php echo json_encode($items); ?>;
- // show/hide ids list - btn state txt
- var BTN_TXT_LOADING = 'IDS (loading...)',
- BTN_TXT_SHOW = 'IDS (pokaż)',
- BTN_TXT_HIDE = 'IDS (ukryj)';
- BTN_TXT_NO_DATA = 'IDS (brak danych)';
- function <?php echo $htmlTreeId; ?>_reload(fltrs) {
- var tree = jQuery('#<?php echo $htmlTreeId; ?>').find('.tree-wrap');
- if (fltrs.filtr_status) {
- if (-1 == _.indexOf(['NORMAL', 'WAITING'], fltrs.filtr_status)) {
- fltrs.filtr_status = null;
- }
- }
- var isFltrsActive = false;
- if (!_.isEmpty(fltrs.filtr_id)) isFltrsActive = true;
- if (fltrs.filtr_status) isFltrsActive = true;
- if (!isFltrsActive) {
- tree.find('li').removeClass('hide');
- return;
- } else {
- tree.find('li').addClass('hide');
- }
- var treeStruct = window['<?php echo $htmlTreeId; ?>TreeStruct'];
- var treeItems = window['<?php echo $htmlTreeId; ?>TreeItems'];
- if (fltrs.filtr_id) {
- var j, ids = [], idsTmp = fltrs.filtr_id.replace(' ', '').split(',');
- for (var i = 0; i < idsTmp.length; i++) {
- j = _.parseInt(idsTmp[i], 10);
- if (_.isNumber(j) && j > 0 && !_.isNaN(j)) {
- ids.push(j);
- }
- }
- fltrs.filtr_id = ids;
- }
- filteredIds = [];
- if (!_.isEmpty(fltrs.filtr_id)) {
- var curId, item, itemIsOk,
- todoStack = _.map(fltrs.filtr_id, function(num) { return num; });
- var limit = 1000;
- while (!_.isEmpty(todoStack)) {
- curId = todoStack.shift();
- if (curId in filteredIds) continue;
- item = (curId in treeItems)? treeItems[curId] : null;
- if (!item) continue;
- filteredIds[curId] = true;
- var pid = _.parseInt(item['P_ID'], 10);
- if (pid > 0) {
- todoStack.push(pid);
- }
- if (limit-- < 1) break;
- }
- var limit = 10000;
- todoStack = _.map(fltrs.filtr_id, function(num) { return num; });
- while (!_.isEmpty(todoStack)) {
- curId = todoStack.shift();
- if (curId in filteredIds && -1 == fltrs.filtr_id.indexOf(curId)) {
- continue;
- }
- item = (curId in treeItems)? treeItems[curId] : null;
- if (!item) continue;
- itemIsOk = false;
- if (fltrs.filtr_status) {
- if ('NORMAL' == fltrs.filtr_status) {
- if ('NORMAL' === item['A_STATUS']) {
- itemIsOk = true;
- }
- }
- else if ('WAITING' == fltrs.filtr_status) {
- if ('WAITING' === item['A_STATUS']) {
- itemIsOk = true;
- }
- else if ('NORMAL' === item['A_STATUS']) {
- itemIsOk = true;
- }
- }
- }
- else {
- itemIsOk = true;
- }
- filteredIds[curId] = itemIsOk;
- var toAdd = [];
- if (true === item['has_childrens']) {
- for (i in item['sub']) {
- //if (id in filteredIds) continue;
- //if (-1 !== toAdd.indexOf(id)) continue;
- //if (-1 !== todoStack.indexOf(id)) continue;
- toAdd.push(i);
- }
- }
- if (_.isEmpty(toAdd)) {
- continue;
- }
-
- todoStack = _.union(todoStack, toAdd);
- if (limit-- < 1) break;
- }
- }
- if (_.isEmpty(fltrs.filtr_id)) {
- if (fltrs.filtr_status) {
- var item, itemIsOk;
- for (var curId in treeItems) {
- item = treeItems[curId];
- if (item) {
- itemIsOk = false;
- if ('NORMAL' === item['A_STATUS']) {
- itemIsOk = true;
- }
- if ('WAITING' == fltrs.filtr_status) {
- if ('WAITING' === item['A_STATUS']) {
- itemIsOk = true;
- }
- }
- filteredIds[curId] = itemIsOk;
- }
- }
- }
- }
- for (var i in filteredIds) {
- if (filteredIds[i]) {
- jQuery('#TREE' + i)
- .removeClass('hide')
- .removeClass('tree-close');
- }
- }
- }
- function <?php echo $htmlTreeId; ?>_filters(el, params) {
- if (!el || !el.form) return false;
- var params = params || {};
- if (params.clear) {
- <?php echo $htmlTreeId; ?>_reload({});
- return;
- }
- var frm = el.form;
- var fltrs = {};
- if (frm['filtr_status'] && frm['filtr_status'].value) {
- fltrs['filtr_status'] = frm['filtr_status'].value;
- }
- if (frm['filtr_id'] && frm['filtr_id'].value) {
- fltrs['filtr_id'] = frm['filtr_id'].value;
- }
- <?php echo $htmlTreeId; ?>_reload(fltrs);
- return false;
- }
- function <?php echo $htmlTreeId; ?>_setIds(btnNode, id, idsList) {
- var idsList = idsList || [];
- var ddNode = btnNode.parentNode.nextSibling;
- if (!ddNode) {
- ddNode = document.createElement('dd');
- btnNode.parentNode.parentNode.insertBefore(ddNode, btnNode.parentNode.nextSibling);
- }
- if (_.isEmpty(idsList)) {
- btnNode.innerHTML = BTN_TXT_NO_DATA;
- ddNode.innerHTML = '';
- return;
- }
- var ulNode = document.createElement('ul');
- _.each(idsList, function(item) {
- var liNode = document.createElement('li');
- var pNode = document.createElement('p');
- if (!_.isEmpty(item.table)) {
- var spanNode = document.createElement('span');
- spanNode.className = 'btn-box btn-box-silver';
- spanNode.appendChild(document.createTextNode(item.table));
- pNode.appendChild(spanNode);
- }
- var bNode = document.createElement('b');
- bNode.appendChild(document.createTextNode(item.name));
- pNode.appendChild(bNode);
- liNode.appendChild(pNode);
- ulNode.appendChild(liNode);
- })
- if (ulNode.lastChild) {
- ulNode.lastChild.className = 'tree-last';
- }
- btnNode.innerHTML = BTN_TXT_HIDE;
- ddNode.innerHTML = '';
- ddNode.appendChild(ulNode);
- }
- function <?php echo $htmlTreeId; ?>_ids(btnNode, id) {
- var item = (id in window['<?php echo $htmlTreeId; ?>TreeItems'])? window['<?php echo $htmlTreeId; ?>TreeItems'][id] : null;
- if (!item) return;
- if (null == btnNode.parentNode.nextSibling) {
- var ddNode = document.createElement('dd');
- btnNode.parentNode.parentNode.insertBefore(ddNode, btnNode.parentNode.nextSibling);
- }
- if (BTN_TXT_HIDE === btnNode.innerHTML) {
- btnNode.innerHTML = BTN_TXT_SHOW;
- btnNode.parentNode.nextSibling.className='hide';
- } else if (BTN_TXT_SHOW === btnNode.innerHTML) {
- btnNode.innerHTML = BTN_TXT_HIDE;
- btnNode.parentNode.nextSibling.className='';
- } else if (BTN_TXT_LOADING === btnNode.innerHTML) {
- } else if (BTN_TXT_NO_DATA === btnNode.innerHTML) {
- } else {// INIT is default state
- btnNode.innerHTML = BTN_TXT_LOADING;
- superagent
- .get('index.php')
- .query({FUNCTION_INIT: '<?php echo __FUNCTION__; ?>'})
- .query({ZASOB_ID: '<?php echo V::get('ZASOB_ID', 0, $_GET, 'int'); ?>'})
- .query({HEADER_NOT_INIT: 'YES'})
- .query({_ajaxTask: 'idsList'})
- .query({id: id})
- .end(function(error, res) {
- if (res.ok && 'ids' in res.body) {
- <?php echo $htmlTreeId; ?>_setIds(btnNode, id, res.body.ids);
- } else {
- <?php echo $htmlTreeId; ?>_setIds(btnNode, id, {ids: []});
- }
- });
- }
- return false;
- }
- </script>
- <?php
- if($DBG_TIME){
- $dbgExecTime->log('end');
- $dbgExecTime->printDebug();
- }
- }
|