diff --git a/templates/web/prod/thesaurus.js b/templates/web/prod/thesaurus.js index 01aba83703..20fa9cee2e 100644 --- a/templates/web/prod/thesaurus.js +++ b/templates/web/prod/thesaurus.js @@ -1,4 +1,3 @@ - function thesau_show() { if(p4.thesau.currentWizard == "???") // first show of thesaurus @@ -213,27 +212,16 @@ function T_filter_delayed2(f, delay, mode) // ====================================================================================================== - - function T_replaceCandidates_OK(dlgnode) { - $("#THPD_confirm_replace_dlg_msg").html("{% trans 'prod::thesaurusTab:dlg:Remplacement en cours.' %}"); - - // 3 cases - // the new term already exists (possibly many times) in the thesaurus - // the new term already exists in the candidates - // the new term is brand new - - // the simpliest solution is to replace the terms and let the indexer work - + $(dlgnode).dialog().html("{% trans 'prod::thesaurusTab:dlg:Remplacement en cours.' %}"); var parms = { url: "/xmlhttp/replacecandidate.j.php", data: { - "sbid" : trees.C._toReplace.sbas - , "cid" : trees.C._toReplace.cid - , "t" : trees.C._toReplace.replaceby - // , "debug" : '1' + "id[]" : trees.C._toReplace.sbas + "." + trees.C._toReplace.cid + , "t" : trees.C._toReplace.replaceby + , "debug" : '0' }, async: false, cache: false, @@ -243,7 +231,21 @@ function T_replaceCandidates_OK(dlgnode) { trees.C._toReplace = null; thesauShowWizard("wiz_0", false); + $(dlgnode).dialog("close"); + var msg = $.sprintf("{% trans 'prod::thesaurusTab:dlg: %s record(s) updated' %}", result.nRecsUpdated); + if(result.msg != '') + { + msg = result.msg + '\n' + msg; + } + alert(msg); + + for(i in result.ctermsDeleted) + { + var cid = "#CX_P\\." + result.ctermsDeleted[i].replace(new RegExp("\\.", "g"), "\\."); // escape les '.' pour jquery + $(cid).remove(); + } + }, _ret: null // private alchemy }; @@ -254,7 +256,7 @@ function T_replaceCandidates_OK(dlgnode) function T_acceptCandidates_OK(dlgnode) { - $("#THPD_confirm_accept_dlg_msg").html("{% trans 'prod::thesaurusTab:dlg:Acceptation en cours.' %}"); + $(dlgnode).dialog().html("{% trans 'prod::thesaurusTab:dlg:Acceptation en cours.' %}"); var t_ids = []; var dst = trees.C._toAccept.dst.split('.'); @@ -264,20 +266,19 @@ function T_acceptCandidates_OK(dlgnode) same_sbas = true; // obviously the candidates and the target already complies (same sbas, good tbranch) trees.C._selInfos.sel.each( - function() - { - var x = this.getAttribute('id').split('.'); - x.shift(); - if(x.shift() != sbid) - same_sbas = false; - t_ids.push(x.join('.')); - } -); + function() + { + var x = this.getAttribute('id').split('.'); + x.shift(); + if(x.shift() != sbid) + same_sbas = false; + t_ids.push(x.join('.')); + } + ); if(!same_sbas) return; - var parms = { url: "/xmlhttp/acceptcandidates.j.php", data: { @@ -319,8 +320,6 @@ function T_acceptCandidates_OK(dlgnode) } , "json"); } - - // $("#THPD_confirm_accept_dlg_msg").dialog("close"); }, error:function(){}, timeout:function(){}, @@ -331,22 +330,22 @@ function T_acceptCandidates_OK(dlgnode) } -function C_deleteCandidates_OK() +function C_deleteCandidates_OK(dlgnode) { - $("#THPD_confirm_del_dlg_msg").html("{% trans 'prod::thesaurusTab:dlg:Suppression en cours.' %}"); + $(dlgnode).dialog().html("{% trans 'prod::thesaurusTab:dlg:Suppression en cours.' %}"); var t_ids = []; var lisel = trees.C.tree.find("LI .selected"); trees.C.tree.find("LI .selected").each( - function() - { - var x = this.getAttribute('id').split('.'); - x.shift(); - t_ids.push(x.join('.')); - } -); + function() + { + var x = this.getAttribute('id').split('.'); + x.shift(); + t_ids.push(x.join('.')); + } + ); var parms = { - url:"/xmlhttp/deletecandidates.j.php", + url:"/xmlhttp/replacecandidate.j.php", data:{"id[]":t_ids}, async:false, cache:false, @@ -354,12 +353,20 @@ function C_deleteCandidates_OK() timeout:10*60*1000, // 10 minutes ! success: function(result, textStatus) { - for(i in result) + $(dlgnode).dialog("close"); + + var msg = $.sprintf("{% trans 'prod::thesaurusTab:dlg: %s record(s) updated' %}", result.nRecsUpdated); + if(result.msg != '') { - var cid = "#CX_P\\." + result[i].replace(new RegExp("\\.", "g"), "\\."); // escape les '.' pour jquery + msg = result.msg + '\n' + msg; + } + alert(msg); + + for(i in result.ctermsDeleted) + { + var cid = "#CX_P\\." + result.ctermsDeleted[i].replace(new RegExp("\\.", "g"), "\\."); // escape les '.' pour jquery $(cid).remove(); } - $("#THPD_confirm_del_dlg").dialog("close"); }, _ret: null }; @@ -1138,15 +1145,14 @@ function startThesaurus(){ buttons:{ "{% trans 'boutton::ok' %}":function() { - C_deleteCandidates_OK(); + C_deleteCandidates_OK(this); }, "{% trans 'boutton::annuler' %}":function() { $(this).dialog("close"); } } - } -); + }); $("#THPD_confirm_accept_dlg").dialog( { @@ -1165,8 +1171,7 @@ function startThesaurus(){ $(this).dialog("close"); } } - } -); + }); $("#THPD_confirm_replace_dlg").dialog( { @@ -1185,8 +1190,7 @@ function startThesaurus(){ $(this).dialog("close"); } } - } -); + }); trees.T.tree.contextMenu( @@ -1341,6 +1345,16 @@ function startThesaurus(){ // glue selection info to the tree trees.C._selInfos = {'sel':lisel, 'field':field, 'sbas':sbas, 'n':lisel.length} ; + +// $(this.menu).find('.context-menu-item')[{{ thesau_languages|length }}].addClass('context-menu-item-disabled'); + if(lisel.length == 1) + { + $(this.menu).find('.context-menu-item').eq({{ thesau_languages|length }}).removeClass('context-menu-item-disabled'); + } + else + { + $(this.menu).find('.context-menu-item').eq({{ thesau_languages|length }}).addClass('context-menu-item-disabled'); + } } else { diff --git a/www/xmlhttp/deletecandidates.j.php b/www/xmlhttp/deletecandidates.j.php deleted file mode 100644 index 86ad000fea..0000000000 --- a/www/xmlhttp/deletecandidates.j.php +++ /dev/null @@ -1,253 +0,0 @@ -get_parms( - 'id', 'debug' -); - -phrasea::headers(200, true, 'application/json', 'UTF-8', false); - -define('SEARCH_REPLACE_MAXREC', 25); - -$tsbas = array(); - -$ret = array( - 'maxRecsUpdatable'=>SEARCH_REPLACE_MAXREC, - 'nRecsToUpdate'=>0, - 'nRecsUpdated'=>0, - 'msg'=>'' -); - -foreach ($parm['id'] as $id) { - $id = explode('.', $id); - $sbas_id = array_shift($id); - if ( ! array_key_exists('b' . $sbas_id, $tsbas)) { - $tsbas['b' . $sbas_id] = array( - 'sbas_id' => (int) $sbas_id, - 'tids' => array(), - 'domct' => null, - 'tvals' => array(), - 'lid' => '', - 'trids' => array() - ); - } - $tsbas['b' . $sbas_id]['tids'][] = implode('.', $id); -} - -if ($parm['debug']) { - var_dump($tsbas); -} - -$appbox = \appbox::get_instance(\bootstrap::getCore()); - - -// first, count the number of records to update -foreach ($tsbas as $ksbas=>$sbas) { - - /* @var $databox databox */ - try { - $databox = $appbox->get_databox($sbas['sbas_id']); - $connbas = $databox->get_connection(); - // $domth = $databox->get_dom_thesaurus(); - $tsbas[$ksbas]['domct'] = $databox->get_dom_cterms(); - } catch (Exception $e) { - continue; - } - - if ( ! $tsbas[$ksbas]['domct']) { - continue; - } - - $lid = ''; - $xpathct = new DOMXPath($tsbas[$ksbas]['domct']); - - foreach ($sbas['tids'] as $tid) { - $xp = '//te[@id="' . $tid . '"]/sy'; - $nodes = $xpathct->query($xp); - if ($nodes->length == 1) { - $sy = $term = $nodes->item(0); - $syid = str_replace('.', 'd', $sy->getAttribute('id')) . 'd'; - $lid .= ( $lid ? ',' : '') . "'" . $syid . "'"; - $field = $sy->parentNode->parentNode->getAttribute('field'); - - if ( ! array_key_exists($field, $tsbas[$ksbas]['tvals'])) { - $tsbas[$ksbas]['tvals'][$field] = array(); - } - $tsbas[$ksbas]['tvals'][$field][] = $sy; - } - } - - if ($lid == '') { - // no cterm was found - continue; - } - $tsbas[$ksbas]['lid'] = $lid; - - // count records - $sql = 'SELECT DISTINCT record_id AS r' - .' FROM thit WHERE value IN (' . $lid . ') ORDER BY record_id'; - $stmt = $connbas->prepare($sql); - $stmt->execute(); - - if ($parm['debug']) { - printf("(%d) sql: \n", __LINE__); - var_dump($sql); - } - - $tsbas[$ksbas]['trids'] = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); - $stmt->closeCursor(); - - $ret['nRecsToUpdate'] += count($tsbas[$ksbas]['trids']); -} - - -if ($parm['debug']) { - printf("(%d) nRecsToUpdate = %d \ntsbas: \n", __LINE__, $ret['nRecsToUpdate']); - print_r($tsbas); -} - - -if($ret['nRecsToUpdate'] < SEARCH_REPLACE_MAXREC) -{ - $unicode = new unicode; - foreach ($tsbas as $sbas) { - - /* @var $databox databox */ - try { - $databox = $appbox->get_databox($sbas['sbas_id']); - $connbas = $databox->get_connection(); - } catch (Exception $e) { - continue; - } - - // delete the branch from the cterms - if ($parm['debug']) { - printf("cterms before :\n%s \n", $sbas['domct']->saveXML()); - } - foreach($sbas['tvals'] as $tval) { - foreach($tval as $sy) { - // remove candidate from cterms - $te = $sy->parentNode; - $te->parentNode->removeChild($te); - } - } - if ($parm['debug']) { - printf("cterms after :\n%s \n", $sbas['domct']->saveXML()); - } - if ( ! $parm['debug']) { - $databox->saveCterms($sbas['domct']); - } - - // fix caption of records - foreach ($sbas['trids'] as $rid) { - - if ($parm['debug']) { - printf("(%d) ======== working on record_id = %d ======= \n", __LINE__, $rid); - } - try { - $record = $databox->get_record($rid); - - $metadatask = array(); // datas to keep - $metadatasd = array(); // datas to delete - - /* @var $field caption_field */ - foreach ($record->get_caption()->get_fields(null, true) as $field) { - $meta_struct_id = $field->get_meta_struct_id(); - if ($parm['debug']) { - printf("(%d) field '%s' meta_struct_id=%s \n", __LINE__, $field->get_name(), $meta_struct_id); - } - - /* @var $v caption_Field_Value */ - $fname = $field->get_name(); - if(!array_key_exists($fname, $sbas['tvals'])) { - foreach ($field->get_values() as $v) { - if ($parm['debug']) { - printf("(%d) ...v = '%s' (meta_id=%s) keep \n", __LINE__, $v->getValue(), $v->getId()); - } - $metadatask[] = array( - 'meta_struct_id' => $meta_struct_id, - 'meta_id' => $v->getId(), - 'value' => $v->getValue() - ); - } - } - else { - foreach ($field->get_values() as $v) { - $keep = true; - $vtxt = $unicode->remove_indexer_chars($v->getValue()); - foreach($sbas['tvals'][$fname] as $sy) { - if ($sy->getAttribute('w') == $vtxt) { - $keep = false; - } - } - - if ($parm['debug']) { - printf("(%d) ...v = '%s' (meta_id=%s) %s \n", __LINE__, $v->getValue(), $v->getId(), ($keep ? '' : '!!! drop !!!')); - } - if ($keep) { - $metadatask[] = array( - 'meta_struct_id' => $meta_struct_id, - 'meta_id' => $v->getId(), - 'value' => $v->getValue() - ); - } else { - $metadatasd[] = array( - 'meta_struct_id' => $meta_struct_id, - 'meta_id' => $v->getId(), - 'value' => '' - ); - } - } - } - } - - if ($parm['debug']) { - printf("(%d) metadatas: \n", __LINE__); - var_dump($metadatasd); - } - - if(count($metadatasd) > 0) { - if ( ! $parm['debug']) { -// foreach (array('idx', 'prop', 'thit') as $t) { -// $sql = 'DELETE FROM ' . $t . ' WHERE record_id = :record_id'; -// $stmt = $connbas->prepare($sql); -// $stmt->execute(array(':record_id' => $rid)); -// $stmt->closeCursor(); -// } - $record->set_metadatas($metadatasd, true); - $ret['nRecsUpdated']++; - } - } - } catch (\Exception $e) { - continue; - } - } - } -} -else { - // too many records to update - $ret['msg'] = 'too many records to update'; -} - - - -/** - * @todo respecter les droits d'editing par collections - */ -print(p4string::jsonencode($ret));