546. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 7/6/2017 8:23:20 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

546.1 Files compared

# Location File Last Modified
1 OSCIF_CTT_v4_build 1.zip\rails_komet\app\assets\javascripts\util ui_helper.js Wed May 31 03:58:56 2017 UTC
2 OSCIF_CTT_v4_build 1.zip\rails_komet\app\assets\javascripts\util ui_helper.js Thu Jul 6 20:59:43 2017 UTC

546.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 3182
Changed 1 2
Inserted 0 0
Removed 0 0

546.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

546.4 Active regular expressions

No regular expressions were active.

546.5 Comparison detail

  1   /*
  2    Copyright  Notice
  3  
  4    This is a  work of t he U.S. Go vernment a nd is not  subject to  copyright
  5    protectio n in the U nited Stat es. Foreig n copyrigh ts may app ly.
  6  
  7    Licensed  under the  Apache Lic ense, Vers ion 2.0 (t he "Licens e");
  8    you may n ot use thi s file exc ept in com pliance wi th the Lic ense.
  9    You may o btain a co py of the  License at
  10  
  11    http://ww w.apache.o rg/license s/LICENSE- 2.0
  12  
  13    Unless re quired by  applicable  law or ag reed to in  writing,  software
  14    distribut ed under t he License  is distri buted on a n "AS IS"  BASIS,
  15    WITHOUT W ARRANTIES  OR CONDITI ONS OF ANY  KIND, eit her expres s or impli ed.
  16    See the L icense for  the speci fic langua ge governi ng permiss ions and
  17    limitatio ns under t he License .
  18    */
  19   /**
  20    * Created  by  PII  on 2/8/20 16.
  21    */
  22   var UIHelp er = (func tion () {
  23  
  24       var co nceptClipb oard = {};
  25       var au toSuggestR ecentCache  = {};
  26       var de ferredRece ntsCalls =  null;
  27       var fl agControlR owTemplate s = {};
  28       const  VHAT = gon .IsaacMeta dataAuxili ary.VHAT_M ODULES.uui ds[0].uuid ;
  29       const  SNOMED = g on.IsaacMe tadataAuxi liary.SNOM ED_CT_CORE _MODULES.u uids[0].uu id;
  30       const  LOINC = go n.IsaacMet adataAuxil iary.LOINC _MODULES.u uids[0].uu id;
  31       const  RXNORM = g on.IsaacMe tadataAuxi liary.RXNO RM_MODULES .uuids[0]. uuid;
  32       const  CHANGEABLE _CLASS = " komet-chan geable";
  33       const  CHANGE_HIG HLIGHT_CLA SS = "kome t-highligh t-changes" ;
  34       const  RECENTS_AS SOCIATION  = 'associa tion';
  35       const  RECENTS_MA PSET = 'ma pset';
  36       const  RECENTS_SE MEME = 'se meme';
  37       const  RECENTS_ME TADATA = ' metadata';
  38       const  FLAG_SHAPE S = {'None ': '', 'Sq uare': 'gl yphicon gl yphicon-st op', 'Star ': 'glyphi con glyphi con-star',  'Triangle ': 'glyphi con glyphi con-triang le-top', ' Asterisk':  'glyphico n glyphico n-asterisk ', 'Circle ': 'fa fa- circle'};
  39  
  40       /*
  41        * ini tDatePicke r - Initia lize a dat e picker i nput group  to with a  starting  date
  42        * @pa ram [objec t or strin g] element OrSelector  - Either  a jquery o bject or t he class o r ID selec tor (inclu ding the " #" or "."  prefix) th at represe nts the da te picker  input grou p we are i nitializin g.
  43        * @pa ram [Numbe r or strin g] startin gDate - a  long numbe r that rep resents th e date in  millisecon ds since t he epoch,  or the str ing 'lates t'
  44        * @pa ram [funct ion] onCha ngeFunctio n - a func tion objec t that wil l be run w hen the da te is chan ged (takes  an event  parameter  which incl udes .oldD ate and .d ate (the n ew date)
  45        */
  46       functi on initDat ePicker(el ementOrSel ector, sta rtingDate,  onChangeF unction) {
  47  
  48           va r datePick er;
  49  
  50           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  51           if  (typeof e lementOrSe lector ===  "string")  {
  52                datePick er = $(ele mentOrSele ctor);
  53           }  else {
  54                datePick er = eleme ntOrSelect or;
  55           }
  56  
  57           //  get the d ate field  input fiel d
  58           va r input_fi eld = date Picker.fin d("input") ;
  59  
  60           //  set the p arams for  the date f ield
  61           va r date_par ams = {
  62                useCurre nt: false,
  63                showClea r: true,
  64                showToda yButton: t rue,
  65                icons: {
  66                    time : "fa fa-c lock-o",
  67                    date : "fa fa-c alendar",
  68                    up:  "fa fa-arr ow-up",
  69                    down : "fa fa-a rrow-down"
  70                }
  71           };
  72  
  73           //  if the st arting dat e is not ' latest' th en set the  default d ate param  to the sta rting valu e. The plu s is in ca se the val ue is a st ring
  74           if  (starting Date != nu ll && star tingDate ! = undefine d && start ingDate !=  'latest') {
  75                date_par ams.defaul tDate = mo ment(+star tingDate);
  76           }
  77  
  78           //  create th e date fie ld
  79           in put_field. datetimepi cker(date_ params);
  80  
  81           //  If it was  passed in , set the  field onCh ange funct ion to the  passed in  function
  82           if  (onChange Function ! = null &&  onChangeFu nction !=  undefined) {
  83                input_fi eld.on("dp .change",  onChangeFu nction);
  84           }
  85       }
  86  
  87       /*
  88        * set StampDate  - set the  value of a  Stated fi eld radio  button gro up
  89        * @pa ram [objec t or strin g] element OrSelector  - Either  a jquery o bject or t he class o r ID selec tor (inclu ding the " #" or "."  prefix) th at represe nts the da te picker  input grou p whose va lue we are  setting.
  90        * @pa ram [strin g] newValu e - the va lue to set  the value  of the fi eld to
  91        */
  92       functi on setStam pDate(elem entOrSelec tor, newVa lue) {
  93  
  94           va r dateGrou p;
  95  
  96           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  97           if  (typeof e lementOrSe lector ===  "string")  {
  98                dateGrou p = $(elem entOrSelec tor);
  99           }  else {
  100                dateGrou p = elemen tOrSelecto r;
  101           }
  102  
  103           if  (newValue  == 'lates t'){
  104                newValue  = '';
  105           }
  106  
  107           //  set the d ate input  value
  108           da teGroup.fi nd("input" ).val(newV alue);
  109       }
  110  
  111       // fun ction to t he the pos ition of a n element  from the e dge of the  viewpoint
  112       functi on getOffs et(element ) {
  113  
  114           el ement = el ement.getB oundingCli entRect();
  115  
  116           re turn {
  117                left: el ement.left  + window. scrollX,
  118                top: ele ment.top +  window.sc rollY
  119           }
  120       }
  121  
  122       functi on escapeR egEx(regEx String) {
  123           re turn regEx String.rep lace(/[.*+ ?^${}()|[\ ]\\]/g, "\ \$&"); //  $& means t he whole m atched str ing
  124       }
  125  
  126       /*
  127        * ini tOrderCont rols - Ini tialize or der contro l widgets  in an area  of the pa ge - must  be set up  using kome t order co ntrol clas ses (komet -row, kome t-order-co ntrol-body , komet-ch ange-order -up, komet -change-or der-down)
  128        * @pa ram [objec t or strin g] element OrSelector  - Either  a jquery o bject or t he class o r ID selec tor (inclu ding the " #" or "."  prefix) th at represe nts the ar ea contain ing order  controls t o initiali ze.
  129        */
  130       functi on initOrd erControls (elementOr Selector){
  131  
  132           va r orderCon trols;
  133           va r orderCon trolRows;
  134  
  135           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  136           if  (typeof e lementOrSe lector ===  "string")  {
  137                orderCon trols = $( elementOrS elector).f ind(".kome t-order-co ntrol-body ");
  138           }  else {
  139                orderCon trols = el ementOrSel ector.find (".komet-o rder-contr ol-body");
  140           }
  141  
  142           //  loop over  each orde r control
  143           or derControl s.each(fun ction(){
  144  
  145                // get a ll the row s in the c ontrol
  146                orderCon trolRows =  $(this).c hildren();
  147  
  148                // disab le the up  button on  the first  row
  149                var firs tRowButton  = orderCo ntrolRows. first().fi nd(".komet -change-or der-up");
  150                firstRow Button.add Class("ui- state-disa bled");
  151                firstRow Button.pro p("disable d", true);
  152  
  153                // disab le the dow n button o n the last  row
  154                var last RowButton  = orderCon trolRows.l ast().find (".komet-c hange-orde r-down");
  155                lastRowB utton.addC lass("ui-s tate-disab led");
  156                lastRowB utton.prop ("disabled ", true);
  157           }) ;
  158       }
  159  
  160       /*
  161        * mov eRowOrderC ontrol - M ove a row  in an orde r control  widget whe n an up or  down butt on is sele cted
  162        * @pa ram [objec t] button  - the butt on object  that was s elected.
  163        * @pa ram [strin g] directi on - the d irection i n the list  to move t he selecte d row. Opt ions are ' up' and 'd own'.
  164        */
  165       functi on moveRow OrderContr ol(button,  direction ) {
  166  
  167           //  get the r ow that su rrounds th e button t hat was se lected
  168           va r selected Row = $(bu tton).clos est("div.k omet-row") ;
  169           va r targetRo w;
  170           va r moveActi on;
  171           va r targetAc tion;
  172  
  173           //  if we are  moving th e row up s et actions  to before  and previ ous, else  to after a nd next
  174           if  (directio n == 'up') {
  175  
  176                moveActi on = 'befo re';
  177                targetAc tion = "pr ev";
  178  
  179           }  else {
  180  
  181                moveActi on = 'afte r';
  182                targetAc tion = "ne xt";
  183           }
  184  
  185           //  get the r ow we are  moving the  selected  row relati ve to
  186           ta rgetRow =  selectedRo w[targetAc tion]();
  187  
  188           //  if the ta rget exist s
  189           if  (targetRo w.length)  {
  190  
  191                // use t he appropr iate move  action met hod on the  target to  move the  selected r ow
  192                targetRo w[moveActi on](select edRow);
  193  
  194                // see i f there is  a disable d button i n the sele cted row
  195                var sele ctedOpposi teButton =  selectedR ow.find(". ui-state-d isabled");
  196  
  197                // if th ere is a d isabled bu tton in th e selected  row then  it started  at one en d of the l ist
  198                if (sele ctedOpposi teButton.l ength){
  199  
  200                    // e nable the  button sin ce it will  no longer  be at tha t end of t he list
  201                    sele ctedOpposi teButton.r emoveClass ("ui-state -disabled" );
  202                    sele ctedOpposi teButton.p rop("disab led", fals e);
  203  
  204                    // t he target  row is now  at the en d of the l ist so dis able the a ppropriate  button
  205                    var  targetOppo siteButton  = targetR ow.find(". " + select edOpposite Button.att r('class') .split(" " ).join("." ));
  206                    targ etOpposite Button.add Class("ui- state-disa bled");
  207                    targ etOpposite Button.pro p("disable d", true);
  208                }
  209  
  210                // see i f there is  another r ow in the  chosen dir ection (if  the selec ted row is  now at on e end of t he list)
  211                var atEn d = select edRow[targ etAction]( ).length;
  212  
  213                // if th e selected  row is at  one end o f the list
  214                if (atEn d == 0){
  215  
  216                    // d isable the  appropria te button  on the sel ected row
  217                    var  selectedBu tton = sel ectedRow.f ind(".kome t-change-o rder-" + d irection);
  218                    sele ctedButton .addClass( "ui-state- disabled") ;
  219                    sele ctedButton .prop("dis abled", tr ue);
  220  
  221                    // e nable the  appropriat e button o n the targ et row sin ce it is n o longer a t one end  of the lis t
  222                    var  targetButt on = targe tRow.find( ".komet-ch ange-order -" + direc tion);
  223                    targ etButton.r emoveClass ("ui-state -disabled" );
  224                    targ etButton.p rop("disab led", fals e);
  225                }
  226           }
  227       }
  228  
  229       /*
  230        * ini tFlagContr ols - Init ialize fla g control  widgets in  an area o f the page  - must be  set up us ing komet  flag contr ol classes  (komet-ro w, komet-f lag-contro l-body, ko met_color_ picker)
  231        * @pa ram [objec t or strin g] element OrSelector  - Either  a jquery o bject or t he class o r ID selec tor (inclu ding the " #" or "."  prefix) th at represe nts the ar ea contain ing contro ls to init ialize.
  232        */
  233       functi on initFla gControls( elementOrS elector){
  234  
  235           va r flagCont rols;
  236  
  237           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  238           if  (typeof e lementOrSe lector ===  "string")  {
  239                flagCont rols = $(e lementOrSe lector);
  240           }  else {
  241                flagCont rols = ele mentOrSele ctor;
  242           }
  243  
  244           if  (flagCont rols.attr( "id").inde xOf("komet _flag_cont rol_row")  == -1){
  245                flagCont rols = fla gControls. find(".kom et-flag-co ntrol-body ");
  246           }
  247  
  248           fl agControls .find('.ko met-color- picker').m inicolors( {
  249  
  250                    posi tion: 'bot tom right' ,
  251                    chan ge: functi on() {
  252  
  253                         var clearB utton = $( this).pare nt().next( ".komet-fl ag-control -clear");
  254                         clearButto n.removeCl ass("ui-st ate-disabl ed");
  255                         clearButto n.prop("di sabled", f alse);
  256                    }
  257  
  258           }) ;
  259  
  260           // $.minicolo rs.default s.position  = 'bottom  right';
  261       }
  262  
  263       //clea r color va lue
  264       functi on clearCo lorFlagCon trol(field ID) {
  265  
  266           va r colorFie ld = $("#"  + fieldID );
  267           co lorField.v al("");
  268           co lorField.c ss("backgr oundColor" , "");
  269  
  270           co lorField.n ext().find ('.minicol ors-swatch -color').c ss("backgr ound-color ", "");
  271  
  272           va r clearBut ton = $(co lorField). parent().n ext(".kome t-flag-con trol-clear ");
  273           cl earButton. addClass(" ui-state-d isabled");
  274           cl earButton. prop("disa bled", tru e);
  275  
  276       }
  277  
  278       /*
  279        * set FlagShape  - Sets the  appropria te element s of a fla g control  widget whe n the user  selects a  shape
  280        * @pa ram [objec t] selecte dOption -  the shape  option tha t was sele cted.
  281        * @pa ram [strin g] shapeNa me - the n ame of the  shape tha t was sele cted. Must  be in the  UIHelper. FLAG_SHAPE S variable
  282        */
  283       functi on setFlag Shape(sele ctedOption , shapeNam e) {
  284  
  285           va r shapeRow  = $(selec tedOption) .closest(' .komet-fla g-control- shape');
  286           va r shapeCla ssField =  shapeRow.f ind("#" +  shapeRow[0 ].dataset. idPrefix +  "_shape_c lass_" + s hapeRow[0] .dataset.i dPostfix);
  287           va r shapeNam eField = s hapeRow.fi nd("#" + s hapeRow[0] .dataset.i dPrefix +  "_shape_na me_" + sha peRow[0].d ataset.idP ostfix);
  288           va r shapeExa mpleField  = shapeRow .find("#"  + shapeRow [0].datase t.idPrefix  + "_shape _example_"  + shapeRo w[0].datas et.idPostf ix);
  289           va r shapeNam eExampleFi eld = shap eRow.find( "#" + shap eRow[0].da taset.idPr efix + "_s hape_name_ example_"  + shapeRow [0].datase t.idPostfi x);
  290  
  291           sh apeNameFie ld.val(sha peName);
  292           sh apeClassFi eld.val(FL AG_SHAPES[ shapeName] );
  293  
  294           sh apeExample Field.remo veClass();
  295           sh apeExample Field.addC lass("glyp hicon " +  FLAG_SHAPE S[shapeNam e]);
  296           sh apeNameExa mpleField. html(shape Name);
  297       }
  298  
  299       functi on addFlag RowTemplat e(flagCont rolID, tem plate){
  300           fl agControlR owTemplate s[flagCont rolID] = t emplate;
  301       }
  302  
  303       functi on addFlag Row(flagCo ntrolID, f ieldIDPref ix, fieldI DPostfix){
  304  
  305           va r controlR ow = $("#k omet_flag_ control_ad d_row_" +  flagContro lID);
  306           re movePageMe ssages(con trolRow);
  307  
  308           va r flagCont rolBody =  $("#komet_ flag_contr ol_body_"  + flagCont rolID);
  309           va r addItemI DField = $ ("#" + fie ldIDPrefix  + fieldID Postfix);
  310  
  311           if  ($("#kome t_flag_con trol_row_"  + addItem IDField.va l() + "_"  + flagCont rolID).len gth != 0){
  312  
  313                controlR ow.prepend (generateP ageMessage ("This ite m already  exists bel ow."));
  314                return f alse;
  315           }
  316  
  317           va r addItemD isplayFiel d = $("#"  + fieldIDP refix + "_ display" +  fieldIDPo stfix);
  318           va r newRow =  flagContr olRowTempl ates[flagC ontrolID];
  319           va r idRegEx  = new RegE xp('komet_ flag_templ ate_id', ' g');
  320           va r textRegE x = new Re gExp('kome t_flag_tem plate_text ', 'g');
  321  
  322           ne wRow = new Row.replac e(idRegEx,  addItemID Field.val( ));
  323           ne wRow = new Row.replac e(textRegE x, addItem DisplayFie ld.val());
  324  
  325           fl agControlB ody.append (newRow);
  326  
  327           va r addedRow  = $("#kom et_flag_co ntrol_row_ " + addIte mIDField.v al() + "_"  + flagCon trolID);
  328           in itFlagCont rols(added Row);
  329  
  330           ad dItemIDFie ld.val('') ;
  331           ad dItemDispl ayField.va l('');
  332  
  333       }
  334  
  335       // TOD O - add co nfirmation  dialog
  336       functi on deleteF lagRow(fla gRowID){
  337           $( "#komet_fl ag_control _row_" + f lagRowID). remove();
  338       }
  339  
  340       functi on getActi veTabId(ta bControlId ) {
  341           va r id = "#"  + tabCont rolId;
  342           va r idx = $( id).tabs(" option", " active");
  343           va r tabpages  = documen t.getEleme ntById(tab ControlId) .children;
  344  
  345           if  (idx >= 0  && idx <=  tabpages. length - 1 ) {
  346                //add on e to the i ndex becau se the fir st child i s the UL e lement for  the tab l abels. The  remaining  children  are the ta bpage divs
  347                return t abpages[pa rseInt(idx ) + 1].id;
  348           }
  349           re turn undef ined;
  350       }
  351  
  352       functi on isTabAc tive(tabCo ntrolId, t abpageId)  {
  353           va r tabpage  = getActiv eTabId(tab ControlId) ;
  354           re turn (tabp age !== un defined ?  (tabpage = == tabpage Id) : fals e);
  355       }
  356  
  357       functi on generat ePageMessa ge(message , isPageLe velMessage , messageT ype) {
  358  
  359           if  (messageT ype == und efined ||  messageTyp e == null  || !(messa geType ==  "success"  || message Type == "w arning"))  {
  360                messageT ype = "err or";
  361           }
  362  
  363           va r icon = ' <div class ="glyphico n glyphico n-alert" t itle="aler t message" ></div>';
  364  
  365           if  (messageT ype == "su ccess") {
  366                icon = ' <div class ="glyphico n glyphico n-ok-circl e" title=" success me ssage"></d iv>';
  367           }
  368  
  369           va r messageT ype = "kom et-page-"  + messageT ype;
  370           va r classLev el = "kome t-page-fie ld-message ";
  371  
  372           if  (isPageLe velMessage  != undefi ned && isP ageLevelMe ssage) {
  373                classLev el = "kome t-page-mes sage";
  374           }
  375  
  376           va r alertCon tainerID =  "komet_"  + window.p erformance .now().toS tring().re place(".",  "");
  377           va r alertMes sageID = " komet_" +  window.per formance.n ow().toStr ing().repl ace(".", " ");
  378  
  379           re turn '<div  id="' + a lertContai nerID + '"  class="'  + classLev el + ' ' +  messageTy pe + '" ro le="alert" >' + icon  + '<div id ="' + aler tMessageID  + '" clas s="komet-p age-messag e-containe r" tabinde x="0"></di v>'
  380                + '<div  class="kom et-flex-ri ght"><butt on type="b utton" cla ss="komet- link-butto n" title=" Remove mes sage" aria -label="Re move alert : ' + mess age + '" o nclick="UI Helper.foc usNextElem ent(); $(\ '#' + aler tContainer ID + '\'). remove();" ><div clas s="glyphic on glyphic on-remove" ></div></b utton></di v></div>'
  381                + '<scri pt>var ale rtMessage  = document .getElemen tById("' +  alertMess ageID + '" ); alertMe ssage.setA ttribute(" role", "al ert"); var  alertText  = documen t.createTe xtNode("'  + message  + '"); '
  382                + 'alert Message.ap pendChild( alertText) ; alertMes sage.style .display=" none"; ale rtMessage. style.disp lay="inlin e";</scrip t>';
  383       }
  384  
  385       functi on removeP ageMessage s(containe rElementOr Selector)  {
  386  
  387           va r element;
  388  
  389           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  390           if  (typeof c ontainerEl ementOrSel ector ===  "string")  {
  391                element  = $(contai nerElement OrSelector );
  392           }  else {
  393                element  = containe rElementOr Selector;
  394           }
  395  
  396           el ement.find (".komet-p age-messag e, .komet- page-field -message") .remove();
  397       }
  398  
  399       functi on focusNe xtElement( ) {
  400  
  401           // add all el ements we  want to in clude in o ur selecti on
  402           va r focusabl eElements  = 'a:not([ disabled]) , button:n ot([disabl ed]), inpu t:not([dis abled]), s elect:not( [disabled] ), [tabind ex]:not([d isabled]): not([tabin dex="-1"]) ';
  403  
  404           if  (document .activeEle ment && do cument.act iveElement .form) {
  405  
  406                var focu sable = Ar ray.protot ype.filter .call(docu ment.activ eElement.f orm.queryS electorAll (focusable Elements),
  407                    func tion (elem ent) {
  408                         //check fo r visibili ty while a lways incl ude the cu rrent acti veElement
  409                         return ele ment.offse tWidth > 0  || elemen t.offsetHe ight > 0 | | element  === docume nt.activeE lement
  410                    });
  411  
  412                var inde x = focusa ble.indexO f(document .activeEle ment);
  413                focusabl e[index +  1].focus() ;
  414           }
  415       }
  416  
  417       functi on generat eConfirmat ionDialog( title, mes sage, clos eCallback,  buttonTex t, positio ningElemen tOrSelecto r, formID)  {
  418  
  419           va r dialogID  = "komet_ generated_ confirm_di alog";
  420           va r body = $ ("body");
  421           va r position  = {my: "c enter", at : "center" , of: body };
  422           va r buttonCl icked = "c ancel";
  423           va r buttonTy pe = "butt on";
  424           va r dialogSt ring = '<d iv id="' +  dialogID  + '"><div  class="kom et-confima tion-dialo g-message" >' + messa ge + '</di v></div>';
  425  
  426           if  (buttonTe xt == unde fined || b uttonText  == null) {
  427                buttonTe xt = "Yes" ;
  428           }
  429  
  430           if  (position ingElement OrSelector  != undefi ned && pos itioningEl ementOrSel ector != n ull) {
  431  
  432                var elem ent;
  433  
  434                // If th e type of  the second  parameter  is a stri ng, then u se it as a  jquery se lector, ot herwise us e as is
  435                if (type of positio ningElemen tOrSelecto r === "str ing") {
  436                    elem ent = $(po sitioningE lementOrSe lector);
  437                } else {
  438                    elem ent = posi tioningEle mentOrSele ctor;
  439                }
  440  
  441                position  = {my: "r ight botto m", at: "l eft bottom ", of: ele ment};
  442           }
  443  
  444           if  (formID = = undefine d) {
  445                formID =  null;
  446           }  else {
  447                buttonTy pe = "subm it";
  448           }
  449  
  450           bo dy.prepend (dialogStr ing);
  451  
  452           //  create a  function t o put focu s on the f irst input  field
  453           va r onDialog Open = fun ction(){
  454                $("#" +  dialogID). find("inpu t:not(.hid e):first") .focus();
  455           };
  456  
  457           va r dialog =  $("#" + d ialogID);
  458  
  459           di alog.dialo g({
  460                beforeCl ose: funct ion () {
  461  
  462                    clos eCallback( buttonClic ked);
  463                    dial og.remove( );
  464                },
  465                open: fu nction ()  {
  466  
  467                    // u se setTime out becaus e the firs t field co uld be an  autosugges t that nee ds to get  built firs t.
  468                    setT imeout(onD ialogOpen,  50);
  469                },
  470                title: t itle,
  471                resizabl e: false,
  472                height:  "auto",
  473                width: 5 00,
  474                modal: t rue,
  475                position : position ,
  476                dialogCl ass: "kome t-confirma tion-dialo g komet-di alog-no-cl ose-button ",
  477                buttons:  {
  478                    Canc el: {
  479                         "class": " btn btn-de fault",
  480                         text: "Can cel",
  481                         click: fun ction () {
  482                             $(this ).dialog(" close");
  483                         }
  484                    },
  485                    OK:  {
  486                         text: butt onText,
  487                         "class": " btn btn-pr imary",
  488                         click: fun ction () {
  489  
  490                             button Clicked =  buttonText ;
  491                             $(this ).dialog(" close");
  492                         },
  493                         type: butt onType,
  494                         form: form ID
  495                    }
  496                }
  497           }) ;
  498  
  499           di alog.paren t().childr en().child ren(".ui-d ialog-titl ebar-close ").remove( );
  500       }
  501  
  502       // TOD O - Not ve ry useful  if showCha nges is tr ue
  503       functi on toggleC hangeHighl ights(cont ainerEleme ntOrSelect or, showCh anges) {
  504  
  505           va r element;
  506  
  507           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  508           if  (typeof c ontainerEl ementOrSel ector ===  "string")  {
  509                element  = $(contai nerElement OrSelector );
  510           }  else {
  511                element  = containe rElementOr Selector;
  512           }
  513  
  514           va r tags = e lement.fin d(".komet- changeable ");
  515  
  516           if  (showChan ges) {
  517                tags.add Class("kom et-highlig ht-changes ");
  518           }  else {
  519                tags.rem oveClass(" komet-high light-chan ges");
  520           }
  521       }
  522  
  523       // fun ction to s witch a fi eld betwee n enabled  and disabl ed
  524       functi on toggleF ieldAvaila bility(ele mentOrSele ctor, enab le) {
  525  
  526           va r element;
  527  
  528           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  529           if  (typeof e lementOrSe lector ===  "string")  {
  530                element  = $(elemen tOrSelecto r);
  531           }  else {
  532                element  = elementO rSelector;
  533           }
  534  
  535           if  (enable)  {
  536  
  537                element. removeClas s("ui-stat e-disabled ");
  538                element. prop("disa bled", fal se);
  539           }  else {
  540  
  541                element. addClass(" ui-state-d isabled");
  542                element. prop("disa bled", tru e);
  543           }
  544       }
  545  
  546       /*
  547        * has FormChange d - Check  to see if  there were  changes i n a form,  optionally  returning  the chang e details  and highli ghting the m.
  548        * @pa ram [objec t or strin g] formEle mentOrSele ctor - Eit her a jque ry object  or the cla ss or ID s elector (i ncluding t he "#" or  "." prefix ) that rep resents th e form to  search for  changes.
  549        * @pa ram [boole an] return Changes -  Should an  array of c hanges be  returned ( true), or  simply tru e/false (f alse). If  this and h ighlightCh anges
  550        *                                      are false  then the f unction wi ll only lo op until i t finds th e first ch ange. (Opt ional: def ault = fal se)
  551        * @pa ram [boole an] highli ghtChanges  - Should  changes be  highlight ed. Requir es the "ko met-change able" clas s on the e lements yo u want hig hlighted.  (Optional:  default =  false)
  552        * @re turn [arra y or boole an] - If r eturnChang es is true , returns  an array c ontaining  a hash of  each field s changes  ({field, o ldValue, n ewValue}),  otherwise  returns t rue or fal se.
  553        */
  554       functi on hasForm Changed(fo rmElementO rSelector,  returnCha nges, high lightChang es) {
  555  
  556           va r changes  = [];
  557           va r element;
  558  
  559           //  set the d efault val ue if this  optional  parameter  wasn't pas sed in
  560           if  (returnCh anges == u ndefined)  {
  561                returnCh anges = fa lse;
  562           }
  563  
  564           //  set the d efault val ue if this  optional  parameter  wasn't pas sed in
  565           if  (highligh tChanges = = undefine d) {
  566                highligh tChanges =  false;
  567           }
  568  
  569           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  570           if  (typeof f ormElement OrSelector  === "stri ng") {
  571                element  = $(formEl ementOrSel ector);
  572           }  else {
  573                element  = formElem entOrSelec tor;
  574           }
  575  
  576           //  remove cu rrent high lights
  577           UI Helper.tog gleChangeH ighlights( element, f alse);
  578  
  579           //  find all  non-hidden  form fiel ds and loo p through  them
  580           el ement.find (":input:n ot(:button ):not([typ e=hidden]) ").each(fu nction ()  {
  581  
  582                // store  the name  of the fie ld, and tw o empty ar rays we ca n easily c heck later  to see if  changes w ere found
  583                // doing  it this w ay allows  for less c ode in the  select bo x section
  584                var fiel d = {field : this.nam e, oldValu e: [], new Value: []} ;
  585  
  586                // if th e field is  a text fi eld and th e old valu e and new  value dont  match sto re the cha nges
  587                if ((thi s.type ==  "text" ||  this.type  == "textar ea") && th is.default Value != t his.value)  {
  588  
  589                    fiel d = {field : this.nam e, oldValu e: this.de faultValue , newValue : this.val ue};
  590  
  591                // if th e field is  a radio o r checkbox  and the o ld value a nd new val ue dont ma tch store  the change s, includi ng the typ e because  it could b e part of  a field gr oup
  592                } else i f ((this.t ype == "ra dio" || th is.type ==  "checkbox ") && this .defaultCh ecked != t his.checke d) {
  593  
  594                    fiel d = {field : this.nam e, oldValu e: this.de faultCheck ed, newVal ue: this.c hecked, ty pe: this.t ype};
  595  
  596                // if th e field is  a select  box
  597                } else i f ((this.t ype == "se lect-one"  || this.ty pe == "sel ect-multip le")) {
  598  
  599                    // l oop throug h the sele ct's optio ns
  600                    for  (var i = 0 ; i < this .length; i ++) {
  601  
  602                         // if the  option's o ld selecte d value an d new sele cted value  dont matc h store th e changes
  603                         if (this.o ptions[i]. selected ! = this.opt ions[i].de faultSelec ted) {
  604  
  605                             // if  this is a  single sel ection sel ect box
  606                             if (th is.type ==  "select-o ne") {
  607  
  608                                 //  if the ol d selected  value was  true then  this is t he old val ue, otherw ise it's t he new val ue
  609                                 if  (this.opt ions[i].de faultSelec ted) {
  610                                      field.ol dValue = t his.option s[i].value ;
  611                                 }  else {
  612  
  613                                      field.ne wValue = t his.option s[i].value ;
  614  
  615                                      // if th e old valu e is still  an empty  array, set  it to an  empty stri ng, becaus e it may h ave never  had a valu e selected
  616                                      if (type of field.o ldValue ==  "object")  {
  617                                          fiel d.oldValue  = "";
  618                                      }
  619                                 }
  620  
  621                             } else  {
  622  
  623                                 //  if this i s a multi  selection  select box  then we n eed to sto re values  as an arra y
  624                                 //  if the ol d selected  value was  true then  this is t he old val ue, otherw ise it's t he new val ue
  625                                 if  (this.opt ions[i].de faultSelec ted) {
  626                                      field.ol dValue.pus h(this.opt ions[i].va lue);
  627                                 }  else {
  628                                      field.ne wValue.pus h(this.opt ions[i].va lue);
  629                                 }
  630                             }
  631                         }
  632                    }
  633                }
  634  
  635                // check  to see if  field's n ew value i s an empty  array. If  it isn't  then the f ield chang ed
  636                if (!(ty peof field .oldValue  == "object " && field .oldValue. length ===  0 && type of field.n ewValue ==  "object"  && field.n ewValue.le ngth === 0 )) {
  637  
  638                    // i f we are n ot returni ng the arr ay of chan ges or hig hlighting  them, then  we can st op looping  and retur n true
  639                    if ( !returnCha nges && !h ighlightCh anges) {
  640                         changes.pu sh(field);
  641                         return fal se;
  642                    }
  643  
  644                    // a dd the fie ld to the  changes ar ray
  645                    chan ges.push(f ield);
  646  
  647                    // i f we are h ighlightin g changes  then find  the neares t element  with the c hangeable  class, and  add the h ightlight  class
  648                    if ( highlightC hanges) {
  649                         $(this).cl osest(".ko met-change able").add Class("kom et-highlig ht-changes ");
  650                    }
  651                }
  652           }) ;
  653  
  654           //  if we are  not retur ning the a rray of ch anges then  check to  see if the re were ch anges
  655           if  (!returnC hanges) {
  656  
  657                if (chan ges.length  > 0) {
  658                    retu rn true;
  659                } else {
  660                    retu rn false;
  661                }
  662           }
  663  
  664           //  return th e array of  changes
  665           re turn chang es;
  666       }
  667  
  668       functi on resetFo rmChanges( formIdOrCl ass) {
  669  
  670           $( formIdOrCl ass + " :i nput:not(: button):no t([type=hi dden])").e ach(functi on () {
  671  
  672                if (this .type == " text" || t his.type = = "textare a" || this .type == " hidden") {
  673                    this .value = t his.defaul tValue;
  674  
  675                } else i f (this.ty pe == "rad io" || thi s.type ==  "checkbox" ) {
  676                    this .checked =  this.defa ultChecked ;
  677  
  678                } else i f (this.ty pe == "sel ect-one" | | this.typ e == "sele ct-multipl e") {
  679  
  680                    for  (var x = 0 ; x < this .length; x ++) {
  681                         this.optio ns[x].sele cted = thi s.options[ x].default Selected;
  682                    }
  683                }
  684           }) ;
  685       }
  686  
  687       functi on acceptF ormChanges (formEleme ntOrSelect or) {
  688  
  689           va r element;
  690  
  691           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  692           if  (typeof f ormElement OrSelector  === "stri ng") {
  693                element  = $(formEl ementOrSel ector);
  694           }  else {
  695                element  = formElem entOrSelec tor;
  696           }
  697  
  698           el ement.find (":input:n ot(:button ):not([typ e=hidden]) ").each(fu nction ()  {
  699  
  700                if (this .type == " text" || t his.type = = "textare a" || this .type == " hidden") {
  701                    this .defaultVa lue = this .value;
  702                }
  703                if (this .type == " radio" ||  this.type  == "checkb ox") {
  704                    this .defaultCh ecked = th is.checked ;
  705                }
  706                if (this .type == " select-one " || this. type == "s elect-mult iple") {
  707                    for  (var x = 0 ; x < this .length; x ++) {
  708                         this.optio ns[x].defa ultSelecte d = this.o ptions[x]. selected
  709                    }
  710                }
  711           }) ;
  712       }
  713  
  714       var fi ndInArray  = function  (arrayToS earch, ite msToFind)  {
  715           re turn items ToFind.som e(function  (value) {
  716                return a rrayToSear ch.indexOf (value) >=  0;
  717           }) ;
  718       };
  719  
  720       var cr eateAutoSu ggestField  = functio n (fieldID Base, fiel dIDPostfix , label, l abelDispla y, name, n ameFormat,  idValue,  displayVal ue, termin oloyTypes,  fieldClas ses, tabIn dex) {
  721  
  722           if  (fieldIDP ostfix ==  null) {
  723                fieldIDP ostfix = " ";
  724           }
  725  
  726           va r labelTag  = "";
  727           va r caption  = "";
  728  
  729           if  (label !=  null) {
  730  
  731                caption  = ' aria-l abel="' +  label + '"  ';
  732  
  733                if (labe lDisplay = = null ||  labelDispl ay == 'lab el') {
  734                    labe lTag = '<l abel for=" ' + fieldI DBase + '_ display' +  fieldIDPo stfix + '" >' + label  + '</labe l>';
  735  
  736                } else i f (labelDi splay == ' tooltip')  {
  737                    capt ion += 'ti tle="' + l abel + '"  ';
  738  
  739                } else {
  740                    capt ion += 'pl aceholder= "' + label  + '" ';
  741                }
  742  
  743           }
  744  
  745           va r idName =  fieldIDBa se;
  746           va r typeName  = fieldID Base + "_t ype";
  747           va r displayN ame = fiel dIDBase +  "_display" ;
  748  
  749           if  (name !=  null) {
  750  
  751                if (name Format ==  "array") {
  752  
  753                    idNa me = name  + "]";
  754                    type Name = nam e + "_type ]";
  755                    disp layName =  name + "_d isplay]";
  756  
  757                } else {
  758  
  759                    idNa me = name;
  760                    type Name = nam e + "_type ";
  761                    disp layName =  name + "_d isplay";
  762                }
  763           }
  764  
  765           if  (idValue  == null) {
  766                idValue  = "";
  767           }
  768  
  769           if  (displayV alue == nu ll) {
  770                displayV alue = "";
  771           }
  772  
  773           if  (terminol oyTypes ==  null) {
  774                terminol oyTypes =  "";
  775           }
  776  
  777           if  (fieldCla sses == nu ll) {
  778                fieldCla sses = "";
  779           }
  780  
  781           va r fieldTab Index = ""
  782           va r recentsT abIndex =  ""
  783  
  784           if  (tabIndex  != null)  {
  785  
  786                fieldTab Index = '  tabindex=" ' + tabInd ex + '"';
  787                recentsT abIndex =  ' tabindex ="' + (tab Index + 1)  + '"';
  788           }
  789  
  790           //  use the h ide class  to hide th e ID and T ype fields  so that t he hasForm Changed()  function c an pick up  the chang ed values.
  791           //  add type= hidden to  inputs wit h class=hi dden.
  792           va r fieldStr ing = labe lTag
  793                + '<inpu t type="hi dden" id=" ' + fieldI DBase + fi eldIDPostf ix + '" na me="' + id Name + '"  class="hid e" value=" ' + idValu e + '">'
  794                + '<inpu t type="hi dden" id=" ' + fieldI DBase + '_ terminolog y_types' +  fieldIDPo stfix + '"  name="' +  typeName  + '" class ="hide" va lue="' + t erminoloyT ypes + '"> '
  795                + '<div  id="' + fi eldIDBase  + '_fields ' + fieldI DPostfix +  '" class= "komet-aut osuggest i nput-group  ' + field Classes +  '">'
  796                + '<inpu t id="' +  fieldIDBas e + '_disp lay' + fie ldIDPostfi x + '" nam e="' + dis playName +  '" ' + ca ption + '  class="for m-control  komet-cont ext-menu"  '
  797                + 'data- menu-type= "paste_tar get" data- menu-id-fi eld="' + f ieldIDBase  + fieldID Postfix +  '" data-me nu-display -field="'  + fieldIDB ase + '_di splay' + f ieldIDPost fix + '" '
  798                + 'data- menu-taxon omy-type-f ield="' +  fieldIDBas e + '_type ' + fieldI DPostfix +  '" value= "' + displ ayValue +  '"' + fiel dTabIndex  + '>'
  799                + '<div  id="' + fi eldIDBase  + '_recent s_button'  + fieldIDP ostfix + ' "  class=" input-grou p-btn kome t-search-c ombo-field ">'
  800                + '<butt on type="b utton" cla ss="btn bt n-default  dropdown-t oggle" dat a-toggle=" dropdown"  aria-label ="Select '  + display Name + '"  aria-haspo pup="true"  aria-expa nded="fals e"><span c lass="care t"></span> </button>'
  801                + '<ul i d="' + fie ldIDBase +  '_recents ' + fieldI DPostfix +  '" class= "dropdown- menu dropd own-menu-r ight"' + r ecentsTabI ndex + '>< /ul>'
  802                + '</div ></div>';
  803  
  804           //  create an d return a  dom fragm ent from t he field s tring
  805           re turn docum ent.create Range().cr eateContex tualFragme nt(fieldSt ring);
  806       };
  807  
  808       var pr ocessAutoS uggestTags  = functio n (contain erElementO rSelector)  {
  809  
  810           va r element;
  811  
  812           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  813           if  (typeof c ontainerEl ementOrSel ector ===  "string")  {
  814                element  = $(contai nerElement OrSelector );
  815           }  else {
  816                element  = containe rElementOr Selector;
  817           }
  818  
  819           va r tags = $ (element). find("auto suggest");
  820  
  821           ta gs.each(fu nction (i,  tag) {
  822  
  823                var fiel dIDBase =  tag.getAtt ribute("id -base");
  824                var fiel dIDPostfix  = tag.get Attribute( "id-postfi x");
  825                var labe l = tag.ge tAttribute ("label");
  826                var labe lDisplay =  tag.getAt tribute("l abel-displ ay");
  827                var name  = tag.get Attribute( "name");
  828                var name Format = t ag.getAttr ibute("nam e-format") ;
  829                var idVa lue = tag. getAttribu te("value" );
  830                var disp layValue =  tag.getAt tribute("d isplay-val ue");
  831                var term inologyTyp es = tag.g etAttribut e("termino logy-types ");
  832                var fiel dClasses =  tag.getAt tribute("c lasses");
  833                var tabI ndex = tag .getAttrib ute("tab-i ndex");
  834                var sugg estionRest Variable =  tag.getAt tribute("s uggestion- rest-varia ble");
  835                var rece ntsRestVar iable = ta g.getAttri bute("rece nts-rest-v ariable");
  836                var useR ecentsCach e = tag.ge tAttribute ("use-rece nts-cache" );
  837                var char acterTrigg erLimit =  tag.getAtt ribute("ch aracter-tr igger-limi t");
  838                var rest rictSearch  = tag.get Attribute( "restrict- search");
  839                var view Params = t ag.getAttr ibute("vie w_params") ;
  840  
  841                if (fiel dIDPostfix  == null)  {
  842                    fiel dIDPostfix  = "";
  843                }
  844  
  845                if (sugg estionRest Variable = = null) {
  846                    sugg estionRest Variable =  "komet_da shboard_ge t_concept_ suggestion s_path";
  847                }
  848  
  849                if (char acterTrigg erLimit ==  null) {
  850                    char acterTrigg erLimit =  1;
  851                }
  852  
  853                if (rest rictSearch  == null)  {
  854                    rest rictSearch  = "";
  855                }
  856  
  857                var auto Suggest =  UIHelper.c reateAutoS uggestFiel d(fieldIDB ase, field IDPostfix,  label, la belDisplay , name, na meFormat,  idValue, d isplayValu e, termino logyTypes,  fieldClas ses, tabIn dex);
  858  
  859                $(tag).r eplaceWith (autoSugge st);
  860  
  861                var disp layField =  $("#" + f ieldIDBase  + "_displ ay" + fiel dIDPostfix );
  862  
  863                displayF ield.autoc omplete({
  864                    sour ce: gon.ro utes[sugge stionRestV ariable] +  '?restric t_search='  + restric tSearch +  '&' + jQue ry.param({ view_param s: viewPar ams}),
  865                    minL ength: cha racterTrig gerLimit,
  866                    sele ct: onAuto SuggestSel ection
  867                    , ch ange: onAu toSuggestC hange(char acterTrigg erLimit)
  868                });
  869  
  870                displayF ield.data( "ui-autoco mplete")._ renderItem  = functio n (ul, ite m) {
  871  
  872                    var  matchingTe xt = "";
  873  
  874                    if ( item.label  != item.m atching_te xt){
  875                         matchingTe xt = " (Ma tching Tex t: " + ite m.matching _text + ") ";
  876                    }
  877  
  878                    var  li = $('<l i class="u i-menu-ite m">' + ite m.label +  matchingTe xt + '</li >').data(' ui-autocom plete-item ', item);
  879                    retu rn ul.appe nd(li);
  880                };
  881  
  882                var rece ntsButton  = $("#" +  fieldIDBas e + "_rece nts_button " + fieldI DPostfix);
  883  
  884                recentsB utton.on(' show.bs.dr opdown', f unction ()  {
  885  
  886                    var  menu = $(" #" + field IDBase + " _recents"  + fieldIDP ostfix);
  887                    menu .css("posi tion", "fi xed");
  888                    menu .css("top" , recentsB utton.offs et().top +  recentsBu tton.heigh t());
  889                    menu .css("righ t", getEle mentRightF romWindow( recentsBut ton));
  890                }.bind(t his));
  891  
  892                var this Helper = t his;
  893  
  894                recentsD ropdown =  $("#" + fi eldIDBase  + "_recent s" + field IDPostfix) ;
  895  
  896                // TODO  - Switch t o using th is event s o we can t rigger men u reloadin g easily
  897                recentsD ropdown.on ("recents: load", {re stVariable : recentsR estVariabl e, useRece ntsCache:  useRecents Cache, rec entsName:  restrictSe arch}, fun ction(even t) {
  898  
  899                    if ( event.data .useRecent sCache ==  null){
  900                         event.data .useRecent sCache = t rue;
  901                    }
  902  
  903                    // u se the rec ents cache  if it exi sts
  904                    if ( event.data .useRecent sCache &&  thisHelper .autoSugge stRecentCa che[event. data.recen tsName] !=  null){
  905  
  906                         $(this).ht ml(thisHel per.autoSu ggestRecen tCache[eve nt.data.re centsName] );
  907                         return;
  908                    }
  909  
  910                    if ( event.data .restVaria ble == nul l) {
  911                         event.data .restVaria ble = "kom et_dashboa rd_get_con cept_recen ts_path";
  912                    }
  913  
  914                    $.ge t(gon.rout es[event.d ata.restVa riable] +  '?recents_ name=' + e vent.data. recentsNam e, functio n (data) {
  915  
  916                         var option s = "";
  917  
  918                         $.each(dat a, functio n (index,  value) {
  919  
  920                             var au toSuggestI DField = t his.id.rep lace("_rec ents", "") ;
  921                             var au toSuggestD isplayFiel d = this.i d.replace( "_recents" , "_displa y");
  922                             var au toSuggestT erminology TypesField  = this.id .replace(" _recents",  "_termino logy_types ");
  923  
  924                             // use  the html  function t o escape a ny html th at may hav e been ent ered by th e user
  925                             var va lueText =  $("<li>"). text(value .text).htm l();
  926  
  927                             // TOD O - remove  this reas signment w hen the ty pe flags a re impleme nted in th e REST API s
  928                             value. terminolog y_types =  UIHelper.V HAT;
  929  
  930                             option s += '<li> <a style=" cursor: de fault"  on click=\'UI Helper.use AutoSugges tRecent("'  + autoSug gestIDFiel d + '", "'  + autoSug gestDispla yField + ' ", "' + au toSuggestT erminology TypesField  + '"'
  931                                 +  ', "' + va lue.id + ' ", "' + va lueText +  '", "' + v alue.type  + '")\'>'  + valueTex t + '</a>< /li>';
  932                         }.bind(thi s));
  933  
  934                         $(this).ht ml(options );
  935  
  936                         if (event. data.useRe centsCache ) {
  937                             thisHe lper.autoS uggestRece ntCache[ev ent.data.r ecentsName ] = option s;
  938                         }
  939  
  940                    }.bi nd(this));
  941                });
  942  
  943                // recen tsDropdown .trigger(" recents:lo ad");
  944  
  945                if (defe rredRecent sCalls &&  deferredRe centsCalls .state() = = "pending "){
  946  
  947                    defe rredRecent sCalls.don e(function (){
  948                         loadAutoSu ggestRecen ts(fieldID Base + "_r ecents" +  fieldIDPos tfix, rece ntsRestVar iable, use RecentsCac he, restri ctSearch);
  949                    }.bi nd(this));
  950  
  951                } else {
  952                    load AutoSugges tRecents(f ieldIDBase  + "_recen ts" + fiel dIDPostfix , recentsR estVariabl e, useRece ntsCache,  restrictSe arch);
  953                }
  954           }) ;
  955       };
  956  
  957       var on AutoSugges tSelection  = functio n (event,  ui) {
  958  
  959           va r labelFie ld = $(thi s);
  960           la belField.v al(ui.item .label);
  961           la belField.c hange();
  962  
  963           va r idField  = $("#" +  this.id.re place("_di splay", "" ));
  964           id Field.val( ui.item.va lue);
  965           id Field.chan ge();
  966  
  967           va r terminol ogyTypesFi eld = $("# " + this.i d.replace( "_display" , "_termin ology_type s"));
  968           te rminologyT ypesField. val(ui.ite m.terminol ogy_types) ;
  969           te rminologyT ypesField. change();
  970  
  971           re turn false ;
  972       };
  973  
  974       var on AutoSugges tChange =  function ( characterT riggerLimi t) {
  975  
  976           re turn funct ion (event , ui) {
  977  
  978                if (this .value.len gth == 0 | | (this.va lue.length  >= charac terTrigger Limit && ! ui.item))  {
  979  
  980                    var  idField =  $("#" + th is.id.repl ace("_disp lay", "")) ;
  981                    idFi eld.val("" );
  982                    idFi eld.change ();
  983  
  984                    var  terminolog yTypesFiel d = $("#"  + this.id. replace("_ display",  "_terminol ogy_types" ));
  985                    term inologyTyp esField.va l("");
  986                    term inologyTyp esField.ch ange();
  987  
  988                    // m ake sure t his is las t, as ther e may be a n onchange  event on  the displa y field th at require s the othe r fields t o be set.
  989                    var  labelField  = $(this) ;
  990                    labe lField.val ("");
  991                    labe lField.cha nge();
  992                }
  993           };
  994       };
  995  
  996       var lo adAutoSugg estRecents  = functio n (recents ID, restVa riable, us eRecentsCa che, recen tsName) {
  997  
  998           de ferredRece ntsCalls =  $.Deferre d();
  999  
  1000           if  (useRecen tsCache ==  null){
  1001                useRecen tsCache =  true;
  1002           }
  1003  
  1004           //  use the r ecents cac he if it e xists
  1005           if  (useRecen tsCache &&  autoSugge stRecentCa che[recent sName] !=  null){
  1006  
  1007                $("#" +  recentsID) .html(auto SuggestRec entCache[r ecentsName ]);
  1008                deferred RecentsCal ls.resolve ();
  1009                return;
  1010           }
  1011  
  1012           if  (restVari able == nu ll) {
  1013                restVari able = "ko met_dashbo ard_get_co ncept_rece nts_path";
  1014           }
  1015  
  1016           $. get(gon.ro utes[restV ariable] +  '?recents _name=' +  recentsNam e, functio n (data) {
  1017  
  1018                var opti ons = "";
  1019  
  1020                $.each(d ata, funct ion (index , value) {
  1021  
  1022                    var  autoSugges tIDField =  recentsID .replace(" _recents",  "");
  1023                    var  autoSugges tDisplayFi eld = rece ntsID.repl ace("_rece nts", "_di splay");
  1024                    var  autoSugges tTerminolo gyTypesFie ld = recen tsID.repla ce("_recen ts", "_ter minology_t ypes");
  1025  
  1026                    // u se the htm l function  to escape  any html  that may h ave been e ntered by  the user
  1027                    var  valueText  = $("<li>" ).text(val ue.text).h tml();
  1028  
  1029                    // T ODO - remo ve this re assignment  when the  type flags  are imple mented in  the REST A PIs
  1030                    valu e.terminol ogy_types  = UIHelper .VHAT;
  1031  
  1032                    opti ons += '<l i><a style ="cursor:  default"   onclick=\' UIHelper.u seAutoSugg estRecent( "' + autoS uggestIDFi eld + '",  "' + autoS uggestDisp layField +  '", "' +  autoSugges tTerminolo gyTypesFie ld + '"'
  1033                         + ', "' +  value.id +  '", "' +  valueText  + '", "' +  value.typ e + '")\'> ' + valueT ext + '</a ></li>';
  1034                });
  1035  
  1036                $("#" +  recentsID) .html(opti ons);
  1037  
  1038                if (useR ecentsCach e) {
  1039  
  1040                    auto SuggestRec entCache[r ecentsName ] = option s;
  1041                    defe rredRecent sCalls.res olve();
  1042                }
  1043  
  1044           }) ;
  1045       };
  1046  
  1047       var cl earAutoSug gestRecent Cache = fu nction (na me){
  1048  
  1049           if  (name ==  undefined  || name ==  null){
  1050                autoSugg estRecentC ache = {};
  1051           }  else {
  1052                delete a utoSuggest RecentCach e[name];
  1053           }
  1054       };
  1055  
  1056       var us eAutoSugge stRecent =  function  (autoSugge stID, auto SuggestDis playField,  autoSugge stTerminol ogyTypesFi eld, id, t ext, termi nologyType s) {
  1057  
  1058           va r idField  = $("#" +  autoSugges tID);
  1059           id Field.val( id);
  1060           id Field.chan ge();
  1061  
  1062           va r terminol ogyTypesFi eld = $("# " + autoSu ggestTermi nologyType sField);
  1063           te rminologyT ypesField. val(termin ologyTypes );
  1064           te rminologyT ypesField. change();
  1065  
  1066           //  make sure  this is l ast, as th ere may be  an onchan ge event o n the disp lay field  that requi res the ot her fields  to be set .
  1067           va r displayF ield = $(" #" + autoS uggestDisp layField);
  1068           di splayField .val(text) ;
  1069           di splayField .change();
  1070  
  1071       };
  1072  
  1073       var cr eateSelect FieldStrin g = functi on(selectI D, selectN ame, class es, option s, selecte dItem, lab el, create EmptyOptio n, display OptionTool tips) {
  1074  
  1075           if  (createEm ptyOption  == null ||  createEmp tyOption = = undefine d){
  1076                createEm ptyOption  = false;
  1077           }
  1078  
  1079           if  (displayO ptionToolt ips == nul l || displ ayOptionTo oltips ==  undefined) {
  1080                displayO ptionToolt ips = fals e;
  1081           }
  1082  
  1083           va r fieldStr ing = '<se lect id="'  + selectI D + '"'
  1084                + ' name ="' + sele ctName + ' "'
  1085                + ' clas s="form-co ntrol ' +  classes +  '"'
  1086                + ((labe l) ? (' ar ia-label=" ' + label)  + '"' : ' ')
  1087                + '>';
  1088  
  1089           //  create an  empty opt ion tag if  that was  specified
  1090           if  (createEm ptyOption) {
  1091  
  1092                fieldStr ing += '<o ption ';
  1093  
  1094                // make  sure to se lect it if  there was  no value  for the fi eld, other wise the d irty form  check will  get trigg ered
  1095                if (sele ctedItem = = null ||  selectedIt em.toStrin g() == "")  {
  1096                    fiel dString +=  'selected ="selected " ';
  1097                }
  1098  
  1099                fieldStr ing += 'va lue=""></o ption>';
  1100           }
  1101  
  1102           fo r (var i =  0; i < op tions.leng th; i++) {
  1103  
  1104                fieldStr ing += '<o ption ';
  1105  
  1106                if (disp layOptionT ooltips){
  1107                    fiel dString +=  'title="'  + options [i].toolti p + '" ';
  1108                }
  1109  
  1110                if (sele ctedItem ! = null &&  selectedIt em.toStrin g().toLowe rCase() ==  options[i ].value.to String().t oLowerCase ()) {
  1111                    fiel dString +=  'selected ="selected " ';
  1112                }
  1113  
  1114                fieldStr ing += 'va lue="' + o ptions[i]. value + '" >' + optio ns[i].labe l + '</opt ion>';
  1115           }
  1116  
  1117           fi eldString  += '</sele ct>';
  1118  
  1119           re turn field String;
  1120       };
  1121  
  1122       var ge tPreDefine dOptionsFo rSelect =  function(t ype){
  1123  
  1124           if  (type ==  "yes_no"){
  1125                return [ {value: "y es", label : "Yes"},  {value: "n o", label:  "No"}];
  1126           }  else if (t ype == "tr ue_false")  {
  1127                return [ {value: "t rue", labe l: "True"} , {value:  "false", l abel: "Fal se"}];
  1128           }  else if (t ype == "ac tive_inact ive") {
  1129                return [ {value: "a ctive", la bel: "Acti ve"}, {val ue: "inact ive", labe l: "Inacti ve"}];
  1130           }
  1131       };
  1132  
  1133       var ge tElementRi ghtFromWin dow = func tion(eleme ntOrSelect or){
  1134  
  1135           va r element;
  1136  
  1137           //  If the ty pe of the  first para meter is a  string, t hen use it  as a jque ry selecto r, otherwi se use as  is
  1138           if  (typeof e lementOrSe lector ===  "string")  {
  1139                element  = $(elemen tOrSelecto r);
  1140           }  else {
  1141                element  = elementO rSelector;
  1142           }
  1143  
  1144           if  (element. length > 0 ) {
  1145                return ( $(window). width() -  (element.o ffset().le ft + eleme nt.outerWi dth()));
  1146           }  else {
  1147                return n ull;
  1148           }
  1149       };
  1150  
  1151       functi on getView Params(jsO bject) {
  1152  
  1153           if  (jsObject  == "taxon omy"){
  1154                return T axonomyMod ule.getVie wParams();
  1155  
  1156           }  else if (j sObject ==  "mapping" ){
  1157                return M appingModu le.getView Params();
  1158  
  1159           }  else if (j sObject ==  "search") {
  1160                return n ull;
  1161  
  1162           }  else {
  1163                return W indowManag er.viewers [jsObject] .getViewPa rams();
  1164           }
  1165       }
  1166  
  1167       // TOD O - Fix z- index of m enus in IE  - splitte r bars cut ting throu gh it
  1168       functi on initial izeContext Menus() {
  1169  
  1170           $. contextMen u({
  1171                selector : '.komet- context-me nu',
  1172                events:  {
  1173                    show : function  (opt) {
  1174                         // show ev ent is exe cuted ever y time the  menu is s hown!
  1175                         // find al l clickabl e commands  and set t heir title -attribute
  1176                         // to thei r textCont ent value
  1177                         opt.$menu. find('.con text-menu- item > spa n').attr(' title', fu nction ()  {
  1178                             return  $(this).t ext();
  1179                         });
  1180                    }
  1181                },
  1182                build: f unction ($ triggerEle ment, e) {
  1183  
  1184                    var  items = {} ;
  1185                    var  menuType =  $triggerE lement.att r("data-me nu-type");
  1186  
  1187                    if ( menuType = = "sememe"  || menuTy pe == "con cept" || m enuType ==  "map_set" ) {
  1188  
  1189                         var uuid =  $triggerE lement.att r("data-me nu-uuid");
  1190                         var concep tText = $t riggerElem ent.attr(" data-menu- concept-te xt");
  1191                         var concep tTerminolo gyTypes =  $triggerEl ement.attr ("data-men u-concept- terminolog y-type");
  1192                         var concep tState = $ triggerEle ment.attr( "data-menu -state");
  1193                         var jsObje ct = $trig gerElement .attr("dat a-menu-js- object");
  1194                         var unlink edViewerID  = WindowM anager.get UnlinkedVi ewerID();
  1195  
  1196                         if (concep tText == u ndefined | | conceptT ext == "")  {
  1197                             concep tText = nu ll;
  1198                         }
  1199  
  1200                         if (concep tState ==  undefined  || concept State == " ") {
  1201                             concep tState = n ull;
  1202                         }
  1203  
  1204                         if (concep tTerminolo gyTypes ==  undefined  || concep tTerminolo gyTypes ==  "") {
  1205                             concep tTerminolo gyTypes =  null;
  1206                         }
  1207  
  1208                         items.open Concept =  {
  1209                             name:  "Open Conc ept",
  1210                             icon:  "context-m enu-icon g lyphicon-l ist-alt",
  1211                             callba ck: openCo ncept($tri ggerElemen t, uuid, j sObject)
  1212                         };
  1213  
  1214                         if (Window Manager.vi ewers.inli neViewers. length < W indowManag er.viewers .maxInline Viewers) {
  1215  
  1216                             items. openNewCon ceptViwer  = {
  1217                                 na me: "Open  in New Con cept Viewe r",
  1218                                 ic on: "conte xt-menu-ic on glyphic on-list-al t",
  1219                                 ca llback: op enConcept( $triggerEl ement, uui d, jsObjec t, WindowM anager.NEW , WindowMa nager.NEW)
  1220                             };
  1221                         }
  1222  
  1223                         if (Window Manager.vi ewers.inli neViewers. length > 1 ) {
  1224  
  1225                             items. openUnlink edConceptV iwer = {
  1226                                 na me: "Open  in Unlinke d Concept  Viewer",
  1227                                 ic on: "conte xt-menu-ic on glyphic on-list-al t",
  1228                                 ca llback: op enConcept( $triggerEl ement, uui d, jsObjec t, unlinke dViewerID)
  1229                             };
  1230                         }
  1231  
  1232                         //items.op enConceptN ewWindow =  {name:"Op en in New  Window", i con: "cont ext-menu-i con glyphi con-list-a lt", callb ack: openC oncept($tr iggerEleme nt, uuid,  "popup")};
  1233  
  1234                         if (menuTy pe == "map _set") {
  1235  
  1236                             items. separatorM apping = { type: "cm_ separator" };
  1237  
  1238                             items. openMapSet  = {
  1239                                 na me: "Open  Mapping",
  1240                                 ic on: "conte xt-menu-ic on glyphic on-list-al t",
  1241                                 ca llback: op enMapSet($ triggerEle ment, uuid , jsObject )
  1242                             };
  1243  
  1244                             if (Wi ndowManage r.viewers. inlineView ers.length  < WindowM anager.vie wers.maxIn lineViewer s) {
  1245  
  1246                                 it ems.openNe wMappingVi wer = {
  1247                                      name: "O pen in New  Mapping V iewer",
  1248                                      icon: "c ontext-men u-icon gly phicon-lis t-alt",
  1249                                      callback : openMapS et($trigge rElement,  uuid, jsOb ject, Wind owManager. NEW, Windo wManager.N EW)
  1250                                 };
  1251                             }
  1252  
  1253                             if (Wi ndowManage r.viewers. inlineView ers.length  > 1) {
  1254  
  1255                                 it ems.openUn linkedMapp ingViwer =  {
  1256                                      name: "O pen in Unl inked Mapp ing Viewer ",
  1257                                      icon: "c ontext-men u-icon gly phicon-lis t-alt",
  1258                                      callback : openMapS et($trigge rElement,  uuid, jsOb ject, unli nkedViewer ID)
  1259                                 };
  1260                             }
  1261                         }
  1262  
  1263                         items.sepa ratorCopy  = {type: " cm_separat or"};
  1264  
  1265                         if (concep tText != n ull && con ceptTermin ologyTypes  != null)  {
  1266                             items. copyConcep t = {
  1267                                 na me: "Copy  Concept",
  1268                                 ic on: "conte xt-menu-ic on glyphic on-copy",
  1269                                 ca llback: co pyConcept( uuid, conc eptText, c onceptTerm inologyTyp es)
  1270                             };
  1271                         }
  1272  
  1273                         items.copy Uuid = {
  1274                             name:  "Copy UUID ",
  1275                             icon:  "context-m enu-icon g lyphicon-c opy",
  1276                             callba ck: copyTo Clipboard( uuid)
  1277                         };
  1278  
  1279                         // check t he dynaimc  role meth ods to see  if the us er can edi t concepts
  1280                         if (RolesM odule.can_ edit_conce pt()) {
  1281  
  1282                             items. separatorC onceptEdit or = {type : "cm_sepa rator"};
  1283  
  1284                             items. editConcep t = {
  1285                                 na me: "Edit  Concept",
  1286                                 ic on: "conte xt-menu-ic on glyphic on-pencil" ,
  1287                                 ca llback: op enConceptE ditor($tri ggerElemen t, Concept sModule.ED IT, uuid,  jsObject)
  1288                             };
  1289  
  1290                             if (Wi ndowManage r.viewers. inlineView ers.length  < WindowM anager.vie wers.maxIn lineViewer s) {
  1291  
  1292                                 it ems.editCo nceptNewVi ewer = {
  1293                                      name: "E dit Concep t in New V iewer",
  1294                                      icon: "c ontext-men u-icon gly phicon-pen cil",
  1295                                      callback : openConc eptEditor( $triggerEl ement, Con ceptsModul e.EDIT, uu id, jsObje ct, Window Manager.NE W, WindowM anager.NEW )
  1296                                 };
  1297                             }
  1298  
  1299                             if (Wi ndowManage r.viewers. inlineView ers.length  > 1) {
  1300  
  1301                                 it ems.editCo nceptUnlin kedViewer  = {
  1302                                      name: "E dit Concep t in Unlin ked Viewer ",
  1303                                      icon: "c ontext-men u-icon gly phicon-pen cil",
  1304                                      callback : openConc eptEditor( $triggerEl ement, Con ceptsModul e.EDIT, uu id, jsObje ct, unlink edViewerID )
  1305                                 };
  1306                             }
  1307  
  1308                             items. cloneConce pt = {
  1309                                 na me: "Clone  Concept",
  1310                                 ic on: "conte xt-menu-ic on glyphic on-share",
  1311                                 ca llback: op enConceptE ditor($tri ggerElemen t, Concept sModule.CL ONE, uuid,  jsObject)
  1312                             };
  1313  
  1314                             if (Wi ndowManage r.viewers. inlineView ers.length  < WindowM anager.vie wers.maxIn lineViewer s) {
  1315  
  1316                                 it ems.cloneC onceptNewV iewer = {
  1317                                      name: "C lone Conce pt in New  Viewer",
  1318                                      icon: "c ontext-men u-icon gly phicon-sha re",
  1319                                      callback : openConc eptEditor( $triggerEl ement, Con ceptsModul e.CLONE, u uid, jsObj ect, Windo wManager.N EW, Window Manager.NE W)
  1320                                 };
  1321                             }
  1322  
  1323                             if (Wi ndowManage r.viewers. inlineView ers.length  > 1) {
  1324  
  1325                                 it ems.cloneC onceptUnli nkedViewer  = {
  1326                                      name: "C lone Conce pt in Unli nked Viewe r",
  1327                                      icon: "c ontext-men u-icon gly phicon-sha re",
  1328                                      callback : openConc eptEditor( $triggerEl ement, Con ceptsModul e.CLONE, u uid, jsObj ect, unlin kedViewerI D)
  1329                                 };
  1330                             }
  1331  
  1332                             if (co nceptText  != null &&  conceptTe rminologyT ypes != nu ll) {
  1333  
  1334                                 it ems.create ChildConce pt = {
  1335                                      name: "C reate Chil d Concept" ,
  1336                                      icon: "c ontext-men u-icon gly phicon-plu s",
  1337                                      callback : openConc eptEditor( $triggerEl ement, Con ceptsModul e.CREATE,  null, jsOb ject, Wind owManager. getLinkedV iewerID(),  WindowMan ager.INLIN E, uuid, c onceptText , conceptT erminology Types)
  1338                                 };
  1339  
  1340                                 if  (WindowMa nager.view ers.inline Viewers.le ngth < Win dowManager .viewers.m axInlineVi ewers) {
  1341  
  1342                                      items.cr eateChildC onceptNewV iewer = {
  1343                                          name : "Create  Child Conc ept in New  Viewer",
  1344                                          icon : "context -menu-icon  glyphicon -plus",
  1345                                          call back: open ConceptEdi tor($trigg erElement,  ConceptsM odule.CREA TE, null,  jsObject,  WindowMana ger.NEW, W indowManag er.NEW, uu id, concep tText, con ceptTermin ologyTypes )
  1346                                      };
  1347                                 }
  1348  
  1349                                 if  (WindowMa nager.view ers.inline Viewers.le ngth > 1)  {
  1350  
  1351                                      items.cr eateChildC onceptUnli nkedViewer  = {
  1352                                          name : "Create  Child Conc ept in Unl inked View er",
  1353                                          icon : "context -menu-icon  glyphicon -plus",
  1354                                          call back: open ConceptEdi tor($trigg erElement,  ConceptsM odule.CREA TE, null,  jsObject,  unlinkedVi ewerID, Wi ndowManage r.INLINE,  uuid, conc eptText, c onceptTerm inologyTyp es)
  1355                                      };
  1356                                 }
  1357                             }
  1358  
  1359                             if (co nceptState  != null)  {
  1360  
  1361                                 it ems.separa torState =  {type: "c m_separato r"};
  1362  
  1363                                 if  (conceptS tate.toLow erCase() = = 'active' ) {
  1364                                      items.ac tiveInacti veUuid = {
  1365                                          name : "Inactiv ate Concep t",
  1366                                          icon : "context -menu-icon  glyphicon -ban-circl e",
  1367                                          call back: chan geConceptS tate($trig gerElement , uuid, co nceptText,  'false')
  1368                                      };
  1369                                 }  else {
  1370                                      items.ac tiveInacti veUuid = {
  1371                                          name : "Activat e Concept" ,
  1372                                          icon : "context -menu-icon  glyphicon -ok-circle ",
  1373                                          call back: chan geConceptS tate($trig gerElement , uuid, co nceptText,  'true')
  1374                                      };
  1375                                 }
  1376                             }
  1377                         }
  1378                    } el se if (men uType == " paste_targ et") {
  1379  
  1380                         var idFiel d = $trigg erElement. attr("data -menu-id-f ield");
  1381                         var displa yField = $ triggerEle ment.attr( "data-menu -display-f ield");
  1382                         var termin ologyTypes Field = $t riggerElem ent.attr(" data-menu- terminolog y-types-fi eld");
  1383  
  1384                         if (concep tClipboard .id != und efined) {
  1385                             items. pasteConce pt = {
  1386                                 na me: "Paste  Concept:  " + concep tClipboard .conceptTe xt,
  1387                                 is HtmlName:  true,
  1388                                 ic on: "conte xt-menu-ic on glyphic on-paste",
  1389                                 ca llback: pa steConcept (idField,  displayFie ld, termin ologyTypes Field)
  1390                             }
  1391                         }
  1392  
  1393                    } el se {
  1394                         items.copy  = {
  1395                             name:  "Copy",
  1396                             icon:  "context-m enu-icon g lyphicon-c opy",
  1397                             callba ck: copyTo Clipboard( $triggerEl ement.attr ("data-men u-copy-val ue"))
  1398                         };
  1399                    }
  1400  
  1401                    retu rn {
  1402                         callback:  function ( ) {
  1403                         },
  1404                         items: ite ms
  1405                    };
  1406                }
  1407           }) ;
  1408       }
  1409  
  1410       // Con text menu  functions
  1411  
  1412       functi on openCon cept(eleme nt, id, js Object, vi ewerID, wi ndowType)  {
  1413  
  1414           re turn funct ion () {
  1415  
  1416                var view erPanel =  element.pa rents("div [id^=komet _viewer_]" );
  1417  
  1418                // if th e viewerID  was not p assed it ( but not if  it is nul l), look u p what it  should be
  1419                if (view erID === u ndefined)  {
  1420  
  1421                    if ( viewerPane l.length >  0) {
  1422                         viewerID =  viewerPan el.first() .attr("dat a-komet-vi ewer-id");
  1423                    } el se {
  1424                         viewerID =  WindowMan ager.getLi nkedViewer ID();
  1425                    }
  1426                }
  1427  
  1428                $.publis h(KometCha nnels.Taxo nomy.taxon omyTreeNod eSelectedC hannel, [" ", id, UIH elper.getV iewParams( jsObject),  viewerID,  windowTyp e]);
  1429           };
  1430       }
  1431  
  1432       functi on openMap Set(elemen t, id, jsO bject, vie werID, win dowType) {
  1433  
  1434           re turn funct ion () {
  1435  
  1436                var view erPanel =  element.pa rents("div [id^=komet _viewer_]" );
  1437  
  1438                // if th e viewerID  was not p assed it ( but not if  it is nul l), look u p what it  should be
  1439                if (view erID === u ndefined)  {
  1440  
  1441                    if ( viewerPane l.length >  0) {
  1442                         viewerID =  viewerPan el.first() .attr("dat a-komet-vi ewer-id");
  1443                    } el se {
  1444  
  1445                         viewerID =  WindowMan ager.getLi nkedViewer ID();
  1446                    }
  1447                }
  1448  
  1449                $.publis h(KometCha nnels.Mapp ing.mappin gTreeNodeS electedCha nnel, ["",  id, UIHel per.getVie wParams(js Object), v iewerID, w indowType] );
  1450           };
  1451       }
  1452  
  1453       functi on copyCon cept(id, c onceptText , conceptT erminology Types) {
  1454  
  1455           re turn funct ion () {
  1456                conceptC lipboard =  {id: id,  conceptTex t: concept Text, conc eptTermino logyTypes:  conceptTe rminologyT ypes};
  1457           };
  1458       }
  1459  
  1460       functi on copyToC lipboard(t ext) {
  1461  
  1462           re turn funct ion () {
  1463                // have  to create  a fake ele ment with  the value  on the pag e to get c opy to wor k
  1464                var text Area = doc ument.crea teElement( 'textarea' );
  1465                textArea .setAttrib ute('style ', 'width: 1px;border :0;opacity :0;');
  1466                document .body.appe ndChild(te xtArea);
  1467                textArea .value = t ext;
  1468                textArea .select();
  1469                document .execComma nd('copy') ;
  1470                document .body.remo veChild(te xtArea);
  1471           };
  1472       }
  1473  
  1474       functi on openCon ceptEditor (element,  action, id , jsObject , viewerID , windowTy pe, parent ID, parent Text, pare ntTerminol ogyTypes)  {
  1475  
  1476           re turn funct ion () {
  1477  
  1478                var view erPanel =  element.pa rents("div [id^=komet _viewer_]" );
  1479  
  1480                // if th e viewerID  was not p assed it ( but not if  it is nul l), look u p what it  should be
  1481                if (view erID === u ndefined)  {
  1482  
  1483                    if ( viewerPane l.length >  0) {
  1484                         viewerID =  viewerPan el.first() .attr("dat a-komet-vi ewer-id");
  1485                    } el se {
  1486                         viewerID =  WindowMan ager.getLi nkedViewer ID();
  1487                    }
  1488                }
  1489  
  1490                $.publis h(KometCha nnels.Taxo nomy.taxon omyConcept EditorChan nel, [acti on, id, UI Helper.get ViewParams (jsObject) , viewerID , windowTy pe, {
  1491                    pare ntID: pare ntID,
  1492                    pare ntText: pa rentText,
  1493                    pare ntType: pa rentTermin ologyTypes
  1494                }]);
  1495           };
  1496       }
  1497  
  1498       functi on changeC onceptStat e(element,  concept_i d, concept Text, newS tate) {
  1499  
  1500           re turn funct ion (){
  1501  
  1502                var para ms = {conc ept_id: co ncept_id,  newState:  newState }  ;
  1503  
  1504                $.get( g on.routes. taxonomy_c hange_conc ept_state_ path , par ams, funct ion( resul ts ) {
  1505  
  1506                    var  splitter =  $("#komet _west_pane ");
  1507  
  1508                    UIHe lper.remov ePageMessa ges(splitt er);
  1509  
  1510                    if ( conceptTex t == null) {
  1511                         conceptTex t = "";
  1512                    } el se {
  1513                         conceptTex t = " '" +  conceptTe xt + "'";
  1514                    }
  1515  
  1516                    if ( results.st ate != nul l) {
  1517  
  1518                         splitter.p repend(UIH elper.gene ratePageMe ssage("The  state of  concept "  + conceptT ext + " wa s successf ully updat ed.", true , "success "));
  1519                         TaxonomyMo dule.tree. reloadTree (TaxonomyM odule.getV iewParams( ), false);
  1520  
  1521                         // if the  mapping mo dule has b een loaded  then refr esh the ma pping tree
  1522                         if (Mappin gModule.tr ee){
  1523                             Mappin gModule.tr ee.reloadT ree(Mappin gModule.ge tViewParam s());
  1524                         }
  1525  
  1526                    } el se {
  1527  
  1528                         splitter.p repend(UIH elper.gene ratePageMe ssage("The  concept s tate was n ot updated ."));
  1529                    }
  1530                });
  1531           };
  1532       }
  1533  
  1534       functi on pasteCo ncept(idFi eld, displ ayField, t erminology TypesField ) {
  1535  
  1536           re turn funct ion () {
  1537  
  1538                $("#" +  idField).v al(concept Clipboard. id);
  1539                $("#" +  displayFie ld).val(co nceptClipb oard.conce ptText);
  1540                $("#" +  terminolog yTypesFiel d).val(con ceptClipbo ard.concep tTerminolo gyTypes);
  1541           };
  1542       }
  1543  
  1544       return  {
  1545           in itDatePick er: initDa tePicker,
  1546           se tStampDate : setStamp Date,
  1547           ge tOffset: g etOffset,
  1548           mo veRowOrder Control: m oveRowOrde rControl,
  1549           in itOrderCon trols: ini tOrderCont rols,
  1550           in itFlagCont rols: init FlagContro ls,
  1551           cl earColorFl agControl:  clearColo rFlagContr ol,
  1552           se tFlagShape : setFlagS hape,
  1553           ad dFlagRowTe mplate: ad dFlagRowTe mplate,
  1554           ad dFlagRow:  addFlagRow ,
  1555           de leteFlagRo w: deleteF lagRow,
  1556           ge tActiveTab Id: getAct iveTabId,
  1557           is TabActive:  isTabActi ve,
  1558           in itializeCo ntextMenus : initiali zeContextM enus,
  1559           ge neratePage Message: g eneratePag eMessage,
  1560           re movePageMe ssages: re movePageMe ssages,
  1561           fo cusNextEle ment: focu sNextEleme nt,
  1562           ge nerateConf irmationDi alog: gene rateConfir mationDial og,
  1563           to ggleChange Highlights : toggleCh angeHighli ghts,
  1564           to ggleFieldA vailabilit y: toggleF ieldAvaila bility,
  1565           ha sFormChang ed: hasFor mChanged,
  1566           re setFormCha nges: rese tFormChang es,
  1567           ac ceptFormCh anges: acc eptFormCha nges,
  1568           fi ndInArray:  findInArr ay,
  1569           cr eateAutoSu ggestField : createAu toSuggestF ield,
  1570           pr ocessAutoS uggestTags : processA utoSuggest Tags,
  1571           lo adAutoSugg estRecents : loadAuto SuggestRec ents,
  1572           us eAutoSugge stRecent:  useAutoSug gestRecent ,
  1573           cl earAutoSug gestRecent Cache: cle arAutoSugg estRecentC ache,
  1574           cr eateSelect FieldStrin g: createS electField String,
  1575           ge tPreDefine dOptionsFo rSelect: g etPreDefin edOptionsF orSelect,
  1576           ge tElementRi ghtFromWin dow: getEl ementRight FromWindow ,
  1577           ge tViewParam s: getView Params,
  1578           VH AT: VHAT,
  1579           SN OMED: SNOM ED,
  1580           LO INC: LOINC ,
  1581           RX NORM: RXNO RM,
  1582           CH ANGEABLE_C LASS: CHAN GEABLE_CLA SS,
  1583           CH ANGE_HIGHL IGHT_CLASS : CHANGE_H IGHLIGHT_C LASS,
  1584           RE CENTS_ASSO CIATION: R ECENTS_ASS OCIATION,
  1585           RE CENTS_MAPS ET: RECENT S_MAPSET,
  1586           RE CENTS_SEME ME: RECENT S_SEMEME,
  1587           RE CENTS_META DATA: RECE NTS_METADA TA,
  1588           FL AG_SHAPES:  FLAG_SHAP ES
  1589       };
  1590   })();
  1591  
  1592