465 /** |
465 /** |
466 * Themes management |
466 * Themes management |
467 */ |
467 */ |
468 themes: { |
468 themes: { |
469 |
469 |
470 initExtracts: function(element) { |
470 updateThesaurus: function(event) { |
471 var thesaurus = $('select[name="manager_themes.widgets.thesaurus_name:list"]', element); |
471 debugger; |
|
472 var form = $(this).parents('form'); |
|
473 // clear extract name |
|
474 var extract = $('select[name$=".extract_name:list"]', form); |
|
475 var plugin = extract.data('select2'); |
|
476 extract.empty(); |
|
477 extract.select2('data', null); |
|
478 plugin.results.empty(); |
|
479 // check thesaurus for new extracts |
|
480 var thesaurus = $('select[name$=".thesaurus_name:list"]', form); |
472 var thesaurus_name = thesaurus.val(); |
481 var thesaurus_name = thesaurus.val(); |
473 var extract = $('select[name="manager_themes.widgets.extract_name:list"]', element); |
|
474 var extract_name = extract.val(); |
|
475 if (thesaurus_name) { |
482 if (thesaurus_name) { |
476 MyAMS.jsonrpc.post('getExtracts', |
483 MyAMS.jsonrpc.post('getExtracts', |
477 {thesaurus_name: thesaurus_name}, |
484 {thesaurus_name: thesaurus_name}, |
478 {url: '/api/thesaurus/json'}, |
485 {url: '/api/thesaurus/json'}, |
479 function(data) { |
486 function(data) { |
480 extract.empty(); |
487 extract.empty(); |
481 $(data.result).each(function() { |
488 $(data.result).each(function() { |
482 $('<option></option>').attr('value', this.id) |
489 $('<option></option>').attr('value', this.id) |
483 .attr('selected', this.id === extract_name) |
|
484 .text(this.text) |
490 .text(this.text) |
485 .appendTo(extract); |
491 .appendTo(extract); |
486 }); |
492 }); |
487 }); |
|
488 } |
|
489 }, |
|
490 |
|
491 getExtracts: function(event) { |
|
492 var select = $(event.currentTarget); |
|
493 var form = select.parents('form'); |
|
494 var thesaurus_name = $('select[name="manager_themes.widgets.thesaurus_name:list"]', form).val(); |
|
495 var extract = $('select[name="manager_themes.widgets.extract_name:list"]', form); |
|
496 var plugin = extract.data('select2'); |
|
497 if (thesaurus_name && (thesaurus_name !== '--NOVALUE--')) { |
|
498 MyAMS.jsonrpc.post('getExtracts', |
|
499 {thesaurus_name: thesaurus_name}, |
|
500 {url: '/api/thesaurus/json'}, |
|
501 function(data) { |
|
502 plugin.results.empty(); |
|
503 plugin.opts.populateResults.call(plugin, plugin.results, data.result, |
493 plugin.opts.populateResults.call(plugin, plugin.results, data.result, |
504 {term: ''}); |
494 {term: ''}); |
505 }); |
495 }); |
506 } else { |
|
507 extract.select2('data', null); |
|
508 plugin.results.empty(); |
|
509 plugin.opts.populateResults.call(plugin, plugin.results, [], {term: ''}); |
|
510 } |
496 } |
511 } |
497 } |
512 }, |
498 }, |
513 |
499 |
514 /** |
500 /** |