| 15 | | $("div.g select").change(function() { |
| 16 | | this.parentNode.className = ""; |
| 17 | | if(this.value === 'DeCS'){ |
| 18 | | this.parentNode.className = "showdecs"; |
| 19 | | var curset = this.id.match(/_.+\d+/)[0]; // get django formset prefix |
| 20 | | if($("select#combodecs"+curset).length === 0){ |
| 21 | | $('<div class="decstools" id="decstools'+curset+'">') |
| 22 | | .appendTo(this.parentNode) |
| 23 | | .append('<select id="combodecs'+curset+'">'); |
| | 16 | function make_decs_for(node){ |
| | 17 | var set = node.id.match(/[a-z]-\d+/)[0]; // get django formset prefix |
| | 18 | return {'select':set+"-combodecs", |
| | 19 | 'div':set+'-decstools', |
| | 20 | 'input':set+'-searchfield', |
| | 21 | 'button':set+'-searchbutton', |
| | 22 | 'id':function(e){ |
| | 23 | return 'id_'+ this[e]; |
| | 24 | }, |
| | 25 | 'create':function(e){ |
| | 26 | return $('<'+e+'>').attr('id',this.id(e)).attr('name',this[e]); |
| | 27 | }, |
| | 28 | 'set':set |
| | 29 | }; |
| | 30 | } |
| 25 | | $.get("/decs/getterm/en/",'', // TODO: Replace absolute path |
| 26 | | function(data){ |
| 27 | | for(var i=0; i<data.length;i++){ |
| 28 | | $("<option>").attr("value",data[i].fields.label) |
| 29 | | .html(data[i].fields.description) |
| 30 | | .appendTo('#combodecs'+curset); |
| 31 | | } |
| 32 | | $('#combodecs'+curset).change(function(){ |
| 33 | | $("input#id"+curset+"-code") |
| 34 | | .attr("value",this.value); |
| 35 | | $("input#id"+curset+"-text") |
| 36 | | .attr("value",$(this).find("option[selected]").html()); |
| 37 | | }); |
| 38 | | }, |
| 39 | | "json" |
| 40 | | ); |
| | 32 | function make_decstool_callback(decs){ |
| | 33 | return function(data){ |
| | 34 | for(var i=0; i<data.length;i++){ |
| | 35 | $("<option>").attr("value",data[i].fields.label) |
| | 36 | .html(data[i].fields.description) |
| | 37 | .appendTo('#'+decs.id('select')); |
| | 38 | } |
| | 39 | $('#'+decs.id('select')).change(function(evt){ |
| | 40 | decs = make_decs_for(evt.target); |
| | 41 | $("input#id_"+decs.set+"-code") |
| | 42 | .attr("value",this.value); |
| | 43 | $("input#id_"+decs.set+"-text") |
| | 44 | .attr("value",$(this).find("option[selected]").html()); |
| | 45 | }); |
| | 46 | document.body.style.cursor="auto"; |
| | 47 | } |
| | 48 | } |
| | 49 | |
| | 50 | var getterm_event = function(decsclient_url) { |
| | 51 | return function(){ |
| | 52 | this.parentNode.className = ""; |
| | 53 | if(this.value === 'DeCS'){ |
| | 54 | this.parentNode.className = "showdecs"; |
| | 55 | var decs = make_decs_for(this); |
| | 56 | |
| | 57 | if($('#'+decs.id('select')).length === 0){ |
| | 58 | document.body.style.cursor="progress"; |
| | 59 | decs.create('div') |
| | 60 | .appendTo(this.parentNode) |
| | 61 | .append(decs.create('select')); |
| | 62 | |
| | 63 | // TODO: Replace absolute path |
| | 64 | $.get(decsclient_url,'', |
| | 65 | make_decstool_callback(decs),"json"); |
| | 66 | } |
| 45 | | $("div.s select").change(function() { |
| 46 | | this.parentNode.className = ""; |
| 47 | | if(this.value === 'DeCS'){ |
| 48 | | this.parentNode.className = "showdecs"; |
| 49 | | var curset = this.id.match(/_.+\d+/)[0]; |
| 50 | | if($("input#searchdecs"+curset).length === 0){ |
| 51 | | $('<div class="decstools" id="decstools'+curset+'">') |
| 52 | | .appendTo(this.parentNode) |
| 53 | | .append('<input class="text" type="text" id="searchdecs'+curset+'">'); |
| 54 | | $('<input type="button" value="{% trans "Search terms" %}">').appendTo("div#decstools"+curset) |
| 55 | | .click(function(){ |
| 56 | | var select = $("select#combodecs"+curset); |
| 57 | | if($("select#combodecs"+curset).length === 0){ |
| 58 | | select= $('<select id="combodecs'+curset+'">') |
| 59 | | .insertAfter(this); |
| 60 | | } |
| 61 | | $(select).html(""); |
| 62 | | |
| 63 | | $.get("/decs/search/en/"+$("input#searchdecs"+curset).attr("value"),'', |
| 64 | | function(data){ |
| 65 | | for(var i=0; i<data.length;i++){ |
| 66 | | $("<option>").attr("value",data[i].fields.label) |
| 67 | | .html(data[i].fields.description) |
| 68 | | .appendTo('#combodecs'+curset); |
| 69 | | } |
| 70 | | $('#combodecs'+curset).change(function(){ |
| 71 | | $("input#id"+curset+"-code") |
| 72 | | .attr("value",this.value); |
| 73 | | $("input#id"+curset+"-text") |
| 74 | | .attr("value",$(this).find("option[selected]").html()); |
| 75 | | }); |
| 76 | | }, |
| 77 | | 'json' |
| 78 | | ); |
| 79 | | }); |
| | 71 | var search_event = function(decsclient_url) { |
| | 72 | return function(){ |
| | 73 | this.parentNode.className = ""; |
| | 74 | if(this.value === 'DeCS'){ |
| | 75 | this.parentNode.className = "showdecs"; |
| | 76 | var decs = make_decs_for(this); |
| | 77 | |
| | 78 | if($('#'+decs.id('input')).length === 0){ |
| | 79 | |
| | 80 | decs.create('div') |
| | 81 | .appendTo(this.parentNode) |
| | 82 | .append(decs.create('input')) |
| | 83 | .append(decs.create('button').html('{% trans "Search terms" %}')); |
| | 84 | |
| | 85 | $('#'+decs.id('button')) |
| | 86 | .click(function(evt){ |
| | 87 | document.body.style.cursor="progress"; |
| | 88 | var decs = make_decs_for(evt.target); |
| | 89 | if($('#'+decs.id('select')).length === 0){ |
| | 90 | decs.create('select') |
| | 91 | .insertAfter(this); |
| | 92 | } |
| | 93 | $('#'+decs.id('select')).html(''); |
| | 94 | |
| | 95 | $.get(decsclient_url+$('#'+decs.id('input')).val(),'', |
| | 96 | make_decstool_callback(decs), |
| | 97 | 'json'); |
| | 98 | return false; |
| | 99 | }); |
| | 100 | } |