removed old event model, fixes in ui
This commit is contained in:
parent
7efe72e282
commit
90337d8ac2
13 changed files with 35 additions and 165 deletions
|
|
@ -75,9 +75,6 @@ function startup() {
|
|||
startup_list[i]();
|
||||
}
|
||||
|
||||
$dh('startup_div');
|
||||
$ds('body_div');
|
||||
|
||||
// show a new form on loading?
|
||||
if(get_url_arg('embed')) {
|
||||
newdoc(get_url_arg('embed'));
|
||||
|
|
@ -92,6 +89,8 @@ function startup() {
|
|||
// show home oage
|
||||
loadpage(home_page);
|
||||
}
|
||||
$dh('startup_div');
|
||||
$ds('body_div');
|
||||
}
|
||||
if(_startup_data && keys(_startup_data).length && _startup_data.docs) {
|
||||
LocalDB.sync(_startup_data.docs);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ var sp1=null;var sp2=null;if(doc.__islocal){label='Unsaved Draft';col='#F81';}el
|
|||
sp1=make_tag(label,col);this.set_in_recent(doc,col);return[sp1,sp2];}
|
||||
_f.FrmHeader.prototype.set_in_recent=function(doc,col){var tn=$i('rec_'+doc.doctype+'-'+doc.name);if(tn)
|
||||
$y(tn,{backgroundColor:col});}
|
||||
_f.FrmHeader.prototype.set_save_submit_color=function(doc){var save_btn=this.page_head.buttons['Save'];var submit_btn=this.page_head.buttons['Submit'];if(cint(doc.docstatus)==0&&submit_btn&&save_btn){if(cint(doc.__unsaved)){save_btn.className='cupid-green';submit_btn.className='clean-gray';}else{save_btn.className='clean-gray';submit_btn.className='cupid-green';}}}
|
||||
_f.FrmHeader.prototype.set_save_submit_color=function(doc){var save_btn=this.page_head.buttons['Save'];var submit_btn=this.page_head.buttons['Submit'];if(cint(doc.docstatus)==0&&submit_btn&&save_btn){if(cint(doc.__unsaved)){$(save_btn).addClass('success');$(submit_btn).removeClass('success');}else{$(submit_btn).addClass('success');$(save_btn).removeClass('success');}}}
|
||||
_f.FrmHeader.prototype.refresh_labels=function(f){var ph=this.page_head;var me=this;this.dt_area.innerHTML=get_doctype_label(f.doctype);this.dn_area.innerHTML='';if(!f.meta.issingle)
|
||||
this.dn_area.innerHTML=f.docname;var doc=locals[f.doctype][f.docname];var sl=this.get_status_tags(doc,f);this.set_save_submit_color(doc);var t=this.status_area;t.innerHTML='';t.appendChild(sl[0]);if(sl[1])t.appendChild(sl[1]);this.timestamp_area.innerHTML=me.get_timestamp(doc);}
|
||||
_f.edit_record=function(dt,dn){d=_f.frm_dialog;var show_dialog=function(){var f=frms[dt];if(f.meta.istable){f.parent_doctype=cur_frm.doctype;f.parent_docname=cur_frm.docname;}
|
||||
|
|
|
|||
|
|
@ -526,9 +526,9 @@ var user_img_loading = [];
|
|||
set_user_img = function(img, username, get_latest, img_id) {
|
||||
function set_it(i) {
|
||||
if(user_img[username]=='no_img_m')
|
||||
i.src = 'lib/images/no_img_m.gif';
|
||||
i.src = 'lib/images/ui/no_img_m.gif';
|
||||
else if(user_img[username]=='no_img_f')
|
||||
i.src = 'lib/images/no_img_f.gif'; // no image
|
||||
i.src = 'lib/images/ui/no_img_f.gif'; // no image
|
||||
else {
|
||||
ac_id = locals['Control Panel']['Control Panel'].account_id;
|
||||
i.src = repl('cgi-bin/getfile.cgi?ac=%(ac)s&name=%(fn)s', {fn:user_img[username], ac:ac_id});
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ PageHeader.prototype.add_button = function(label, fn, bold, icon, green) {
|
|||
var tb = this.toolbar_area;
|
||||
if(this.buttons[label]) return;
|
||||
|
||||
var btn = $btn(tb,label,fn,{marginRight:'4px'},(green ? 'green' : ''));
|
||||
var btn = $btn(tb,label,fn,{marginRight:'4px'}, (green ? 'success' : ''));
|
||||
if(bold) $y(btn,{fontWeight:'bold'});
|
||||
|
||||
this.buttons[label]=btn;
|
||||
|
|
|
|||
|
|
@ -176,11 +176,11 @@ _f.FrmHeader.prototype.set_save_submit_color = function(doc) {
|
|||
|
||||
if(cint(doc.docstatus)==0 && submit_btn && save_btn) {
|
||||
if(cint(doc.__unsaved)) {
|
||||
save_btn.className = 'cupid-green';
|
||||
submit_btn.className = 'clean-gray';
|
||||
$(save_btn).addClass('success');
|
||||
$(submit_btn).removeClass('success');
|
||||
} else {
|
||||
save_btn.className = 'clean-gray';
|
||||
submit_btn.className = 'cupid-green';
|
||||
$(submit_btn).addClass('success');
|
||||
$(save_btn).removeClass('success');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,8 +205,8 @@ return d;},get_base_url:function(){var url=window.location.href.split('#')[0].sp
|
|||
return url},get_file_url:function(file_id){var ac_id=locals['Control Panel']['Control Panel'].account_id;return repl('cgi-bin/getfile.cgi?name=%(fn)s&acx=%(ac)s',{fn:file_id,ac:ac_id})}}
|
||||
get_url_arg=wn.urllib.get_arg;get_url_dict=wn.urllib.get_dict;var user_img={}
|
||||
var user_img_queue={};var user_img_loading=[];set_user_img=function(img,username,get_latest,img_id){function set_it(i){if(user_img[username]=='no_img_m')
|
||||
i.src='lib/images/no_img_m.gif';else if(user_img[username]=='no_img_f')
|
||||
i.src='lib/images/no_img_f.gif';else{ac_id=locals['Control Panel']['Control Panel'].account_id;i.src=repl('cgi-bin/getfile.cgi?ac=%(ac)s&name=%(fn)s',{fn:user_img[username],ac:ac_id});}}
|
||||
i.src='lib/images/ui/no_img_m.gif';else if(user_img[username]=='no_img_f')
|
||||
i.src='lib/images/ui/no_img_f.gif';else{ac_id=locals['Control Panel']['Control Panel'].account_id;i.src=repl('cgi-bin/getfile.cgi?ac=%(ac)s&name=%(fn)s',{fn:user_img[username],ac:ac_id});}}
|
||||
if(img_id){user_img[username]=img_id;set_it(img);return;}
|
||||
if(user_img[username]&&!get_latest){set_it(img);}else{if(in_list(user_img_loading,username)){if(!user_img_queue[username])
|
||||
user_img_queue[username]=[];user_img_queue[username].push(img);return;}
|
||||
|
|
@ -531,7 +531,7 @@ this.show=function(){$ds(me.ldiv);}}
|
|||
var def_ph_style={wrapper:{marginBottom:'16px',backgroundColor:'#EEE'},main_heading:{},sub_heading:{marginBottom:'8px',color:'#555',display:'none'},separator:{borderTop:'3px solid #444'},toolbar_area:{padding:'3px 0px',display:'none',borderBottom:'1px solid #AAA'}}
|
||||
function PageHeader(parent,main_text,sub_text){this.wrapper=$a(parent,'div','page_header');this.t1=make_table($a(this.wrapper,'div','',def_ph_style.wrapper.backgroundColor),1,2,'100%',[null,'100px'],{padding:'2px'});$y(this.t1,{borderCollapse:'collapse'})
|
||||
this.lhs=$td(this.t1,0,0);this.main_head=$a(this.lhs,'h1','',def_ph_style.main_heading);this.sub_head=$a(this.lhs,'h4','',def_ph_style.sub_heading);this.separator=$a(this.wrapper,'div','',def_ph_style.separator);this.toolbar_area=$a(this.wrapper,'div','',def_ph_style.toolbar_area);this.padding_area=$a(this.wrapper,'div','',{padding:'3px'});$y($td(this.t1,0,1),{textAlign:'right',padding:'3px'});this.close_btn=$btn($td(this.t1,0,1),'Close',function(){nav_obj.show_last_open();},0);if(main_text)this.main_head.innerHTML=main_text;if(sub_text)this.sub_head.innerHTML=sub_text;this.buttons={};this.buttons2={};}
|
||||
PageHeader.prototype.add_button=function(label,fn,bold,icon,green){var tb=this.toolbar_area;if(this.buttons[label])return;var btn=$btn(tb,label,fn,{marginRight:'4px'},(green?'green':''));if(bold)$y(btn,{fontWeight:'bold'});this.buttons[label]=btn;$ds(this.toolbar_area);return btn;}
|
||||
PageHeader.prototype.add_button=function(label,fn,bold,icon,green){var tb=this.toolbar_area;if(this.buttons[label])return;var btn=$btn(tb,label,fn,{marginRight:'4px'},(green?'success':''));if(bold)$y(btn,{fontWeight:'bold'});this.buttons[label]=btn;$ds(this.toolbar_area);return btn;}
|
||||
PageHeader.prototype.clear_toolbar=function(){this.toolbar_area.innerHTML='';this.buttons={};}
|
||||
PageHeader.prototype.make_buttonset=function(){$(this.toolbar_area).buttonset();}
|
||||
function SelectWidget(parent,options,width,editable,bg_color){var me=this;this.inp=$a(parent,'select');if(options)add_sel_options(this.inp,options);if(width)$y(this.inp,{width:width});this.set_width=function(w){$y(this.inp,{width:w})};this.set_options=function(o){add_sel_options(this.inp,o);}
|
||||
|
|
@ -858,8 +858,9 @@ var setup_events=function(){addEvent('keyup',function(ev,target){for(var i in ke
|
|||
keypress_observers[i].notify_keypress(ev,ev.keyCode);}});addEvent('click',function(ev,target){for(var i=0;i<click_observers.length;i++){if(click_observers[i])
|
||||
click_observers[i].notify_click(ev,target);}});if(isIE){$op($i('dialog_back'),60);}}
|
||||
var callback=function(r,rt){if(r.exc)console.log(r.exc);setup_globals(r);setup_history();setup_events();var a=new Body();page_body.run_startup_code();page_body.setup_sidebar_menu();for(var i=0;i<startup_list.length;i++){startup_list[i]();}
|
||||
$dh('startup_div');$ds('body_div');if(get_url_arg('embed')){newdoc(get_url_arg('embed'));return;}
|
||||
var t=to_open();if(t){historyChange(t);}else if(home_page){loadpage(home_page);}}
|
||||
if(get_url_arg('embed')){newdoc(get_url_arg('embed'));return;}
|
||||
var t=to_open();if(t){historyChange(t);}else if(home_page){loadpage(home_page);}
|
||||
$dh('startup_div');$ds('body_div');}
|
||||
if(_startup_data&&keys(_startup_data).length&&_startup_data.docs){LocalDB.sync(_startup_data.docs);callback(_startup_data,'');if(_startup_data.server_messages)msgprint(_startup_data.server_messages);}else{if($i('startup_div'))
|
||||
$c('startup',{},callback,null,1);}}
|
||||
function to_open(){if(get_url_arg('page'))
|
||||
|
|
|
|||
|
|
@ -97,7 +97,9 @@ wn.ui.toolbar.Toolbar = Class.extend({
|
|||
}
|
||||
},
|
||||
make_logout: function() {
|
||||
$('.topbar .nav.secondary-nav a.dropdown-toggle').html(user_fullname);
|
||||
var fn = user_fullname;
|
||||
if(fn.length > 15) fn = fn.substr(0,12) + '...';
|
||||
$('.topbar .nav.secondary-nav a.dropdown-toggle').html(fn);
|
||||
|
||||
// logout
|
||||
$('#toolbar-user').append('<li><a href="#" onclick="return logout();">Logout</a></li>');
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
# DocType, DocTrigger
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2011-04-08 10:50:39',
|
||||
'docstatus': 0,
|
||||
'modified': '2011-03-31 15:23:46',
|
||||
'modified_by': 'Administrator',
|
||||
'owner': 'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all DocType
|
||||
{
|
||||
'autoname': '_TRIGGER.######',
|
||||
'colour': 'White:FFF',
|
||||
'doctype': 'DocType',
|
||||
'in_create': 1,
|
||||
'module': 'Core',
|
||||
'name': '__common__',
|
||||
'read_only': 1,
|
||||
'section_style': 'Simple',
|
||||
'show_in_menu': 0,
|
||||
'version': 2
|
||||
},
|
||||
|
||||
# These values are common for all DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldtype': 'Data',
|
||||
'name': '__common__',
|
||||
'parent': 'DocTrigger',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0
|
||||
},
|
||||
|
||||
# DocType, DocTrigger
|
||||
{
|
||||
'doctype': 'DocType',
|
||||
'name': 'DocTrigger'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'doc_type',
|
||||
'idx': 1,
|
||||
'label': 'Doc Type',
|
||||
'search_index': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'doc_name',
|
||||
'idx': 2,
|
||||
'label': 'Doc Name',
|
||||
'search_index': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'event_name',
|
||||
'idx': 3,
|
||||
'label': 'Event Name'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'method',
|
||||
'idx': 4,
|
||||
'label': 'Method'
|
||||
}
|
||||
]
|
||||
|
|
@ -174,8 +174,8 @@ class DocList:
|
|||
if hasattr(self.obj, 'custom_' + method):
|
||||
getattr(self.obj, 'custom_' + method)()
|
||||
|
||||
from webnotes.model.triggers import fire_event
|
||||
fire_event(self.doc, method)
|
||||
from webnotes.model.events import trigger
|
||||
trigger(method, self.doc)
|
||||
|
||||
def save_main(self):
|
||||
"""
|
||||
|
|
|
|||
14
py/webnotes/model/events.py
Normal file
14
py/webnotes/model/events.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
"""trigger doctype events"""
|
||||
|
||||
def trigger(method, doc):
|
||||
try:
|
||||
import startup.event_handlers
|
||||
except ImportError:
|
||||
return
|
||||
|
||||
if hasattr(startup.event_handlers, method):
|
||||
getattr(startup.event_handlers, method)(doc)
|
||||
|
||||
if hasattr(startup.event_handlers, 'doclist_all'):
|
||||
startup.event_handlers.doclist_all(doc, method)
|
||||
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
"""
|
||||
Add, manage, fire triggers (events / observers)
|
||||
Standard events called by the framework are "save, submit, cancel"
|
||||
"""
|
||||
|
||||
import webnotes
|
||||
|
||||
def insert_trigger(doctype, docname, event_name, method):
|
||||
"inserts a new trigger record"
|
||||
|
||||
from webnotes.model.doc import Document
|
||||
d = Document('DocTrigger')
|
||||
d.doc_type = doctype
|
||||
d.doc_name = docname
|
||||
d.event_name = event_name
|
||||
d.method = method
|
||||
d.save(1)
|
||||
|
||||
def add_trigger(doctype, docname, event_name, method):
|
||||
"""Add a trigger to an event on a doctype, docname. The specified method will be called.
|
||||
Wild card '*' is allowed in doctype, docname and/or event_name"""
|
||||
|
||||
try:
|
||||
if not trigger_exists(doctype, docname, event_name, method):
|
||||
insert_trigger(doctype, docname, event_name, method)
|
||||
except Exception, e:
|
||||
if e.args[0]==1146:
|
||||
setup()
|
||||
insert_trigger(doctype, docname, event_name, method)
|
||||
else: raise e
|
||||
|
||||
def trigger_exists(doctype, docname, event_name, method):
|
||||
"returns true if trigger exists"
|
||||
return webnotes.conn.sql("select name from tabDocTrigger where doc_name=%s and doc_type=%s and event_name=%s and method=%s", \
|
||||
(doctype, docname, event_name, method))
|
||||
|
||||
def remove_trigger(doctype, docname, event_name, method):
|
||||
"Remove a trigger on an event"
|
||||
webnotes.conn.sql("delete from tabDocTrigger where doc_name=%s and doc_type=%s and event_name=%s and method=%s", \
|
||||
(doctype, docname, event_name, method))
|
||||
|
||||
def fire_event(doc, event_name):
|
||||
"Fire all triggers on an event and passes the doc to the trigger"
|
||||
try:
|
||||
tl = webnotes.conn.sql("""select method from tabDocTrigger
|
||||
where (doc_type=%s or doc_type='*')
|
||||
and (doc_name=%s or doc_name='*')
|
||||
and (event_name=%s or event_name='*')""", (doc.doctype, doc.name, event_name))
|
||||
except Exception, e:
|
||||
if e.args[0]==1146:
|
||||
setup()
|
||||
tl = []
|
||||
else: raise e
|
||||
|
||||
for t in tl:
|
||||
module, method = '.'.join(t[0].split('.')[:-1]), t[0].split('.')[-1]
|
||||
exec 'from %s import %s' % (module, method) in locals()
|
||||
locals()[method](doc, event_name)
|
||||
#
|
||||
# setup
|
||||
#
|
||||
def setup():
|
||||
"creates the DocTrigger table from core"
|
||||
webnotes.conn.commit()
|
||||
from webnotes.modules.module_manager import reload_doc
|
||||
reload_doc('core','doctype','doctrigger')
|
||||
webnotes.conn.begin()
|
||||
|
||||
|
|
@ -5,7 +5,6 @@ Server side handler for "Form" events
|
|||
import webnotes
|
||||
import webnotes.model.doc
|
||||
import webnotes.model.meta
|
||||
from webnotes.model.triggers import fire_event
|
||||
|
||||
def getdoc():
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue