Belegvorlagen: Anzeigen, Umbenennen, Löschen
[kivitendo-erp.git] / js / kivi.RecordTemplate.js
1 namespace('kivi.RecordTemplate', function(ns) {
2   'use strict';
3
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);
9   };
10
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'));
15       return false;
16     }
17
18     kivi.RecordTemplate.save(undefined, new_name);
19   };
20
21   ns.save = function(id, name) {
22     var $type = $("#record_template_dialog_template_type");
23     var $form = $($type.data('form_selector'));
24
25     if (!$form) {
26       console.log("nothing found for form_selector " + $type.data("form_selector"));
27       return false;
28     }
29
30     var data = $form.serializeArray().filter(function(val) { return val.name !== 'action'; });
31     data.push({ name: 'action',                            value: $type.data('save_action') });
32     data.push({ name: 'record_template_id',                value: id });
33     data.push({ name: 'record_template_new_template_name', value: name });
34
35     $.post($type.data('controller'), data, kivi.eval_json_result);
36   };
37
38   ns.load = function(id) {
39     if (!confirm(kivi.t8('Do you really want to load this record template? All unsaved data will be lose.')))
40       return false;
41
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);
46
47     console.log(url);
48
49     window.location = url;
50   };
51
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);
55
56     if ((new_name === current_name) || !new_name || (new_name === ''))
57       return;
58
59     $.post('controller.pl', {
60       action: 'RecordTemplate/rename.js',
61       id: id,
62       template_name: new_name
63     }, kivi.eval_json_result);
64   };
65
66   ns.delete = function(id) {
67     if (!confirm(kivi.t8('Do you really want to delete this record template?')))
68       return;
69
70     $.post('controller.pl', {
71       action: 'RecordTemplate/delete.js',
72       id: id
73     }, kivi.eval_json_result);
74   };
75 });