]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/scap_editor.js
fef8a0f8a9f54950f7883dd3f2577f612e99257e
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / serial / scap_editor.js
1 dump('entering serial/scap_editor.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 JSAN.use('serial.editor_base');
5
6 if (typeof serial == 'undefined') serial = {};
7 serial.scap_editor = function (params) {
8     try {
9         JSAN.use('util.error'); this.error = new util.error();
10         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
11         JSAN.use('util.network'); this.network = new util.network();
12     } catch(E) {
13         dump('serial/scap_editor: ' + E + '\n');
14     }
15
16     /* This keeps track of what fields have been edited for styling purposes */
17     this.changed = {};
18
19     /* This holds the original values for prepopulating the field editors */
20     this.editor_values = {};
21
22 };
23
24 serial.scap_editor.prototype = {
25     // we could do this with non-standard '__proto__' property instead
26     'editor_base_init' : serial.editor_base.editor_base_init,
27     'editor_base_apply' : serial.editor_base.editor_base_apply,
28     'editor_base_save' : serial.editor_base.editor_base_save,
29
30     'fm_type' : 'scap',
31     'fm_type_plural' : 'scaps',
32
33     'init' : function (params) {
34         var obj = this;
35
36         params.retrieve_function = 'FM_SCAP_BATCH_RETRIEVE.authoritative';
37
38         obj.editor_base_init(params);
39
40         /* Do it */
41         obj.summarize( obj.scaps );
42         obj.render();
43     },
44
45     /******************************************************************************************************/
46     /* Restore backup copies */
47
48     'reset' :  serial.editor_base.editor_base_reset,
49
50     /******************************************************************************************************/
51     /* Apply a value to a specific field on all the copies being edited */
52
53     'apply' : function(field,value) {
54         var obj = this;
55
56         obj.editor_base_apply(field, value);
57     },
58
59     /******************************************************************************************************/
60
61     'init_panes' : function () {
62         var obj = this;
63         obj.panes_and_field_names = {
64
65         /* These get shown in the left panel */
66         'scap_editor_left_pane' :
67         [
68             [
69                 'id',
70                 { 
71                     //input: 'c = function(v){ obj.apply("distribution",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
72
73                 }
74             ],
75             [
76                 'create_date',
77                 {
78                     render: 'fm.create_date() == null ? "" : util.date.formatted_date( fm.create_date(), "%F");',
79                 }
80             ],
81             [
82                 'type',
83                 {
84                     input: 'c = function(v){ obj.apply("type",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ ["basic", "basic"], ["index", "index"], ["supplement", "supplement"] ] ); x.setAttribute("value",obj.editor_values.type); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
85                     value_key: 'type',
86                     required: true
87                 }
88             ],
89             [
90                 'active',
91                 {
92                     render: 'fm.active() == null ? $("catStrings").getString("staff.cat.copy_editor.field.unset_or_null") : ( get_bool( fm.active() ) ? $("catStrings").getString("staff.cat.copy_editor.field.circulate.yes_or_true") : $("catStrings").getString("staff.cat.copy_editor.field.circulate.no_or_false") )',
93                     input: 'c = function(v){ obj.apply("active",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ $("catStrings").getString("staff.cat.copy_editor.field.circulate.yes_or_true"), get_db_true() ], [ $("catStrings").getString("staff.cat.copy_editor.field.circulate.no_or_false"), get_db_false() ] ] ); x.setAttribute("value",obj.editor_values.active); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
94                     value_key: 'active',
95                     dropdown_key: 'fm.active()'
96                 }
97             ],
98             [
99                 'pattern_code',
100                 { 
101                     input: 'c = function(v){ obj.apply("pattern_code",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("multiline",true); x.setAttribute("cols",40); x.setAttribute("value",obj.editor_values.pattern_code); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
102                     value_key: 'pattern_code',
103                     required: true
104                 }
105             ]
106         ]
107
108         };
109     },
110
111     /******************************************************************************************************/
112     /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
113
114     'summarize' :  serial.editor_base.editor_base_summarize,
115
116     /******************************************************************************************************/
117     /* Display the summarized data and inputs for editing */
118
119     'render' :  serial.editor_base.editor_base_render,
120
121     /******************************************************************************************************/
122     /* This actually draws the change button and input widget for a given field */
123     'render_input' : serial.editor_base.editor_base_render_input,
124
125     /******************************************************************************************************/
126     /* save the caption/patterns */
127
128     'save' : function() {
129         var obj = this;
130         obj.editor_base_save('open-ils.serial.caption_and_pattern.batch.update');
131     },
132
133     /* Pattern/caption wizard */
134     "pattern_wizard": function() {
135         var obj = this;
136
137         var onsubmit = function(value) {
138             obj.apply("pattern_code", value);
139             obj.summarize(obj.scaps);
140             obj.render();
141         };
142         window.openDialog(
143             xulG.url_prefix("XUL_SERIAL_PATTERN_WIZARD"),
144             "pattern_wizard",
145             "width=800",
146             onsubmit
147         );
148     },
149
150     /******************************************************************************************************/
151     'save_attributes' : serial.editor_base.editor_base_save_attributes
152 };
153
154 dump('exiting serial/scap_editor.js\n');