1 namespace('kivi.RecordTemplate', function(ns) {
 
   4   ns.popup = function(template_type) {
 
   5     $.get('controller.pl', {
 
   6       action:        'RecordTemplate/show_dialog.js',
 
   7       template_type: template_type,
 
   8     }, kivi.eval_json_result);
 
  11   ns.create = function() {
 
  12     var new_name = $("#record_template_dialog_new_template_name").val();
 
  13     if (new_name === '') {
 
  14       alert(kivi.t8('Error: Name missing'));
 
  18     kivi.RecordTemplate.save(undefined, new_name);
 
  21   ns.save = function(id, name) {
 
  22     var $type = $("#record_template_dialog_template_type");
 
  23     var $form = $($type.data('form_selector'));
 
  26       console.log("nothing found for form_selector " + $type.data("form_selector"));
 
  30     if ((id !== undefined) && !confirm(kivi.t8('Are you sure you want to update the selected record template with the current values? This cannot be undone.')))
 
  33     var data = $form.serializeArray().filter(function(val) { return val.name !== 'action'; });
 
  34     data.push({ name: 'action',                            value: $type.data('save_action') });
 
  35     data.push({ name: 'record_template_id',                value: id });
 
  36     data.push({ name: 'record_template_new_template_name', value: name });
 
  38     $.post($type.data('controller'), data, kivi.eval_json_result);
 
  41   ns.load = function(id) {
 
  42     var $type = $("#record_template_dialog_template_type");
 
  43     var url   = encodeURIComponent($type.data('controller'))
 
  44               + '?action=' + encodeURIComponent($type.data('load_action'))
 
  45               + '&id='     + encodeURIComponent(id);
 
  49     window.location = url;
 
  52   ns.rename = function(id) {
 
  53     var current_name = $("#record_template_dialog_template_name_" + id).val();
 
  54     var new_name     = prompt(kivi.t8("Please enter the new name:"), current_name);
 
  56     if ((new_name === current_name) || !new_name || (new_name === ''))
 
  59     $.post('controller.pl', {
 
  60       action: 'RecordTemplate/rename.js',
 
  62       template_name: new_name
 
  63     }, kivi.eval_json_result);
 
  66   ns.delete = function(id) {
 
  67     if (!confirm(kivi.t8('Do you really want to delete this record template?')))
 
  70     $.post('controller.pl', {
 
  71       action: 'RecordTemplate/delete.js',
 
  73     }, kivi.eval_json_result);
 
  76   ns.filter_templates = function() {
 
  77     $.post('controller.pl', {
 
  78       action: 'RecordTemplate/filter_templates',
 
  79       template_filter: $("#template_filter").val(),
 
  80       template_type: $("#record_template_dialog_template_type").val(),
 
  81     }, kivi.eval_json_result);