epic-s6ts
[kivitendo-erp.git] / js / kivi.ShopPart.js
1 namespace('kivi.ShopPart', function(ns) {
2   var $dialog;
3
4   ns.shop_part_dialog = function(title, html) {
5     var id            = 'jqueryui_popup_dialog';
6     var dialog_params = {
7       id:     id,
8       width:  800,
9       height: 500,
10       modal:  true,
11       close: function(event, ui) { $dialog.remove(); },
12     };
13
14     $('#' + id).remove();
15
16     $dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
17     $dialog.attr('title', title);
18     $dialog.html(html);
19     $dialog.dialog(dialog_params);
20
21     $('.cancel').click(ns.close_dialog);
22
23     return true;
24   };
25
26   ns.close_dialog = function() {
27     $dialog.dialog("close");
28   }
29
30   ns.save_shop_part = function(shop_part_id) {
31     var form = $('form').serializeArray();
32     form.push( { name: 'action', value: 'ShopPart/update' }
33              , { name: 'shop_part_id',  value: shop_part_id }
34     );
35
36     $.post('controller.pl', form, function(data) {
37       kivi.eval_json_result(data);
38     });
39   }
40
41   ns.add_shop_part = function() {
42     var form = $('form').serializeArray();
43     form.push( { name: 'action', value: 'ShopPart/update' }
44     );
45     $.post('controller.pl', form, function(data) {
46       kivi.eval_json_result(data);
47     });
48   }
49
50   ns.edit_shop_part = function(shop_part_id) {
51     $.post('controller.pl', { action: 'ShopPart/create_or_edit_popup', shop_part_id: shop_part_id }, function(data) {
52       kivi.eval_json_result(data);
53     });
54   }
55
56   ns.create_shop_part = function(part_id, shop_id) {
57     $.post('controller.pl', { action: 'ShopPart/create_or_edit_popup', part_id: part_id, shop_id: shop_id }, function(data) {
58       kivi.eval_json_result(data);
59     });
60   }
61
62   ns.get_all_categories = function(shop_part_id) {
63     $.post('controller.pl', { action: 'ShopPart/get_categories', shop_part_id: shop_part_id }, function(data) {
64       kivi.eval_json_result(data);
65     });
66   }
67
68   ns.save_categories = function(shop_part_id, shop_id) {
69     var form = $('form').serializeArray();
70     form.push( { name: 'action', value: 'ShopPart/save_categories' }
71              , { name: 'shop_id', value: shop_id }
72              , { name: 'shop_part_id', value: shop_part_id }
73     );
74
75     $.post('controller.pl', form, function(data) {
76       kivi.eval_json_result(data);
77     });
78   }
79
80   ns.update_shop_part = function(shop_part_id) {
81     $.post('controller.pl', { action: 'ShopPart/update_shop', shop_part_id: shop_part_id }, function(data) {
82       kivi.eval_json_result(data);
83     });
84   }
85
86   ns.update_discount_source = function(row, source, discount_str) {
87     $('#active_discount_source_' + row).val(source);
88     if (discount_str) $('#discount_' + row).val(discount_str);
89     $('#update_button').click();
90   }
91
92   ns.show_images = function(id) {
93     var url = 'controller.pl?action=ShopPart/show_files&id='+id;
94     $('#shop_images').load(url);
95   }
96
97   ns.update_price_n_price_source = function(shop_part_id,price_source) {
98     $.post('controller.pl', { action: 'ShopPart/show_price_n_pricesource', shop_part_id: shop_part_id, pricesource: price_source }, function(data) {
99       kivi.eval_json_result(data);
100     });
101   }
102
103   ns.update_stock = function(shop_part_id) {
104     $.post('controller.pl', { action: 'ShopPart/show_stock', shop_part_id: shop_part_id }, function(data) {
105       kivi.eval_json_result(data);
106     });
107   }
108
109   ns.massUploadInitialize = function() {
110     kivi.popup_dialog({
111       id: 'status_mass_upload',
112       dialog: {
113         title: kivi.t8('Status Shopupload')
114       }
115     });
116   };
117
118   ns.massUploadStarted = function() {
119     $('#status_mass_upload').data('timerId', setInterval(function() {
120       $.get("controller.pl", {
121         action: 'ShopPart/upload_status',
122         job_id: $('#smu_job_id').val()
123       }, kivi.eval_json_result);
124     }, 5000));
125   };
126
127   ns.massUploadFinished = function() {
128     clearInterval($('#status_mass_upload').data('timerId'));
129     $('.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', '')
130   };
131
132   ns.imageUpload = function(id,type,filetype,upload_title,gl) {
133     kivi.popup_dialog({ url:     'controller.pl',
134                         data:    { action: 'File/ajax_upload',
135                                    file_type:   filetype,
136                                    object_type: type,
137                                    object_id:   id,
138                                    is_global:   gl
139                                  },
140                         id:     'files_upload',
141                         dialog: { title: kivi.t8('File upload'), width: 650, height: 240 } });
142     return true;
143   }
144
145
146   ns.setup = function() {
147     kivi.ShopPart.massUploadInitialize();
148     kivi.submit_ajax_form('controller.pl?action=ShopPart/mass_upload','[name=shop_parts]');
149   };
150
151 });