+function warehouse_selected(warehouse_id, bin_id, bin_id_name) {
+ // bin_id_name is optional and only used in client_config.html
+ bin_id_name = bin_id_name || 'bin_id';
+
+ // Remove all bins safe for the empty entry
+ var bin_select = $('#' + bin_id_name);
+ bin_select.find('option').filter('[value!=""]').remove();
+
+ // Find selected warehouse
+ var warehouse = warehouses.filter(function(elt) { return elt.id == warehouse_id; })[0];
+ if (!warehouse)
+ return;
+
+ // Add bins as options to select.
+ $(warehouse.bins).each(function(idx, bin) {
+ bin_select.append($('<option>', { value: bin.id, selected: bin.id == bin_id }).text(bin.description));
+ });
+}
+
+function enable_template_controls() {
+ var existing = $('#use_templates_existing').prop('checked');
+ $('#defaults_templates').prop('disabled', !existing);
+ $('#new_templates,#new_master_templates').prop('disabled', existing);
+}
+
+$(function() {
+ warehouse_selected([% SELF.defaults.warehouse_id || -1 %], [% SELF.defaults.bin_id || -1 %], 'bin_id');
+ warehouse_selected([% SELF.defaults.warehouse_id_ignore_onhand || -1 %], [% SELF.defaults.bin_id_ignore_onhand || -1 %], 'bin_id_ignore_onhand');
+
+ enable_template_controls();
+ $('#use_templates_existing,#use_templates_new').change(enable_template_controls);
+})
+ -->
+ </script>