/[webpac2]/Webpacus/root/editor/editor.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /Webpacus/root/editor/editor.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 187 - (show annotations)
Sun Nov 27 22:10:36 2005 UTC (18 years, 5 months ago) by dpavlin
File MIME type: application/javascript
File size: 4866 byte(s)
 r11243@llin:  dpavlin | 2005-11-27 23:13:09 +0100
 added load_rec(nr, tmp_template_filename) usable from TT templates to reload
 single record (usually nr is comming from [% d('MFN') %]) in different
 template [0.07]

1 /*
2 Webpacus template editor
3 */
4
5 var rec = null;
6 var url = null;
7 var template_filename = null;
8
9 var pending_js = null;
10
11 var css_rnd = 0;
12
13 function _ts(text) {
14 var el = $('div_template_status');
15 if (el) el.innerHTML = text;
16 }
17
18 function _cs(text) {
19 var el = $('div_css_status');
20 if (el) el.innerHTML = text;
21 }
22
23 function load_rec(nr, tmp_template_filename) {
24
25 if (! nr) {
26 Logger.error('load_rec called without nr');
27 return false;
28 }
29
30 if (! tmp_template_filename) tmp_template_filename = template_filename;
31 Logger.info('load_rec '+nr+' in '+tmp_template_filename);
32
33 if (loading.record) {
34 Logger.info('loading of record '+nr+' skipped, load in progress');
35 return;
36 }
37
38 show_working();
39 $('record_nr').disabled = 'true';
40
41 if (nr == 1) {
42 Element.addClassName('a_left_arr', 'nav_disable');
43 } else {
44 Element.removeClassName('a_left_arr', 'nav_disable');
45 }
46
47 var args = '?mfn='+nr+'&template_filename='+tmp_template_filename;
48
49 new Ajax.Updater( 'div_record', url+'record'+args, {
50 asynchronous: 1,
51 onLoading: function(request) {
52 loading.record = 1;
53 Logger.info('load_rec.onLoading: '+nr);
54 },
55 onLoaded: function(request) {
56 loading.record = 0;
57 hide_working();
58 $('record_nr').value = nr;
59 $('record_nr').disabled = '';
60 rec = nr;
61 Logger.info('load_rec.onLoaded: '+nr);
62 }
63 } ) ;
64
65 }
66
67 function inc_rec() {
68 show_working();
69 rec++;
70 load_rec(rec);
71 hide_working();
72 return false;
73 }
74
75 function dec_rec() {
76 if (rec > 1) {
77 show_working();
78 rec--;
79 load_rec(rec);
80 hide_working();
81 }
82 return false;
83 }
84
85 function reload_rec() {
86 show_working();
87 load_rec(rec);
88 hide_working();
89 return false;
90 }
91
92 var current_edit = '';
93
94 function edit_template() {
95 $('div_css').style.visibility = "hidden";
96 $('div_css').style.zIndex = 1;
97 Element.removeClassName('a_css', 'tab_selected');
98 Element.addClassName('a_template', 'tab_selected');
99 $('div_template').style.visibility = "visible";
100 $('div_template').style.zIndex = 2;
101 Logger.debug("switched to template editor");
102 var c = $('template_content');
103 if (c) c.focus();
104 Logger.debug('zIndex template:'+$('div_template').style.zIndex+' css:'+$('div_css').style.zIndex);
105 return false;
106 }
107
108 function edit_css() {
109 $('div_template').style.visibility = "hidden";
110 $('div_template').style.zIndex = 1;
111 Element.removeClassName('a_template', 'tab_selected');
112 Element.addClassName('a_css', 'tab_selected');
113 $('div_css').style.visibility = "visible";
114 $('div_css').style.zIndex = 2;
115 Logger.debug("switched to CSS editor");
116 var c = $('css_content');
117 if (c) c.focus();
118 Logger.debug('zIndex template:'+$('div_template').style.zIndex+' css:'+$('div_css').style.zIndex);
119 return false;
120 }
121
122 function switch_template(new_template_filename) {
123
124 Logger.info('switch_template to '+new_template_filename);
125 show_working();
126
127 Logger.debug('load template editor');
128 template_filename = new_template_filename;
129 load_template(new_template_filename);
130
131 Logger.debug('refresh record');
132 load_rec(rec);
133
134 edKill('template_content');
135
136 hide_working();
137
138 return false;
139 }
140
141 var loading = {
142 template: 0,
143 css: 0,
144 record: 0
145 };
146
147 function load_template( template_filename ) {
148
149 if (loading.template) {
150 Logger.info('loading of template '+template_filename+' skipped, load in progress');
151 return;
152 }
153
154 show_working();
155
156 var args = '?template_filename='+template_filename;
157
158 new Ajax.Updater( 'div_template', url+'template'+args, {
159 asynchronous: 1,
160 onLoading: function(request) {
161 loading.template = 1;
162 Logger.info('load_template.onLoading: '+template_filename);
163 },
164 onLoaded: function(request) {
165 loading.template = 0;
166 Position.clone('div_template', 'div_css');
167 hide_working();
168 Logger.info('load_template.onLoaded: '+template_filename);
169 }
170 } ) ;
171 }
172
173 function load_css(css_filename) {
174
175 if (loading.css) {
176 Logger.info('loading of css '+css_filename+' skipped, load in progress');
177 return;
178 }
179
180 show_working();
181
182 new Ajax.Updater( 'div_css', url+'css', {
183 asynchronous: 1,
184 onLoading: function(request) {
185 loading.css = 1;
186 Logger.info('load_css.onLoading: '+css_filename);
187 },
188 onLoaded: function(request) {
189 loading.css = 0;
190 hide_working();
191 Logger.info('load_css.onLoaded: '+css_filename);
192 }
193 } ) ;
194 };
195
196 function reload_css() {
197
198 css_rnd++;
199 Logger.info('loading user.css?'+css_rnd);
200 $('user_css_link').href = 'css/user.css?'+css_rnd;
201
202 return false;
203 }
204
205 var working_count = 0;
206
207 function show_working() {
208 working_count++;
209 if (working_count > 1) Element.show('working');
210 Logger.debug('show_working, count = '+working_count);
211 }
212
213 function hide_working() {
214 working_count--;
215 if (working_count < 1) Element.hide('working');
216 Logger.debug('hide_working, count = '+working_count);
217 }
218
219 function init_page() {
220
221 show_working();
222
223 edit_template();
224
225 // load css editor
226 load_css();
227
228 // load template editor and record
229 switch_template(template_filename);
230
231 hide_working();
232
233 }
234

  ViewVC Help
Powered by ViewVC 1.1.26