]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/notes.xul
Call persist_helper() in most interfaces. Give it the ability to handle resizing...
[Evergreen.git] / Open-ILS / xul / staff_client / server / serial / notes.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Serial Notes -->
4 <!--
5  vim:noet:sw=4:ts=4
6 -->
7
8 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
9 <!-- STYLESHEETS -->
10 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
11 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
12 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
13 <?xml-stylesheet href="/xul/server/skin/patron_display.css" type="text/css"?>
14
15 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
16 <!-- LOCALIZATION -->
17 <!DOCTYPE window PUBLIC "" ""[
18         <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
19 ]>
20
21 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
22 <!-- OVERLAYS -->
23 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
24
25 <window id="notes_win" width="700" height="550" oils_persist="height width sizemode"
26         onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
27         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
28
29         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
30         <!-- BEHAVIOR -->
31         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
32         <scripts id="openils_util_scripts"/>
33
34         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
35         <script>
36         <![CDATA[
37
38                 function $(id) { return document.getElementById(id); }
39
40                 function my_init() {
41                         try {
42                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
43                                 if (typeof JSAN == 'undefined') { 
44                                         throw( $("commonStrings").getString('common.jsan.missing') );
45                                 }
46                                 JSAN.errorLevel = "die"; // none, warn, or die
47                                 JSAN.addRepository('/xul/server/');
48
49                                 JSAN.use('util.error'); g.error = new util.error();
50                                 JSAN.use('util.network'); g.network = new util.network();
51                                 JSAN.use('util.date'); JSAN.use('util.money'); 
52                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
53
54                                 g.error.sdump('D_TRACE','my_init() for notes.xul');
55
56                                 g.object_type = xul_param('object_type',{'modal_xulG':true});
57                                 g.object_id = xul_param('object_id',{'modal_xulG':true});
58                                 g.function_type = xul_param('function_type',{'modal_xulG':true});
59                                 g.constructor = xul_param('constructor',{'modal_xulG':true});
60
61                                 refresh();
62
63                         } catch(E) {
64                                 var err_msg = $("commonStrings").getFormattedString('common.exception', ['serial/notes.xul', js2JSON(E)]);
65                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
66                                 alert(err_msg);
67                         }
68                 }
69
70                 function refresh() {
71                         retrieve_notes(); render_notes();
72                 }
73
74                 function retrieve_notes() {
75                         g.notes = g.network.simple_request('FM_'+g.function_type+'_RETRIEVE_ALL',[ { 'authtoken' : ses(), 'object_id' : g.object_id } ]).reverse();
76                 }
77
78                 function apply(node,field,value) {
79                         util.widgets.apply(
80                                 node,'name',field,
81                                 function(n) {
82                                         switch(n.nodeName) {
83                                                 case 'description' : n.appendChild( document.createTextNode( value ) ); break;
84                                                 case 'label' : n.value = value; break;
85                                                 default : n.value = value; break;
86                                         }
87                                 }
88                         );
89                 }
90
91                 function render_notes() {
92                         JSAN.use('util.widgets'); util.widgets.remove_children('notes_panel');
93                         var np = $('notes_panel');
94                                 var hbox = document.createElement('hbox'); np.appendChild(hbox);
95                                         var btn = document.createElement('button'); hbox.appendChild(btn);
96                                                 btn.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.render_notes.label'));
97                                                 btn.setAttribute('accesskey', $('catStrings').getString('staff.cat.copy_notes.render_notes.accesskey'));
98                                                 btn.setAttribute('oncommand','new_note()');
99
100                         for (var i = 0; i < g.notes.length; i++) {
101
102                                 /* template */
103                                 var node = $('note_template').cloneNode(true); np.appendChild(node); node.hidden = false;
104                                 apply(node,'create_date',g.notes[i].create_date().toString().substr(0,10));
105                                 util.widgets.apply(node,'name','create_date',
106                                         function(n) {
107                                                 n.setAttribute(
108                                                         "tooltiptext",
109                                                         $('catStrings').getString('staff.cat.copy_notes.widgets_apply.note_id') + " "
110                                                         + g.notes[i].id() + " " 
111                                                         + $('catStrings').getString('staff.cat.copy_notes.widgets_apply.creator_id') + " "
112                                                         + g.notes[i].creator()
113                                                 );
114                                         }
115                                 );
116                                 apply(node,'title',g.notes[i].title());
117                                 apply(node,'pub',get_bool( g.notes[i].pub() ) ? $('catStrings').getString('staff.cat.copy_notes.widgets.public') : $('catStrings').getString('staff.cat.copy_notes.widgets.private'));
118                                 apply(node,'value',g.notes[i].value());
119                                 apply(node,'id',g.notes[i].id());
120                                 apply(node,'creator',g.notes[i].creator());
121
122                                 /* button bar */
123                                 var hb = document.createElement('hbox'); np.appendChild(hb);
124                                         var btn1 = document.createElement('button'); hb.appendChild(btn1);
125                                                 btn1.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.label'));
126                                                 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
127
128                                                 btn1.addEventListener(
129                                                         'command',
130                                                         function(id){ return function() { 
131                                                                 var r = g.error.yns_alert(
132                                                                         $('catStrings').getFormattedString('staff.cat.copy_notes.delete_note.prompt.msg', [g.notes[id].title(), g.notes[id].create_date().toString().substr(0,10)]),
133                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.title'),
134                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.yes'),
135                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.no'),
136                                                                         null,
137                                                                         $('commonStrings').getString('common.confirm')
138                                                                 ); 
139                                                                 if (r == 0) {
140                                                                         g.network.simple_request('FM_'+g.function_type+'_DELETE',[ses(),g.notes[id].id()]);
141                                                                         setTimeout(function() { 
142                                                                                 alert($('catStrings').getString('staff.cat.copy_notes.delete_note.success'));
143                                                                                 refresh(); },0
144                                                                         );
145                                                                 }
146                                                         } }(i),
147                                                         false
148                                                 );
149                                         var spacer = document.createElement('spacer'); hb.appendChild(spacer); spacer.flex = 1;
150                                         var btn2 = document.createElement('button'); hb.appendChild(btn2);
151                                                 btn2.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.close_window'));
152                                                 btn2.setAttribute('oncommand','window.close();');
153                         }
154
155                 }
156                 
157                 function new_note() {
158                         try {
159                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
160                                 var xml = '<groupbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1"> \
161                                         <caption label="' + $('catStrings').getString('staff.cat.copy_notes.new_note.label') + '"/> \
162                                         <grid flex="1"><columns><column/><column flex="1"/></columns> \
163                                                 <rows> \
164                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.public') + '"/><checkbox id="pub" name="fancy_data" checked="false"/></row> \
165                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.title') + '"/><textbox id="title" name="fancy_data" context="clipboard"/></row> \
166                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.note') + '"/><textbox multiline="true" id="note" name="fancy_data" context="clipboard"/></row> \
167                                                         <row><spacer/><hbox> \
168                                                                 <button label="' + $('catStrings').getString('staff.cat.copy_notes.new_note.cancel.label') + '" name="fancy_cancel" accesskey="' + $('catStrings').getString('staff.cat.copy_notes.new_note.cancel.accesskey') + '"/> \
169                                                                 <button label="' + $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.label') + '" accesskey="' + $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.accesskey') + '" name="fancy_submit"/></hbox></row> \
170                                                 </rows></grid></groupbox>';
171                                 //g.data.init({'via':'stash'});
172                                 //g.data.temp_note_xml = xml; g.data.stash('temp_note_xml');
173                                 JSAN.use('util.window'); var win = new util.window();
174                                 var fancy_prompt_data = win.open(
175                                         urls.XUL_FANCY_PROMPT,
176                                         //+ '?xml_in_stash=temp_note_xml'
177                                         //+ '&focus=' + window.escape('title')
178                                         //+ '&title=' + window.escape('Add Note'),
179                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
180                                         { 'xml' : xml, 'focus' : 'title', 'title' : $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.label') }
181                                 );
182                                 //g.data.init({'via':'stash'});
183                                 if (fancy_prompt_data.fancy_status == 'complete') {
184                                         //alert(js2JSON(g.data.fancy_prompt_data));
185                                         var note = new g.constructor();
186                                         note.isnew(1);
187                                         note.title( fancy_prompt_data.title );
188                                         note.value( fancy_prompt_data.note );
189                                         note.pub( get_bool( fancy_prompt_data.pub ) ? get_db_true() : get_db_false() );
190                                         note[g.object_type]( g.object_id );
191                                         var r = g.network.simple_request('FM_'+g.function_type+'_CREATE',[ ses(), note ]);
192                                         if (typeof r.ilsevent != 'undefined') throw(r);
193                                         setTimeout(function() {
194                                                 alert($('catStrings').getString('staff.cat.copy_notes.new_note.success'));
195                                                 refresh();},0
196                                         );
197                                 }
198                         } catch(E) {
199                                 g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_notes.new_note.error'),E);
200                         }
201                 }
202
203         ]]>
204         </script>
205
206         <messagecatalog id="catStrings" src="/xul/server/locale/<!--#echo var='locale'-->/cat.properties" />
207         <messagecatalog id="circStrings" src="/xul/server/locale/<!--#echo var='locale'-->/circ.properties" />
208
209         <stack hidden="true" id="note_template" flex="1">
210                 <groupbox flex="1" style="background-color: black;"/>
211                 <groupbox flex="1" style="background-color: #FFDE00; -moz-border-radius-topright: 35px;" >
212                         <hbox>
213                                 <description name="title" style="font-weight: bold"/>
214                                 <spacer flex="1"/>
215                                 <description name="create_date" style="font-weight: bold"/>
216                                 <description name="pub" style="font-weight: bold"/>
217                         </hbox>
218                         <description name="value"/>
219                 </groupbox>
220         </stack>
221
222         <vbox flex="1" class="my_overflow" id="notes_panel">
223         </vbox>
224
225
226 </window>
227