--- Webpacus/root/editor/editor.js 2005/11/26 18:18:10 163 +++ Webpacus/root/editor/editor.js 2005/11/29 13:04:44 191 @@ -6,46 +6,87 @@ var url = null; var template_filename = null; +var pending_js = null; + var css_rnd = 0; -function iwfRequest( url, div ) { - Logger.info('iwfRequest('+url+','+div+')'); - return; +function _ts(text) { + var el = $('div_template_status'); + if (el) el.innerHTML = text; } -function update_status(text) { - var el = $('div_record_nr'); +function _cs(text) { + var el = $('div_css_status'); if (el) el.innerHTML = text; } -function load_rec(nr) { - Logger.debug('load_rec '+nr); +function load_rec(nr, tmp_template_filename) { + + if (! nr) { + Logger.error('load_rec called without nr'); + return false; + } + + if (! tmp_template_filename) tmp_template_filename = template_filename; + Logger.info('load_rec '+nr+' in '+tmp_template_filename); + + if (loading.record) { + Logger.info('loading of record '+nr+' skipped, load in progress'); + return false; + } + + show_working(); + $('record_nr').disabled = 'true'; + if (nr == 1) { - Element.hide('a_left_arr'); + Element.addClassName('a_left_arr', 'nav_disable'); } else { - Element.show('a_left_arr'); + Element.removeClassName('a_left_arr', 'nav_disable'); } - update_status(nr+'...'); - iwfRequest( url+'/xml/?template='+template_filename+'&rec='+nr, 'div_record' ); - new Effect.Opacity('div_record', { from: 1.0, to: 0.7, duration: 0.3 }); + + var args = '?mfn='+nr+'&template_filename='+tmp_template_filename; + + new Ajax.Updater( 'div_record', url+'record'+args, { + asynchronous: 1, + onLoading: function(request) { + loading.record = 1; + Logger.info('load_rec.onLoading: '+nr); + }, + onLoaded: function(request) { + loading.record = 0; + hide_working(); + $('record_nr').value = nr; + $('record_nr').disabled = ''; + rec = nr; + Logger.info('load_rec.onLoaded: '+nr); + } + } ) ; + + return false; } function inc_rec() { + show_working(); rec++; load_rec(rec); + hide_working(); return false; } function dec_rec() { if (rec > 1) { + show_working(); rec--; load_rec(rec); + hide_working(); } return false; } function reload_rec() { + show_working(); load_rec(rec); + hide_working(); return false; } @@ -53,90 +94,136 @@ function edit_template() { $('div_css').style.visibility = "hidden"; + $('div_css').style.zIndex = 1; Element.removeClassName('a_css', 'tab_selected'); Element.addClassName('a_template', 'tab_selected'); $('div_template').style.visibility = "visible"; + $('div_template').style.zIndex = 2; Logger.debug("switched to template editor"); - $('template_content').focus(); + var c = $('template_content'); + if (c) c.focus(); + Logger.debug('zIndex template:'+$('div_template').style.zIndex+' css:'+$('div_css').style.zIndex); return false; } function edit_css() { $('div_template').style.visibility = "hidden"; + $('div_template').style.zIndex = 1; Element.removeClassName('a_template', 'tab_selected'); Element.addClassName('a_css', 'tab_selected'); $('div_css').style.visibility = "visible"; + $('div_css').style.zIndex = 2; Logger.debug("switched to CSS editor"); - $('css_content').focus(); + var c = $('css_content'); + if (c) c.focus(); + Logger.debug('zIndex template:'+$('div_template').style.zIndex+' css:'+$('div_css').style.zIndex); return false; } -function switch_template(template_name) { +function switch_template(new_template_filename) { + + Logger.info('switch_template to '+new_template_filename); + show_working(); - Logger.info('switch_template to '+template_name); - new Effect.Opacity('div_template', { from: 1.0, to: 0.7, duration: 0.3 }); Logger.debug('load template editor'); - load_template(template_name); + template_filename = new_template_filename; + load_template(new_template_filename); Logger.debug('refresh record'); load_rec(rec); - Logger.debug('refresh template list'); - iwfRequest( url+'/template_list/?template='+template_filename, 'div_template_list' ); + edKill('template_content'); + + hide_working(); + + return false; } var loading = { template: 0, css: 0, -} + record: 0 +}; -function load_template( template ) { +function load_template( template_filename ) { if (loading.template) { - Logger.info('loading of template '+name+' skipped, load in progress'); + Logger.info('loading of template '+template_filename+' skipped, load in progress'); return; } - new Ajax.Updater( 'div_template', url+'template', { + show_working(); + + var args = '?template_filename='+template_filename; + + new Ajax.Updater( 'div_template', url+'template'+args, { asynchronous: 1, onLoading: function(request) { loading.template = 1; - Logger.info('load_template.onLoading: '+template); + Logger.info('load_template.onLoading: '+template_filename); }, onLoaded: function(request) { loading.template = 0; Position.clone('div_template', 'div_css'); - Logger.info('load_template.onLoaded: '+template); + hide_working(); + Logger.info('load_template.onLoaded: '+template_filename); } } ) ; } -function load_css(css_file) { +function load_css(css_filename) { if (loading.css) { - Logger.info('loading of css '+name+' skipped, load in progress'); + Logger.info('loading of css '+css_filename+' skipped, load in progress'); return; } + show_working(); + new Ajax.Updater( 'div_css', url+'css', { asynchronous: 1, onLoading: function(request) { loading.css = 1; - Logger.info('load_css.onLoading: '+css_file); + Logger.info('load_css.onLoading: '+css_filename); }, onLoaded: function(request) { loading.css = 0; - Logger.info('load_css.onLoaded: '+css_file); + hide_working(); + Logger.info('load_css.onLoaded: '+css_filename); + Element.clone('div_template', 'div_css'); } } ) ; }; +function reload_css() { + + css_rnd++; + var css_url = url + 'css/user.css?'+css_rnd; + Logger.info('reload_css from '+css_url); + $('user_css_link').href = css_url; + + return false; +} + +var working_count = 0; + +function show_working() { + working_count++; + if (working_count > 1) Element.show('working'); + Logger.debug('show_working, count = '+working_count); +} + +function hide_working() { + working_count--; + if (working_count < 1) Element.hide('working'); + Logger.debug('hide_working, count = '+working_count); +} + function init_page() { -// Element.hide('div_css'); -// Element.show('div_template'); + show_working(); -// Position.clone('div_template', 'div_css'); + edit_template(); // load css editor load_css(); @@ -144,5 +231,7 @@ // load template editor and record switch_template(template_filename); + hide_working(); + }