/[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

Diff of /Webpacus/root/editor/editor.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 167 by dpavlin, Sat Nov 26 21:11:41 2005 UTC revision 357 by dpavlin, Sat Jan 7 23:43:38 2006 UTC
# Line 6  var rec = null; Line 6  var rec = null;
6  var url = null;  var url = null;
7  var template_filename = null;  var template_filename = null;
8    
9    var pending_js = null;
10    
11  var css_rnd = 0;  var css_rnd = 0;
12    
13  function iwfRequest( url, div ) {  function _ts(text) {
14          Logger.info('iwfRequest('+url+','+div+')');          var el = $('div_template_status');
15          return;          if (el) el.innerHTML = text;
16  }  }
17    
18  function update_status(text) {  function _cs(text) {
19          var el = $('div_record_nr');          var el = $('div_css_status');
20          if (el) el.innerHTML = text;          if (el) el.innerHTML = text;
21  }  }
22    
23  function load_rec(nr) {  function load_rec(nr, tmp_template_filename) {
24          Logger.debug('load_rec '+nr);  
25            if (! nr) {
26                    Logger.error('load_rec called without nr');
27                    return false;
28            }
29    
30            var rec_uri = $F('rec_uri_prefix');
31            if (! rec_uri) Logger.error('rec_uri_prefix field not found in form!');
32            rec_uri += '/' + nr;
33    
34            if (! tmp_template_filename) tmp_template_filename = template_filename;
35            Logger.info('load_rec '+rec_uri+' in '+tmp_template_filename);
36    
37          if (loading.record) {          if (loading.record) {
38                  Logger.info('loading of record '+nr+' skipped, load in progress');                  Logger.info('loading of record '+rec_uri+' skipped, load in progress');
39                  return;                  return false;
40          }          }
41    
42            show_working();
43            $('record_nr').disabled = 'true';
44    
45          if (nr == 1) {          if (nr == 1) {
46                  Element.addClassName('a_left_arr', 'nav_disable');                  Element.addClassName('a_left_arr', 'nav_disable');
47          } else {          } else {
48                  Element.removeClassName('a_left_arr', 'nav_disable');                  Element.removeClassName('a_left_arr', 'nav_disable');
49          }          }
50    
51          var args = '?mfn='+nr+'&template_filename='+template_filename;          var args = '?record_uri='+rec_uri+'&template_filename='+tmp_template_filename;
52    
53          new Ajax.Updater( 'div_record',  url+'record'+args, {          new Ajax.Updater( 'div_record',  url+'record'+args, {
54                  asynchronous: 1,                  asynchronous: 1,
55                  onLoading: function(request) {                  onLoading: function(request) {
56                          loading.record = 1;                          loading.record = 1;
                         update_status(nr+'...');  
57                          Logger.info('load_rec.onLoading: '+nr);                          Logger.info('load_rec.onLoading: '+nr);
58                  },                  },
59                  onLoaded: function(request) {                  onLoaded: function(request) {
60                          loading.record = 0;                          loading.record = 0;
61                          update_status('# '+nr);                          hide_working();
62                            $('record_nr').value = nr;
63                            $('record_nr').disabled = '';
64                            rec = nr;
65                          Logger.info('load_rec.onLoaded: '+nr);                          Logger.info('load_rec.onLoaded: '+nr);
66                  }                  }
67          } ) ;          } ) ;
68    
69            return false;
70  }  }
71    
72  function inc_rec() {  function inc_rec() {
73            show_working();
74          rec++;          rec++;
75          load_rec(rec);          load_rec(rec);
76            hide_working();
77          return false;          return false;
78  }  }
79    
80  function dec_rec() {  function dec_rec() {
81          if (rec > 1) {          if (rec > 1) {
82                    show_working();
83                  rec--;                  rec--;
84                  load_rec(rec);                  load_rec(rec);
85                    hide_working();
86          }          }
87          return false;          return false;
88  }  }
89    
90  function reload_rec() {  function reload_rec() {
91            show_working();
92          load_rec(rec);          load_rec(rec);
93            hide_working();
94          return false;          return false;
95  }  }
96    
97  var current_edit = '';  var current_edit = '';
98    
99  function edit_template() {  function edit_template() {
100          $('div_css').style.visibility = "hidden";          Element.hide('row_css');
101    
102          Element.removeClassName('a_css', 'tab_selected');          Element.removeClassName('a_css', 'tab_selected');
103          Element.addClassName('a_template', 'tab_selected');          Element.addClassName('a_template', 'tab_selected');
104          $('div_template').style.visibility = "visible";  
105            Element.show('row_template');
106    
107          Logger.debug("switched to template editor");          Logger.debug("switched to template editor");
108          var c = $('template_content');          var c = $('template_content');
109          if (c) c.focus();          if (c) c.focus();
110            Logger.debug('zIndex template:'+$('row_template').style.zIndex+' css:'+$('row_css').style.zIndex);
111          return false;          return false;
112  }  }
113    
114  function edit_css() {  function edit_css() {
115          $('div_template').style.visibility = "hidden";  
116            Element.hide('row_template');
117    
118          Element.removeClassName('a_template', 'tab_selected');          Element.removeClassName('a_template', 'tab_selected');
119          Element.addClassName('a_css', 'tab_selected');          Element.addClassName('a_css', 'tab_selected');
120          $('div_css').style.visibility = "visible";  
121            Element.show('row_css');
122    
123          Logger.debug("switched to CSS editor");          Logger.debug("switched to CSS editor");
124          var c = $('css_content');          var c = $('css_content');
125          if (c) c.focus();          if (c) c.focus();
126            Logger.debug('zIndex template:'+$('row_template').style.zIndex+' css:'+$('row_css').style.zIndex);
127          return false;          return false;
128  }  }
129    
130  function switch_template(template_name) {  function switch_template(new_template_filename) {
131    
132            Logger.info('switch_template to '+new_template_filename);
133            show_working();
134    
         Logger.info('switch_template to '+template_name);  
         new Effect.Opacity('div_template', { from: 1.0, to: 0.7, duration: 0.3 });  
135          Logger.debug('load template editor');          Logger.debug('load template editor');
136          load_template(template_name);          template_filename = new_template_filename;
137            load_template(new_template_filename);
138    
139          Logger.debug('refresh record');          Logger.debug('refresh record');
140          load_rec(rec);          load_rec(rec);
141    
142            edKill('template_content');
143    
144            hide_working();
145    
146            return false;
147  }  }
148    
149  var loading = {  var loading = {
150          template: 0,          template: 0,
151          css: 0,          css: 0,
152          record: 0,          record: 0
153          template_list: 0,  };
 }  
154    
155  function load_template( template_filename ) {  function load_template( template_filename ) {
156    
# Line 118  function load_template( template_filenam Line 159  function load_template( template_filenam
159                  return;                  return;
160          }          }
161    
162            show_working();
163    
164          var args = '?template_filename='+template_filename;          var args = '?template_filename='+template_filename;
165    
166          new Ajax.Updater( 'div_template',  url+'template'+args, {          new Ajax.Updater( 'row_template',  url+'template'+args, {
167                  asynchronous: 1,                  asynchronous: 1,
168                  onLoading: function(request) {                  onLoading: function(request) {
169                          loading.template = 1;                          loading.template = 1;
# Line 128  function load_template( template_filenam Line 171  function load_template( template_filenam
171                  },                  },
172                  onLoaded: function(request) {                  onLoaded: function(request) {
173                          loading.template = 0;                          loading.template = 0;
174                          Position.clone('div_template', 'div_css');                          hide_working();
175                          Logger.info('load_template.onLoaded: '+template_filename);                          Logger.info('load_template.onLoaded: '+template_filename);
176                  }                  }
177          } ) ;          } ) ;
178  }  }
179    
180  function load_css(css_filename) {  function load_css( css_filename ) {
181    
182          if (loading.css) {          if (loading.css) {
183                  Logger.info('loading of css '+css_filename+' skipped, load in progress');                  Logger.info('loading of css '+css_filename+' skipped, load in progress');
184                  return;                  return;
185          }          }
186    
187          new Ajax.Updater( 'div_css',  url+'css', {          var css_url = url + 'css?css_filename='+css_filename;
188    
189            Logger.info('load_css '+css_url);
190    
191            show_working();
192    
193            new Ajax.Updater( 'row_css', css_url, {
194                  asynchronous: 1,                  asynchronous: 1,
195                  onLoading: function(request) {                  onLoading: function(request) {
196                          loading.css = 1;                          loading.css = 1;
# Line 149  function load_css(css_filename) { Line 198  function load_css(css_filename) {
198                  },                  },
199                  onLoaded: function(request) {                  onLoaded: function(request) {
200                          loading.css = 0;                          loading.css = 0;
201                            hide_working();
202                          Logger.info('load_css.onLoaded: '+css_filename);                          Logger.info('load_css.onLoaded: '+css_filename);
203                            reload_css( css_filename );
204                  }                  }
205          } ) ;          } ) ;
206  };  };
207    
208  function init_page() {  function reload_css( css_filename ) {
209    
210            if (! css_filename) css_filename = 'user.css';
211    
212            css_rnd++;
213            var css_url = '/css/' + css_filename + '?' + css_rnd;
214            Logger.info('reload_css from '+css_url);
215            $('user_css_link').href = css_url;
216    
217            return false;
218    }
219    
220  //      Element.hide('div_css');  var working_count = 0;
 //      Element.show('div_template');  
221    
222  //      Position.clone('div_template', 'div_css');  function show_working() {
223            working_count++;
224            if (working_count > 1) Element.show('working');
225            Logger.debug('show_working, count = '+working_count);
226    }
227    
228    function hide_working() {
229            working_count--;
230            if (working_count < 1) Element.hide('working');
231            Logger.debug('hide_working, count = '+working_count);
232    }
233    
234    /* called body.onLoad */
235    
236    function init_page() {
237            show_working();
238    
239            textarea_reset_size( 'template_content' );
240            textarea_reset_size( 'css_content' );
241    
242          edit_template();          edit_template();
243    
244          // load css editor          hide_working();
245          load_css();  }
246    
247          // load template editor and record  /* resize textarea */
         switch_template(template_filename);  
248    
249    function textarea_reset_size( id ) {
250            var textarea = $( id );
251            if (! textarea) {
252                    Logger.error('can\'t reset size to non-existant textarea '+id);
253                    return;
254            }
255            var hgt = Cookie.get('webpacus_ta_'+id);
256            if (! hgt) hgt='20em';
257            textarea.style.height = hgt;
258            Logger.debug('reset textarea '+id+' height to '+hgt);
259  }  }
260    
261    function textarea_resize( id, val ){
262            var textarea = $( id );
263            var height = parseInt(textarea.style.height.substr(0,textarea.style.height.length-2));
264            height += val;
265            Logger.debug('resize_textarea('+id+','+val+') '+textarea.style.height+' '+height);
266            textarea.style.height = height+'px';
267            Cookie.set('webpacus_ta_'+id,textarea.style.height,365);
268    }

Legend:
Removed from v.167  
changed lines
  Added in v.357

  ViewVC Help
Powered by ViewVC 1.1.26