major reworking of page navigation
This commit is contained in:
parent
8b9fbad95a
commit
5edda1dc22
34 changed files with 615 additions and 1248 deletions
|
|
@ -26,8 +26,6 @@
|
|||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
<script src="lib/js/wn/ui/listing.js"></script>
|
||||
<script src="lib/js/wn/pages/doclistview.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
{{ body_html }}
|
||||
|
|
|
|||
14
css/ui/container.css
Normal file
14
css/ui/container.css
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#body_div {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 900px;
|
||||
position: absolute;
|
||||
left: 1000px;
|
||||
-webkit-transition:all 0.5s ease-in-out;
|
||||
-moz-transition:all 0.5s ease-in-out;
|
||||
-o-transition:all 0.5s ease-in-out;
|
||||
-ms-transition:all 0.5s ease-in-out;
|
||||
transition:all 0.5s ease-in-out;
|
||||
}
|
||||
202
js/core.min.js
vendored
202
js/core.min.js
vendored
|
|
@ -24,8 +24,7 @@ localStorage.setItem('_version_number',window._version_number);}}}
|
|||
wn.assets={executed_:{},exists:function(src){if('localStorage'in window&&localStorage.getItem(src))
|
||||
return true},add:function(src,txt){if('localStorage'in window){localStorage.setItem(src,txt);}},get:function(src){return localStorage.getItem(src);},extn:function(src){if(src.indexOf('?')!=-1){src=src.split('?').slice(-1)[0];}
|
||||
return src.split('.').slice(-1)[0];},load:function(src){var t=src;$.ajax({url:t,data:{q:Math.floor(Math.random()*1000)},dataType:'text',success:function(txt){wn.assets.add(src,txt);},async:false})},execute:function(src){if(!wn.assets.exists(src)){wn.assets.load(src);}
|
||||
var type=wn.assets.extn(src);if(wn.assets.handler[type]){wn.assets.handler[type](wn.assets.get(src),src);wn.assets.executed_[src]=1;}},handler:{js:function(txt,src){wn.dom.eval(txt);},css:function(txt,src){var se=document.createElement('style');se.type="text/css";if(se.styleSheet){se.styleSheet.cssText=txt;}else{se.appendChild(document.createTextNode(txt));}
|
||||
document.getElementsByTagName('head')[0].appendChild(se);},cgi:function(txt,src){wn.dom.eval(txt)}}}
|
||||
var type=wn.assets.extn(src);if(wn.assets.handler[type]){wn.assets.handler[type](wn.assets.get(src),src);wn.assets.executed_[src]=1;}},handler:{js:function(txt,src){wn.dom.eval(txt);},css:function(txt,src){wn.dom.set_style(txt);},cgi:function(txt,src){wn.dom.eval(txt)}}}
|
||||
/*
|
||||
* lib/js/wn/require.js
|
||||
*/
|
||||
|
|
@ -35,7 +34,9 @@ var l=items.length;for(var i=0;i<l;i++){var src=items[i];if(!(src in wn.assets.e
|
|||
* lib/js/wn/dom.js
|
||||
*/
|
||||
wn.provide('wn.dom');wn.dom.by_id=function(id){return document.getElementById(id);}
|
||||
wn.dom.eval=function(txt){var el=document.createElement('script');el.appendChild(document.createTextNode(txt));document.getElementsByTagName('head')[0].appendChild(el);}
|
||||
wn.dom.eval=function(txt){if(!txt)return;var el=document.createElement('script');el.appendChild(document.createTextNode(txt));document.getElementsByTagName('head')[0].appendChild(el);}
|
||||
wn.dom.set_style=function(txt){if(!txt)return;var se=document.createElement('style');se.type="text/css";if(se.styleSheet){se.styleSheet.cssText=txt;}else{se.appendChild(document.createTextNode(txt));}
|
||||
document.getElementsByTagName('head')[0].appendChild(se);}
|
||||
wn.dom.add=function(parent,newtag,className,cs,innerHTML,onclick){if(parent&&parent.substr)parent=wn.dom.by_id(parent);var c=document.createElement(newtag);if(parent)
|
||||
parent.appendChild(c);if(className){if(newtag.toLowerCase()=='img')
|
||||
c.src=className
|
||||
|
|
@ -47,14 +48,7 @@ wn.get_cookie=function(c){var t=""+document.cookie;var ind=t.indexOf(c);if(ind==
|
|||
/*
|
||||
* lib/js/wn/model.js
|
||||
*/
|
||||
wn.provide('wn.model');wn.model.no_value_type=['Section Break','Column Break','HTML','Table','Button','Image'];wn.model.can_delete=function(doctype){if(!doctype)return false;return locals.DocType[doctype].allow_trash&&wn.boot.profile.can_cancel.indexOf(doctype)!=-1;}
|
||||
/*
|
||||
* lib/js/wn/page.js
|
||||
*/
|
||||
wn.page={set:function(src){var new_selection=$('.inner div.content[_src="'+src+'"]');if(!new_selection.length){wn.assets.execute(src);new_selection=$('.inner div.content[_src="'+src+'"]');}
|
||||
$('.inner .current_page').removeClass('current_page');new_selection.addClass('current_page');var title=$('nav ul li a[href*="'+src+'"]').attr('title')||'No Title'
|
||||
state=window.location.hash;if(state!=src){window.location.hash=state;}
|
||||
else{document.title=title;}}}
|
||||
wn.provide('wn.model');wn.model={no_value_type:['Section Break','Column Break','HTML','Table','Button','Image'],with_doctype:function(doctype,callback){if(locals.DocType[doctype]){callback();}else{wn.call({method:'webnotes.widgets.form.load.getdoctype',args:{doctype:doctype},callback:callback});}},with_doc:function(doctype,name,callback){if(!name)name=doctype;if(locals[doctype]&&locals[doctype][name]){callback(name);}else{if(name&&name.indexOf('New '+doctype)!=-1){name=LocalDB.create(doctype);callback(name);}else{wn.call({method:'webnotes.widgets.form.load.getdoc',args:{doctype:doctype,name:name},callback:function(r){callback(name);}});}}},can_delete:function(doctype){if(!doctype)return false;return locals.DocType[doctype].allow_trash&&wn.boot.profile.can_cancel.indexOf(doctype)!=-1;}}
|
||||
/*
|
||||
* lib/js/wn/misc/user.js
|
||||
*/
|
||||
|
|
@ -92,6 +86,192 @@ text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function
|
|||
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
|
||||
if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
|
||||
throw new SyntaxError('JSON.parse');};}}());
|
||||
/*
|
||||
* lib/js/wn/router.js
|
||||
*/
|
||||
wn.route=function(){var route=window.location.hash;wn._cur_route=location.hash;if(route.substr(0,1)=='#')route=route.substr(1);if(route.substr(0,1)=='!')route=route.substr(1);route=$.map(route.split('/'),function(r){return decodeURIComponent(r);});switch(route[0]){case"List":wn.views.doclistview.show(route[1]);break;case"Form":if(route.length>3){route[2]=route.splice(2).join('/');}
|
||||
wn.views.formview.show(route[1],route[2]);break;case"Report":wn.views.reportview.show(route[1],route[2]);break;default:wn.views.pageview.show(route[0]);}}
|
||||
wn.set_route=function(route){window.location.hash=route;}
|
||||
wn._cur_route=null;$(window).bind('hashchange',function(){if(location.hash==wn._cur_route)
|
||||
return;wn.route();if(wn.boot.analytics_code){try{eval(wn.boot.analytics_code);}catch(e){console.log(e);}}});
|
||||
/*
|
||||
* lib/js/wn/ui/listing.js
|
||||
*/
|
||||
wn.provide('wn.ui');wn.ui.Listing=Class.extend({init:function(opts){this.opts=opts||{};this.page_length=20;this.start=0;this.data=[];if(opts){this.make();}},prepare_opts:function(){if(this.opts.new_doctype){if(wn.boot.profile.can_read.indexOf(this.opts.new_doctype)==-1){this.opts.new_doctype=null;}else{this.opts.new_doctype=get_doctype_label(this.opts.new_doctype);}}
|
||||
if(!this.opts.no_result_message){this.opts.no_result_message='Nothing to show'}},make:function(opts){if(opts){this.opts=opts;}
|
||||
this.prepare_opts();$.extend(this,this.opts);$(this.parent).html(repl('\
|
||||
<div class="wnlist">\
|
||||
<h3 class="title hide">%(title)s</h3>\
|
||||
\
|
||||
<div class="list-filters hide">\
|
||||
<div class="show_filters well">\
|
||||
<div>\
|
||||
<button class="btn btn-small add-filter-btn">\
|
||||
<i class="icon-plus"></i> Add Filter</button>\
|
||||
</div>\
|
||||
<div class="filter_area"></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
\
|
||||
<div style="height: 37px; margin-bottom:9px" class="list-toolbar-wrapper">\
|
||||
<div class="list-toolbar">\
|
||||
<a class="btn btn-small btn-refresh btn-info">\
|
||||
<i class="icon-refresh icon-white"></i> Refresh</a>\
|
||||
<a class="btn btn-small btn-new">\
|
||||
<i class="icon-plus"></i> New</a>\
|
||||
<a class="btn btn-small btn-filter">\
|
||||
<i class="icon-search"></i> Filter</a>\
|
||||
</div>\
|
||||
<img src="lib/images/ui/button-load.gif" \
|
||||
class="img-load" style="float: left;"/>\
|
||||
</div><div style="clear:both"></div>\
|
||||
\
|
||||
<div class="no-result help hide">\
|
||||
%(no_result_message)s\
|
||||
</div>\
|
||||
\
|
||||
<div class="result">\
|
||||
<div class="result-list"></div>\
|
||||
<div class="result-grid hide"></div>\
|
||||
</div>\
|
||||
\
|
||||
<div class="paging-button">\
|
||||
<button class="btn btn-small btn-more hide">More...</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
',this.opts));this.$w=$(this.parent).find('.wnlist');this.set_events();this.make_filters();},add_button:function(html,onclick,before){$(html).click(onclick).insertBefore(this.$w.find('.list-toolbar '+before));this.btn_groupify();},show_view:function($btn,$div,$btn_unsel,$div_unsel){$btn_unsel.removeClass('btn-info');$btn_unsel.find('i').removeClass('icon-white');$div_unsel.toggle(false);$btn.addClass('btn-info');$btn.find('i').addClass('icon-white');$div.toggle(true);},set_events:function(){var me=this;this.$w.find('.btn-refresh').click(function(){me.run();});this.$w.find('.btn-more').click(function(){me.run({append:true});});if(this.title){this.$w.find('h3').html(this.title).toggle(true);}
|
||||
if(this.new_doctype){this.$w.find('.btn-new').toggle(true).click(function(){newdoc(me.new_doctype,me.new_doc_onload,true,me.new_doc_onsave);})}else{this.$w.find('.btn-new').remove();}
|
||||
if(!me.show_filters){this.$w.find('.btn-filter').remove();}
|
||||
if(this.hide_refresh||this.no_refresh){this.$w.find('.btn-refresh').remove();}
|
||||
this.btn_groupify();},btn_groupify:function(){var nbtns=this.$w.find('.list-toolbar a').length;if(nbtns>1){this.$w.find('.list-toolbar').addClass('btn-group')}
|
||||
if(nbtns==0){this.$w.find('.list-toolbar-wrapper').toggle(false);}},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
|
||||
this.onrun=a0;if(a0&&a0.callback)
|
||||
this.onrun=a0.callback;if(!a1&&!(a0&&a0.append))
|
||||
this.start=0;me.set_working(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(),callback:function(r){me.set_working(false);me.render_results(r)},no_spinner:this.opts.no_loading,btn:this.run_btn});},set_working:function(flag){this.$w.find('.img-load').toggle(flag);},get_call_args:function(){if(!this.method){this.query=this.get_query?this.get_query():this.query;this.add_limits();var args={query_max:this.query_max,as_dict:1}
|
||||
args.simple_query=this.query;}else{var args={limit_start:this.start,limit_page_length:this.page_length}}
|
||||
if(this.args)
|
||||
$.extend(args,this.args)
|
||||
if(this.get_args){$.extend(args,this.get_args());}
|
||||
return args;},render_results:function(r){if(this.start==0)this.clear();this.$w.find('.btn-more').toggle(false);if(r.message)r.values=r.message;if(r.values&&r.values.length){this.data=this.data.concat(r.values);this.render_list(r.values);}else{if(this.start==0){this.$w.find('.result').toggle(false);this.$w.find('.no-result').toggle(true);}}
|
||||
if(this.onrun)this.onrun();if(this.callback)this.callback(r);},render_list:function(values){var m=Math.min(values.length,this.page_length);for(var i=0;i<m;i++){this.render_row(this.add_row(),values[i],this,i);}
|
||||
this.start+=m;if(values.length>=this.page_length)
|
||||
this.$w.find('.btn-more').toggle(true);},add_row:function(){return this.$w.find('.result-list').append('<div class="list-row">').find('.list-row:last').get(0);},refresh:function(){this.run();},add_limits:function(){this.query+=' LIMIT '+this.start+','+(this.page_length+1);}});wn.ui.FilterList=Class.extend({init:function(opts){wn.require('lib/js/legacy/widgets/form/fields.js');$.extend(this,opts);this.filters=[];this.$w=this.$parent;this.set_events();},set_events:function(){var me=this;this.listobj.$w.find('.btn-filter').bind('click',function(){me.$w.find('.show_filters').slideToggle();if(!me.filters.length)
|
||||
me.add_filter();});this.$w.find('.add-filter-btn').bind('click',function(){me.add_filter();});},add_filter:function(fieldname,condition,value){this.filters.push(new wn.ui.Filter({flist:this,fieldname:fieldname,condition:condition,value:value}));if(fieldname){this.$w.find('.show_filters').slideDown();}},get_filters:function(){var values=[];$.each(this.filters,function(i,f){if(f.field)
|
||||
values.push(f.get_value());})
|
||||
return values;},update_filters:function(){var fl=[];$.each(this.filters,function(i,f){if(f.field)fl.push(f);})
|
||||
this.filters=fl;},get_filter:function(fieldname){for(var i in this.filters){if(this.filters[i].field.df.fieldname==fieldname)
|
||||
return this.filters[i];}}});wn.ui.Filter=Class.extend({init:function(opts){$.extend(this,opts);this.doctype=this.flist.doctype;this.fields_by_name={};this.make();this.make_options();this.set_events();},make:function(){this.flist.$w.find('.filter_area').append('<div class="list_filter">\
|
||||
<select class="fieldname_select"></select>\
|
||||
<select class="condition">\
|
||||
<option value="=">Equals</option>\
|
||||
<option value="like">Like</option>\
|
||||
<option value=">=">Greater or equals</option>\
|
||||
<option value=">=">Less or equals</option>\
|
||||
<option value=">">Greater than</option>\
|
||||
<option value="<">Less than</option>\
|
||||
<option value="in">In</option>\
|
||||
<option value="!=">Not equals</option>\
|
||||
</select>\
|
||||
<span class="filter_field"></span>\
|
||||
<a class="close">×</a>\
|
||||
</div>');this.$w=this.flist.$w.find('.list_filter:last-child');this.$select=this.$w.find('.fieldname_select');},make_options:function(){if(this.filter_fields){for(var i in this.filter_fields)
|
||||
this.add_field_option(this.filter_fields[i])}else{this.render_field_select();}},set_events:function(){var me=this;this.$w.find('.fieldname_select').bind('change',function(){me.set_field(this.value);});this.$w.find('a.close').bind('click',function(){me.$w.css('display','none');var value=me.field.get_value();me.field=null;if(!me.flist.get_filters().length){me.flist.$w.find('.set_filters').toggle(true);me.flist.$w.find('.show_filters').toggle(false);}
|
||||
if(value){me.flist.listobj.run();}
|
||||
me.flist.update_filters();return false;});me.$w.find('.condition').change(function(){if($(this).val()=='in'){me.set_field(me.field.df.fieldname,'Data');if(!me.field.desc_area)
|
||||
me.field.desc_area=$a(me.field.wrapper,'span','help',null,'values separated by comma');}else{me.set_field(me.field.df.fieldname);}});if(me.fieldname){this.set_values(me.fieldname,me.condition,me.value);}else{me.set_field('name');}},set_values:function(fieldname,condition,value){this.set_field(fieldname);if(condition)this.$w.find('.condition').val(condition).change();if(value)this.field.set_input(value)},render_field_select:function(){var me=this;me.table_fields=[];var std_filters=[{fieldname:'name',fieldtype:'Data',label:'ID',parent:me.doctype},{fieldname:'modified',fieldtype:'Date',label:'Last Modified',parent:me.doctype},{fieldname:'owner',fieldtype:'Data',label:'Created By',parent:me.doctype},{fieldname:'_user_tags',fieldtype:'Data',label:'Tags',parent:me.doctype}];$.each(std_filters.concat(fields_list[me.doctype]),function(i,df){me.add_field_option(df);});$.each(me.table_fields,function(i,table_df){if(table_df.options){$.each(fields_list[table_df.options],function(i,df){me.add_field_option(df);});}})},add_field_option:function(df){var me=this;if(me.doctype&&df.parent==me.doctype){var label=df.label;var table=get_label_doctype(me.doctype);if(df.fieldtype=='Table')me.table_fields.push(df);}else{var label=df.label+' ('+df.parent+')';var table=df.parent;}
|
||||
if(wn.model.no_value_type.indexOf(df.fieldtype)==-1&&!me.fields_by_name[df.fieldname]){this.$select.append($('<option>',{value:df.fieldname,table:table}).text(label));me.fields_by_name[df.fieldname]=df;}},set_field:function(fieldname,fieldtype){var me=this;var cur=me.field?{fieldname:me.field.df.fieldname,fieldtype:me.field.df.fieldtype}:{}
|
||||
var df=me.fields_by_name[fieldname];this.set_fieldtype(df,fieldtype);if(me.field&&cur.fieldname==fieldname&&df.fieldtype==cur.fieldtype){return;}
|
||||
me.$w.find('.fieldname_select').val(fieldname);var field_area=me.$w.find('.filter_field').empty().get(0);f=make_field(df,null,field_area,null,0,1);f.df.single_select=1;f.not_in_form=1;f.with_label=0;f.refresh();me.field=f;this.set_default_condition(df,fieldtype);$(me.field.wrapper).find(':input').keydown(function(ev){if(ev.which==13){me.flist.listobj.run();}})},set_fieldtype:function(df,fieldtype){if(df.original_type)
|
||||
df.fieldtype=df.original_type;else
|
||||
df.original_type=df.fieldtype;df.description='';df.reqd=0;if(fieldtype){df.fieldtype=fieldtype;return;}
|
||||
if(df.fieldtype=='Check'){df.fieldtype='Select';df.options='No\nYes';}else if(['Text','Text Editor','Code','Link'].indexOf(df.fieldtype)!=-1){df.fieldtype='Data';}},set_default_condition:function(df,fieldtype){if(!fieldtype){if(df.fieldtype=='Data'){this.$w.find('.condition').val('like');}else{this.$w.find('.condition').val('=');}}},get_value:function(){var me=this;var val=me.field.get_value();var cond=me.$w.find('.condition').val();if(me.field.df.original_type=='Check'){val=(val=='Yes'?1:0);}
|
||||
if(cond=='like'){val=val+'%';}
|
||||
return[me.$w.find('.fieldname_select option:selected').attr('table'),me.field.df.fieldname,me.$w.find('.condition').val(),val];}});
|
||||
/*
|
||||
* lib/js/wn/views/container.js
|
||||
*/
|
||||
wn.provide('wn.pages');wn.provide('wn.views');wn.views.Container=Class.extend({init:function(){this.container=$('#body_div').get(0);this.page=null;},add_page:function(label,onshow,onhide){var page=$('<div class="content"></div>').appendTo(this.container).get(0);if(onshow)
|
||||
$(page).bind('show',onshow);if(onshow)
|
||||
$(page).bind('hide',onhide);page.label=label;wn.pages[label]=page;return page;},change_to:function(label){if(label.tagName){var page=label;}else{var page=wn.pages[label];}
|
||||
if(!page){console.log('Page not found '+label);return;}
|
||||
if(this.page){$(this.page).css('left','-1000px');}
|
||||
this.page=page;$(this.page).css('left','0px');return this.page;},show:function(label){return this.change_to(label);}});
|
||||
/*
|
||||
* lib/js/wn/views/doclistview.js
|
||||
*/
|
||||
wn.provide('wn.views.doclistview');wn.provide('wn.doclistviews');wn.views.doclistview.pages={};wn.views.doclistview.show=function(doctype){var pagename=doctype+' List';wn.model.with_doctype(doctype,function(){var page=wn.views.doclistview.pages[pagename];if(!page){var page=wn.container.add_page(pagename);page.doclistview=new wn.views.DocListView(doctype,page);wn.views.doclistview.pages[pagename]=page;}
|
||||
document.title=page.doclistview.label;wn.container.change_to(pagename);})}
|
||||
wn.views.DocListView=wn.ui.Listing.extend({init:function(doctype,page){this.doctype=get_label_doctype(doctype);this.$page=$(page);this.label=get_doctype_label(doctype);this.label=(this.label.toLowerCase().substr(-4)=='list')?this.label:(this.label+' List');this.make_page();this.setup();},make_page:function(){var me=this;this.$page.html(repl('<div class="layout-wrapper layout-wrapper-background">\
|
||||
<div class="layout-main-section">\
|
||||
<a class="close" onclick="window.history.back();">×</a>\
|
||||
<h1>%(label)s</h1>\
|
||||
<hr>\
|
||||
<div class="wnlist-area"><div class="help">Loading...</div></div>\
|
||||
</div>\
|
||||
<div class="layout-side-section">\
|
||||
<div class="stat-wrapper show-docstatus hide">\
|
||||
<h4>Show</h4>\
|
||||
<div><input data-docstatus="0" type="checkbox" checked="checked" /> Drafts</div>\
|
||||
<div><input data-docstatus="1" type="checkbox" checked="checked" /> Submitted</div>\
|
||||
<div><input data-docstatus="2" type="checkbox" /> Cancelled</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div style="clear: both"></div>\
|
||||
</div>',{label:this.label}));},setup:function(){var me=this;me.can_delete=wn.model.can_delete(me.doctype);me.meta=locals.DocType[me.doctype];me.$page.find('.wnlist-area').empty(),me.setup_docstatus_filter();me.setup_listview();me.init_list();me.init_stats();me.add_delete_option();},setup_docstatus_filter:function(){var me=this;this.can_submit=$.map(locals.DocPerm,function(d){if(d.parent==me.meta.name&&d.submit)return 1
|
||||
else return null;}).length;if(this.can_submit){this.$page.find('.show-docstatus').removeClass('hide');this.$page.find('.show-docstatus input').click(function(){me.run();})}},setup_listview:function(){if(this.meta.__listjs){eval(this.meta.__listjs);this.listview=new wn.doclistviews[this.doctype](this);}else{this.listview=new wn.views.ListView(this);}
|
||||
this.listview.parent=this;},init_list:function(){this.make({method:'webnotes.widgets.doclistview.get',get_args:this.get_args,parent:this.$page.find('.wnlist-area'),start:0,page_length:20,show_filters:true,show_grid:true,new_doctype:this.doctype,allow_delete:true,columns:this.listview.fields});this.run();},render_row:function(row,data){data.doctype=this.doctype;this.listview.render(row,data,this);},get_query_fields:function(){return this.listview.fields;},get_args:function(){return{doctype:this.doctype,fields:this.get_query_fields(),filters:this.filter_list.get_filters(),docstatus:this.can_submit?$.map(this.$page.find('.show-docstatus :checked'),function(inp){return $(inp).attr('data-docstatus')}):[]}},add_delete_option:function(){var me=this;if(this.can_delete){this.add_button('<a class="btn btn-small btn-delete">\
|
||||
<i class="icon-remove"></i> Delete</a>',function(){me.delete_items();},'.btn-filter')}},delete_items:function(){var me=this;var dl=$.map(me.$page.find('.list-check :checked'),function(e){return $(e).data('name');});if(!dl.length)
|
||||
return;if(!confirm('This is PERMANENT action and you cannot undo. Continue?')){return;}
|
||||
me.set_working(true);wn.call({method:'webnotes.widgets.doclistview.delete_items',args:{items:dl,doctype:me.doctype},callback:function(){me.set_working(false);me.refresh();}})},init_stats:function(){var me=this
|
||||
wn.call({method:'webnotes.widgets.doclistview.get_stats',args:{stats:me.listview.stats,doctype:me.doctype},callback:function(r){$.each(r.message,function(field,stat){me.render_stat(field,stat);});}});},render_stat:function(field,stat){var me=this;if(!stat||!stat.length){if(field=='_user_tags'){this.$page.find('.layout-side-section').append('<div class="stat-wrapper"><h4>Tags</h4>\
|
||||
<div class="help"><i>No records tagged.</i><br><br> \
|
||||
To add a tag, open the document and click on \
|
||||
"Add Tag" on the sidebar</div></div>');}
|
||||
return;}
|
||||
var label=fields[this.doctype][field]?fields[this.doctype][field].label:field;if(label=='_user_tags')label='Tags';var $w=$('<div class="stat-wrapper">\
|
||||
<h4>'+label+'</h4>\
|
||||
<div class="stat-grid">\
|
||||
</div>\
|
||||
</div>');stat=stat.sort(function(a,b){return b[1]-a[1]});var sum=0;$.each(stat,function(i,v){sum=sum+v[1];})
|
||||
$.each(stat,function(i,v){me.render_stat_item(i,v,sum,field).appendTo($w.find('.stat-grid'));});$w.appendTo(this.$page.find('.layout-side-section'));},render_stat_item:function(i,v,max,field){var me=this;var args={}
|
||||
args.label=v[0];args.width=flt(v[1])/max*100;args.count=v[1];args.field=field;$item=$(repl('<div class="stat-item">\
|
||||
<div class="stat-bar" style="width: %(width)s%"></div>\
|
||||
<div class="stat-label">\
|
||||
<a href="#" data-label="%(label)s" data-field="%(field)s">\
|
||||
%(label)s</a> \
|
||||
(%(count)s)</div>\
|
||||
</div>',args));this.setup_stat_item_click($item);return $item;},setup_stat_item_click:function($item){var me=this;$item.find('a').click(function(){var fieldname=$(this).attr('data-field');var label=$(this).attr('data-label');me.set_filter(fieldname,label);return false;});},set_filter:function(fieldname,label){var filter=this.filter_list.get_filter(fieldname);if(filter){var v=filter.field.get_value();if(v.indexOf(label)!=-1){return false;}else{if(fieldname=='_user_tags'){this.filter_list.add_filter(fieldname,'like','%'+label);}else{filter.set_values(fieldname,'in',v+', '+label);}}}else{if(fieldname=='_user_tags'){this.filter_list.add_filter(fieldname,'like','%'+label);}else{this.filter_list.add_filter(fieldname,'=',label);}}
|
||||
this.run();}});wn.views.ListView=Class.extend({init:function(doclistview){this.doclistview=doclistview;this.doctype=doclistview.doctype;var t="`tab"+this.doctype+"`.";this.fields=[t+'name',t+'owner',t+'docstatus',t+'_user_tags',t+'modified'];this.stats=['_user_tags']},render:function(row,data){this.prepare_data(data);$(row).html(repl('<span class="list-check hide"><input type="checkbox"></span> \
|
||||
<span class="avatar-small"><img src="%(avatar)s" /></span> \
|
||||
<span class="docstatus"><i class="%(docstatus_icon)s" \
|
||||
title="%(docstatus_title)s"></i></span> \
|
||||
<a href="#!Form/%(doctype)s/%(name)s">%(name)s</a>\
|
||||
<span class="tags"></span> \
|
||||
<span style="float:right; font-size: 11px; color: #888; \
|
||||
margin-left: 8px;">%(when)s</span>\
|
||||
<span class="main" style=""></span>\
|
||||
',data)).addClass('list-row');this.hide_delete(row,data);this.add_user_tags(row,data);this.$main=$(row).find('.main');},prepare_data:function(data){data.fullname=wn.user_info(data.owner).fullname;data.avatar=wn.user_info(data.owner).image;data.when=dateutil.str_to_user(data.modified).split(' ')[0];if(data.docstatus==0||data.docstatus==null){data.docstatus_icon='icon-pencil';data.docstatus_title='Editable';}else if(data.docstatus==1){data.docstatus_icon='icon-lock';data.docstatus_title='Submitted';}else if(data.docstatus==2){data.docstatus_icon='icon-remove';data.docstatus_title='Cancelled';}},hide_delete:function(row,data){if(this.parent.can_delete){$(row).find('.list-check').removeClass('hide');$(row).find('.list-check input').data('name',data.name);}},add_user_tags:function(row,data){var me=this;if(data._user_tags){$.each(data._user_tags.split(','),function(i,t){if(t){$('<span class="label label-info" style="cursor: pointer">'
|
||||
+strip(t)+'</span>').click(function(){me.doclistview.set_filter('_user_tags',$(this).text())}).appendTo($(row).find('.tags'));}});}}})
|
||||
/*
|
||||
* lib/js/wn/views/pageview.js
|
||||
*/
|
||||
wn.provide('wn.views.pageview');wn.views.pageview={pages:{},with_page:function(name,callback){if(!locals.Page[name]){wn.call({method:'webnotes.widgets.page.getpage',args:{'name':name},callback:callback});}else{callback();}},show:function(name){wn.views.pageview.with_page(name,function(){if(!wn.pages[name]){wn.views.pageview.pages[name]=new wn.views.Page(name);}
|
||||
wn.container.change_to(name);});}}
|
||||
wn.views.Page=Class.extend({init:function(name){this.name=name;this.render();},render:function(){var me=this;this.pagedoc=locals.Page[this.name];this.wrapper=wn.container.add_page(this.name);this.wrapper.innerHTML=this.pagedoc.content;wn.dom.eval(this.pagedoc.__script||this.pagedoc.script||'');wn.dom.set_style(this.pagedoc.style);this.trigger('onload');$(this.wrapper).bind('show',function(){cur_frm=null;me.trigger('onshow');});},trigger:function(event){var me=this;try{if(pscript[event+'_'+this.name]){pscript[event+'_'+this.name](me.wrapper);}
|
||||
if(me.wrapper[event]){me.wrapper[event](me.wrapper);}}catch(e){console.log(e);}}})
|
||||
/*
|
||||
* lib/js/wn/views/formview.js
|
||||
*/
|
||||
wn.provide('wn.views.formview');wn.views.formview={show:function(dt,dn){wn.model.with_doctype(dt,function(){wn.model.with_doc(dt,dn,function(dn){if(!wn.views.formview[dt]){wn.views.formview[dt]=wn.container.add_page('Form - '+dt);wn.views.formview[dt].frm=new _f.Frm(dt,wn.views.formview[dt]);}
|
||||
wn.container.change_to('Form - '+dt);wn.views.formview[dt].frm.refresh(dn);});})}}
|
||||
/*
|
||||
* lib/js/wn/views/reportview.js
|
||||
*/
|
||||
wn.views.reportview={show:function(dt,rep_name){wn.require('lib/js/legacy/report.compressed.js');dt=get_label_doctype(dt);if(!_r.rb_con){_r.rb_con=new _r.ReportContainer();}
|
||||
_r.rb_con.set_dt(dt,function(rb){if(rep_name){var t=rb.current_loaded;rb.load_criteria(rep_name);if(onload)
|
||||
onload(rb);if((rb.dt)&&(!rb.dt.has_data()||rb.current_loaded!=t))
|
||||
rb.dt.run();}
|
||||
if(!rb.forbidden){wn.container.change_to('Report Builder');}});}}
|
||||
/*
|
||||
* lib/js/wn/request.js
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -36,34 +36,44 @@ function startup() {
|
|||
wn.control_panel = r.control_panel;
|
||||
}
|
||||
|
||||
var setup_history = function(r) {
|
||||
rename_observers.push(nav_obj);
|
||||
var setup_viewport = function() {
|
||||
wn.container = new wn.views.Container();
|
||||
|
||||
// toolbar
|
||||
if(user=='Guest')
|
||||
user_defaults.hide_webnotes_toolbar = 1;
|
||||
if(!cint(user_defaults.hide_webnotes_toolbar) || user=='Administrator') {
|
||||
wn.container.wntoolbar = new wn.ui.toolbar.Toolbar();
|
||||
}
|
||||
|
||||
// startup code
|
||||
$(document).trigger('startup');
|
||||
try{
|
||||
if(wn.control_panel.custom_startup_code)
|
||||
eval(wn.control_panel.custom_startup_code);
|
||||
} catch(e) {
|
||||
errprint(e);
|
||||
}
|
||||
|
||||
// open an existing page or record
|
||||
var t = to_open();
|
||||
if(t) {
|
||||
wn.set_route(t);
|
||||
} else if(home_page) {
|
||||
loadpage(home_page);
|
||||
}
|
||||
wn.route();
|
||||
|
||||
$dh('startup_div');
|
||||
$ds('body_div');
|
||||
}
|
||||
|
||||
var callback = function(r,rt) {
|
||||
if(r.exc) console.log(r.exc);
|
||||
setup_globals(r);
|
||||
setup_history();
|
||||
|
||||
var a = new Body();
|
||||
page_body.run_startup_code();
|
||||
|
||||
for(var i=0; i<startup_list.length; i++) {
|
||||
startup_list[i]();
|
||||
}
|
||||
|
||||
// show a new form on loading?
|
||||
|
||||
// open an existing page or record
|
||||
var t = to_open();
|
||||
if(t) {
|
||||
historyChange(t);
|
||||
} else if(home_page) {
|
||||
// show home oage
|
||||
loadpage(home_page);
|
||||
}
|
||||
page_body.ready();
|
||||
setup_viewport();
|
||||
}
|
||||
|
||||
if(wn.boot) {
|
||||
LocalDB.sync(wn.boot.docs);
|
||||
callback(wn.boot, '');
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ var user_email=null;
|
|||
var user_img = {};
|
||||
var home_page=null;
|
||||
|
||||
var page_body=null;
|
||||
var pscript = {};
|
||||
var selector=null;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* lib/js/legacy/widgets/report_builder/report_builder.js
|
||||
*/
|
||||
_r.ReportContainer=function(){if(user=='Guest'){msgprint("Not Allowed");return;}
|
||||
this.wrapper=page_body.add_page("Report Builder",function(){});this.wrapper.className='layout_wrapper';var head_div=$a(this.wrapper,'div');this.rb_area=$a(this.wrapper,'div');$dh(this.wrapper);var me=this;this.rb_dict={};this.page_head=new PageHeader(head_div);$y(this.page_head.wrapper,{marginBottom:'0px'});var run_fn=function(){if(me.cur_rb){me.cur_rb.dt.start_rec=1;me.cur_rb.dt.run();}}
|
||||
this.wrapper=wn.container.add_page("Report Builder",function(){});this.wrapper.className='layout_wrapper';var head_div=$a(this.wrapper,'div');this.rb_area=$a(this.wrapper,'div');$dh(this.wrapper);var me=this;this.rb_dict={};this.page_head=new PageHeader(head_div);$y(this.page_head.wrapper,{marginBottom:'0px'});var run_fn=function(){if(me.cur_rb){me.cur_rb.dt.start_rec=1;me.cur_rb.dt.run();}}
|
||||
var runbtn=this.page_head.add_button('Run',run_fn,1,'ui-icon-circle-triangle-e',1);if(has_common(['Administrator','System Manager'],user_roles)){var savebtn=this.page_head.add_button('Save',function(){if(me.cur_rb)me.cur_rb.save_criteria();},0,'ui-icon-disk');var fn=function(){if(me.cur_rb){if(!me.cur_rb.current_loaded){msgprint("error:You must save the report before you can set Advanced features");return;}
|
||||
loaddoc('Search Criteria',me.cur_rb.sc_dict[me.cur_rb.current_loaded]);}};var advancedbtn=this.page_head.add_button('Advanced Settings',fn);}
|
||||
this.set_dt=function(dt,onload){my_onload=function(f){if(!f.forbidden){me.cur_rb=f;me.cur_rb.mytabs.items['Result'].expand();if(onload)onload(f);}}
|
||||
|
|
@ -60,7 +60,7 @@ me.set_sort_options();}
|
|||
_r.ReportBuilder.prototype.set_sort_options=function(l){var sl=this.orig_sort_list;empty_select(this.dt.sort_sel);if(l)sl=add_lists(l,this.orig_sort_list);if(!l)l=[];if(!l.length){l.push(['ID','name'])}
|
||||
for(var i=0;i<sl.length;i++){this.dt.add_sort_option(sl[i][0],sl[i][1]);}}
|
||||
_r.ReportBuilder.prototype.validate_permissions=function(onload){this.perm=get_perm(this.parent_dt?this.parent_dt:this.doctype);if(!this.perm[0][READ]){this.forbidden=1;if(user=='Guest'){msgprint('You must log in to view this page');}else{msgprint('No Read Permission');}
|
||||
nav_obj.show_last_open();return 0;}
|
||||
window.back();return 0;}
|
||||
return 1;}
|
||||
_r.ReportBuilder.prototype.setup_doctype=function(onload){var me=this;if(!locals['DocType'][this.doctype]){this.load_doctype_from_server(onload);}else{for(var key in locals.DocField){var f=locals.DocField[key];if(f.fieldtype=='Table'&&f.options==this.doctype)
|
||||
this.parent_dt=f.parent;}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@
|
|||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
var startup_list = [];
|
||||
|
||||
wn.utils.full_name = function(fn, ln) { return fn + (ln ? ' ' : '') + (ln ? ln : '') }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ function $ln(parent, label, onclick, style) {
|
|||
}
|
||||
|
||||
function $btn(parent, label, onclick, style, css_class, is_ajax) {
|
||||
wn.require('lib/js/wn/ui/button.js');
|
||||
if(css_class==='green') css_class='btn-info';
|
||||
return new wn.ui.Button(
|
||||
{parent:parent, label:label, onclick:onclick, style:style, is_ajax: is_ajax, css_class: css_class}
|
||||
|
|
@ -321,14 +320,7 @@ function $yt(tab, r, c, s) { /// set style on tables with wildcards
|
|||
// add css classes etc
|
||||
|
||||
function set_style(txt) {
|
||||
var se = document.createElement('style');
|
||||
se.type = "text/css";
|
||||
if (se.styleSheet) {
|
||||
se.styleSheet.cssText = txt;
|
||||
} else {
|
||||
se.appendChild(document.createTextNode(txt));
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(se);
|
||||
wn.dom.set_style(txt);
|
||||
}
|
||||
|
||||
// Make table
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,133 +0,0 @@
|
|||
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
|
||||
//
|
||||
// MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
/** Page Body
|
||||
|
||||
+ body
|
||||
+ body
|
||||
+ left_sidebar
|
||||
+ center
|
||||
+ right_sidebar
|
||||
+ dead session
|
||||
|
||||
**/
|
||||
|
||||
wn.provide('wn.pages');
|
||||
|
||||
function Body() {
|
||||
this.left_sidebar = null;
|
||||
this.right_sidebar = null;
|
||||
this.status_area = null;
|
||||
var me = this;
|
||||
page_body = this;
|
||||
|
||||
this.ready = function() {
|
||||
$dh('startup_div');
|
||||
$ds('body_div');
|
||||
}
|
||||
|
||||
this.setup_page_areas = function() {
|
||||
this.center = this.body;
|
||||
this.center.header = $a(this.center, 'div');
|
||||
this.center.body = $a(this.center, 'div');
|
||||
this.center.loading = $a(this.center, 'div', '', {margin:'200px 0px', fontSize:'14px', color:'#999', textAlign:'center'});
|
||||
this.center.loading.innerHTML = 'Loading...'
|
||||
|
||||
}
|
||||
|
||||
this.run_startup_code = function() {
|
||||
$(document).trigger('startup');
|
||||
// startup code
|
||||
try{
|
||||
if(this.cp.custom_startup_code)
|
||||
eval(this.cp.custom_startup_code);
|
||||
} catch(e) {
|
||||
errprint(e);
|
||||
}
|
||||
}
|
||||
|
||||
this.setup = function() {
|
||||
this.cp = wn.control_panel;
|
||||
|
||||
this.wrapper = $a($i('body_div'),'div');
|
||||
this.body = $a(this.wrapper, 'div');
|
||||
|
||||
this.setup_page_areas();
|
||||
|
||||
// core areas;
|
||||
if(user=='Guest') user_defaults.hide_webnotes_toolbar = 1;
|
||||
if(!cint(user_defaults.hide_webnotes_toolbar) || user=='Administrator') {
|
||||
this.wntoolbar = new wn.ui.toolbar.Toolbar();
|
||||
}
|
||||
|
||||
// page width
|
||||
if(this.cp.page_width)
|
||||
$y(this.wrapper,{width:cint(this.cp.page_width) + 'px'});
|
||||
|
||||
}
|
||||
|
||||
// Standard containers
|
||||
// - Forms
|
||||
// - Report Builder
|
||||
// - Item List
|
||||
// - [Pages by their names]
|
||||
|
||||
this.cur_page = null;
|
||||
this.add_page = function(label, onshow, onhide) {
|
||||
var c = $a(this.center.body, 'div');
|
||||
if(onshow)
|
||||
c.page_show = onshow;
|
||||
if(onhide)
|
||||
c.page_hide = onhide;
|
||||
wn.pages[label] = c;
|
||||
$dh(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
this.change_to = function(label) {
|
||||
// hide existing
|
||||
$dh(this.center.loading);
|
||||
if(me.cur_page && wn.pages[label]!=me.cur_page) {
|
||||
if(me.cur_page.page_hide)
|
||||
me.cur_page.page_hide();
|
||||
$dh(me.cur_page);
|
||||
}
|
||||
// show
|
||||
me.cur_page = wn.pages[label];
|
||||
me.cur_page_label = label;
|
||||
$(me.cur_page).fadeIn();
|
||||
|
||||
// on show
|
||||
if(me.cur_page.page_show)
|
||||
me.cur_page.page_show(me.cur_page);
|
||||
}
|
||||
|
||||
this.set_session_changed = function() {
|
||||
if(this.session_message_set) return;
|
||||
var div = $a($i('body_div').parentNode,'div','',{textAlign: 'center', fontSize:'14px', margin:'150px auto'});
|
||||
$dh('body_div');
|
||||
div.innerHTML = 'This session has been changed. Please <span class="link_type" onclick="window.location.reload()">refresh</span> to continue';
|
||||
this.session_message_set = 1;
|
||||
}
|
||||
|
||||
this.setup();
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ ItemBrowserPage = function() {
|
|||
this.dt_details = {};
|
||||
this.cur_list = null;
|
||||
|
||||
this.my_page = page_body.add_page('ItemBrowser');
|
||||
this.my_page = wn.container.add_page('ItemBrowser');
|
||||
this.wrapper = $a(this.my_page,'div');
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ ItemBrowserPage.prototype.show = function(dt, label, field_list) {
|
|||
me.cur_list = me.lists[dt];
|
||||
me.cur_list.show();
|
||||
|
||||
page_body.change_to('ItemBrowser');
|
||||
wn.container.change_to('ItemBrowser');
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ function errprint(t) {
|
|||
border-bottom: 1px solid #AAA; overflow: auto; width: 90%;">'+t+'</pre>');
|
||||
}
|
||||
|
||||
function setup_err_console() {
|
||||
$(document).bind('startup', function() {
|
||||
err_console = new Dialog(640, 480, 'Error Console')
|
||||
err_console.make_body([
|
||||
['HTML', 'Error List']
|
||||
|
|
@ -57,6 +57,4 @@ function setup_err_console() {
|
|||
err_console.rows['Error List'].innerHTML = '<div style="padding: 16px; height: 360px; width: 90%; overflow: auto;">'
|
||||
+ err_list.join('<div style="height: 10px; margin-bottom: 10px; border-bottom: 1px solid #AAA"></div>') + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
startup_list.push(setup_err_console);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,203 +0,0 @@
|
|||
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
|
||||
//
|
||||
// MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
// Navigation Object
|
||||
|
||||
var nav_obj = {}
|
||||
|
||||
nav_obj.observers = [];
|
||||
nav_obj.add_observer = function(o) { nav_obj.observers.push(o); }
|
||||
|
||||
nav_obj.ol = [];
|
||||
|
||||
//
|
||||
// notify my history so that it gets added to the back button history
|
||||
//
|
||||
nav_obj.open_notify = function(t, dt, dn, no_history) {
|
||||
// last should not be this (refresh)
|
||||
if(nav_obj.ol.length) {
|
||||
var tmp = nav_obj.ol[nav_obj.ol.length-1];
|
||||
if(tmp && tmp[0]==t && tmp[1]==dt && tmp[2]==dn) return;
|
||||
}
|
||||
|
||||
if(!no_history) {
|
||||
|
||||
// remove from history (if exists so that we can put it back on top)
|
||||
var tmp = [];
|
||||
for(var i in nav_obj.ol)
|
||||
if(!(nav_obj.ol[i][0]==t && nav_obj.ol[i][1]==dt && nav_obj.ol[i][2]==dn)) tmp.push(nav_obj.ol[i]);
|
||||
nav_obj.ol = tmp;
|
||||
|
||||
// add to top
|
||||
nav_obj.ol.push([t, dt, dn])
|
||||
|
||||
// encode
|
||||
en_t = encodeURIComponent(t);
|
||||
en_dt = encodeURIComponent(dt);
|
||||
en_dn = dn ? encodeURIComponent(dn) : '';
|
||||
|
||||
if(en_t=='Page') {
|
||||
var id = en_dt + (dn ? ('/'+en_dn): '')
|
||||
} else {
|
||||
var id = en_t+'/'+ en_dt + (dn ? ('/'+en_dn): '')
|
||||
}
|
||||
|
||||
// option to add to analytics engine
|
||||
if(nav_obj.on_open)
|
||||
nav_obj.on_open(id);
|
||||
|
||||
// add to "back" history
|
||||
// replace state (to url)
|
||||
if(window.location.hash!='!' + id) {
|
||||
window.location.hash = '!' + id;
|
||||
}
|
||||
}
|
||||
|
||||
nav_obj.notify_observers(t, dt, dn);
|
||||
|
||||
if(wn.boot.analytics_code) {
|
||||
try {
|
||||
eval(wn.boot.analytics_code);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Notify observers
|
||||
// =========================================
|
||||
|
||||
nav_obj.notify_observers = function(t, dt, dn) {
|
||||
// notify observers (for menu?)
|
||||
for(var i=0; i<nav_obj.observers.length; i++) {
|
||||
var o = nav_obj.observers[i];
|
||||
if(o && o.notify) o.notify(t, dt, dn);
|
||||
}
|
||||
}
|
||||
|
||||
// Remame links (for save - name change)
|
||||
// =========================================
|
||||
|
||||
nav_obj.rename_notify = function(dt, oldn, newn) {
|
||||
for(var i=0;i<nav_obj.ol.length;i++) {
|
||||
var o = nav_obj.ol[i];
|
||||
if(o[1]==dt && o[2]==oldn) o[2]=newn;
|
||||
}
|
||||
}
|
||||
|
||||
nav_obj.show_last_open = function() {
|
||||
var l = nav_obj.ol[nav_obj.ol.length-2];
|
||||
delete nav_obj.ol[nav_obj.ol.length-1]; // delete current open
|
||||
|
||||
if(!l) loadpage('_home');
|
||||
else if(l[0]=='Page') {
|
||||
loadpage(l[1]);
|
||||
} else if(l[0]=='Report') {
|
||||
loadreport(l[1],l[2]);
|
||||
} else if(l[0]=='Form') {
|
||||
loaddoc(l[1],l[2]);
|
||||
} else if(l[0]=='DocBrowser' || l[0]=='List') {
|
||||
loaddocbrowser(l[1]);
|
||||
}
|
||||
}
|
||||
|
||||
var _history_current;
|
||||
|
||||
function history_get_name(t) {
|
||||
var parts = [];
|
||||
if(t.length>=3) {
|
||||
// combine all else
|
||||
for(var i=2; i<t.length; i++) {
|
||||
parts.push(t[i]);
|
||||
}
|
||||
}
|
||||
return parts.join('/')
|
||||
}
|
||||
|
||||
//
|
||||
// get the page details from the location
|
||||
//
|
||||
nav_obj.get_page = function(loc) {
|
||||
if(!loc) loc = window.location.hash;
|
||||
|
||||
// remove exclamation for hash-bangs
|
||||
if(loc.substr(0,1)=='#') { loc = loc.substr(1); }
|
||||
if(loc.substr(0,1)=='!') { loc = loc.substr(1); }
|
||||
|
||||
if(!in_list(['Page/', 'Form/', 'Repor', 'DocBr', 'List/', 'List2'], loc.substr(0,5))) {
|
||||
loc = 'Page/' + loc;
|
||||
}
|
||||
return loc.split('/');
|
||||
}
|
||||
//
|
||||
// function called when page is updated
|
||||
//
|
||||
function historyChange(newLocation) {
|
||||
var t = nav_obj.get_page(newLocation)
|
||||
|
||||
for(var i=0;i<t.length;i++)
|
||||
t[i] = decodeURIComponent(t[i]);
|
||||
|
||||
// re-opening the same page?
|
||||
if(nav_obj.ol.length) {
|
||||
var c = nav_obj.ol[nav_obj.ol.length-1];
|
||||
|
||||
if(t.length==2) {
|
||||
if(c[0]==t[0] && c[1]==t[1]) return;
|
||||
} else {
|
||||
if(c[0]==t[0] && c[1]==t[1] && c[2]==t[2]) return;
|
||||
}
|
||||
}
|
||||
|
||||
if(t[2])
|
||||
var docname = history_get_name(t);
|
||||
|
||||
if(t[0]=='Form') {
|
||||
_history_current = newLocation;
|
||||
if(docname.substr(0, 3)=='New' && !(locals[t[1]] && locals[t[1]][docname])) {
|
||||
newdoc(t[1]);
|
||||
} else {
|
||||
loaddoc(t[1], docname);
|
||||
}
|
||||
} else if(t[0]=='Report') {
|
||||
_history_current = newLocation;
|
||||
loadreport(t[1], docname);
|
||||
} else if(t[0]=='Page') {
|
||||
_history_current = newLocation;
|
||||
loadpage(t[1]);
|
||||
} else if(t[0]=='Application') {
|
||||
_history_current = newLocation;
|
||||
loadapp(t[1]);
|
||||
} else if(t[0]=='DocBrowser' || t[0]=='List') {
|
||||
_history_current = newLocation;
|
||||
loaddocbrowser(t[1]);
|
||||
} else if(t[0]=='List2') {
|
||||
_history_current = newLocation;
|
||||
loaddocbrowser2(t[1]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$(window).bind('hashchange', function() {
|
||||
historyChange(location.hash);
|
||||
});
|
||||
|
|
@ -20,265 +20,30 @@
|
|||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
// Load Report
|
||||
// -------------------------------------------------------------------------------
|
||||
function loadreport(dt, rep_name, onload) {
|
||||
if(rep_name)
|
||||
wn.set_route('Report/' + encodeURIComponent(dt) + '/' + encodeURIComponent(rep_name));
|
||||
else
|
||||
wn.set_route('Report/' + encodeURIComponent(dt));
|
||||
}
|
||||
|
||||
function loadreport(dt, rep_name, onload, menuitem, reset_report) {
|
||||
wn.require('lib/js/legacy/report.compressed.js');
|
||||
dt = get_label_doctype(dt);
|
||||
|
||||
var show_report_builder = function() {
|
||||
if(!_r.rb_con) {
|
||||
// first load
|
||||
_r.rb_con = new _r.ReportContainer();
|
||||
}
|
||||
|
||||
_r.rb_con.set_dt(dt, function(rb) {
|
||||
if(rep_name) {
|
||||
var t = rb.current_loaded;
|
||||
rb.load_criteria(rep_name);
|
||||
|
||||
// call onload
|
||||
if(onload)
|
||||
onload(rb);
|
||||
|
||||
// if loaded, then run
|
||||
if((rb.dt) && (!rb.dt.has_data() || rb.current_loaded!=t))
|
||||
rb.dt.run();
|
||||
|
||||
} else {
|
||||
// reset if from toolbar
|
||||
if(reset_report) {
|
||||
rb.reset_report();
|
||||
}
|
||||
}
|
||||
|
||||
// show
|
||||
if(!rb.forbidden) {
|
||||
page_body.change_to('Report Builder');
|
||||
nav_obj.open_notify('Report',dt,rep_name);
|
||||
}
|
||||
} );
|
||||
}
|
||||
show_report_builder();
|
||||
function loaddoc(doctype, name, onload) {
|
||||
doctype = get_label_doctype(doctype);
|
||||
wn.set_route(['Form', encodeURIComponent(doctype), encodeURIComponent(name)].join('/'));
|
||||
}
|
||||
|
||||
|
||||
// Load Doc
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
var load_doc = loaddoc;
|
||||
|
||||
function loaddoc(doctype, name, onload, menuitem, from_archive) {
|
||||
doctype = get_label_doctype(doctype);
|
||||
|
||||
// validate
|
||||
if(frms['DocType'] && frms['DocType'].opendocs[doctype]) {
|
||||
msgprint("Cannot open an instance of \"" + doctype + "\" when the DocType is open.");
|
||||
return;
|
||||
}
|
||||
|
||||
// reverse validation - do not open DocType when an instance is open
|
||||
if(doctype=='DocType' && frms[name]) {
|
||||
msgprint("Cannot open DocType \"" + name + "\" when its instance is open.");
|
||||
return;
|
||||
}
|
||||
|
||||
var show_form = function(f) {
|
||||
// load the frm container
|
||||
if(!_f.frm_con) {
|
||||
_f.frm_con = new _f.FrmContainer(); //new _f.FrmContainer();
|
||||
}
|
||||
|
||||
// case A - frm not loaded
|
||||
if(!frms[doctype]) {
|
||||
_f.add_frm(doctype, show_doc, name, from_archive);
|
||||
|
||||
// case B - both loaded
|
||||
} else if(LocalDB.is_doc_loaded(doctype, name)) {
|
||||
show_doc();
|
||||
|
||||
// case C - only frm loaded
|
||||
} else {
|
||||
$c('webnotes.widgets.form.load.getdoc', {'name':name, 'doctype':doctype, 'user':user, 'from_archive':(from_archive ? 1 : 0) }, show_doc, null, null); // onload
|
||||
}
|
||||
}
|
||||
|
||||
var show_doc = function(r,rt) {
|
||||
if(locals[doctype] && locals[doctype][name]) {
|
||||
var frm = frms[doctype];
|
||||
|
||||
// show
|
||||
frm.refresh(name);
|
||||
|
||||
// notify for back button
|
||||
if(!frm.in_dialog)
|
||||
nav_obj.open_notify('Form',doctype,name);
|
||||
|
||||
if(onload) onload();
|
||||
|
||||
} else {
|
||||
// nothing, go home - there were errors
|
||||
if(r.exc) { msgprint('There were errors while loading ' + doctype + ' ' + name); }
|
||||
loadpage('_home');
|
||||
}
|
||||
}
|
||||
|
||||
//// is libary loaded?
|
||||
|
||||
show_form();
|
||||
}
|
||||
|
||||
|
||||
// New Doc
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
function new_doc(doctype, onload, in_dialog, on_save_callback, cdt, cdn, cnic) {
|
||||
// cnic = caller not in container (caller is a dialog)
|
||||
|
||||
doctype = get_label_doctype(doctype);
|
||||
|
||||
if(!doctype) {
|
||||
if(cur_frm)doctype = cur_frm.doctype; else return;
|
||||
}
|
||||
|
||||
var show_doc = function() {
|
||||
frm = frms[doctype];
|
||||
|
||||
if (frm.perm[0][CREATE]==1) {
|
||||
|
||||
// load new doc - create the new doc (if single, just load it)
|
||||
if(frm.meta.issingle) {
|
||||
var dn = doctype;
|
||||
LocalDB.set_default_values(locals[doctype][doctype]);
|
||||
} else
|
||||
var dn = LocalDB.create(doctype);
|
||||
|
||||
// call (optional) onload
|
||||
if(onload)onload(dn);
|
||||
|
||||
|
||||
if(frm.in_dialog) {
|
||||
// attach values so that the "new" value is set in the field from which it was set
|
||||
var fd = _f.frm_dialog;
|
||||
fd.cdt = cdt;
|
||||
fd.cdn = cdn;
|
||||
fd.cnic = cnic;
|
||||
fd.on_save_callback = on_save_callback;
|
||||
} else {
|
||||
nav_obj.open_notify('Form',doctype,dn);
|
||||
}
|
||||
|
||||
// show the form
|
||||
frm.refresh(dn);
|
||||
|
||||
} else {
|
||||
msgprint('error:Not Allowed To Create '+doctype+'\nContact your Admin for help');
|
||||
}
|
||||
}
|
||||
|
||||
var show_form = function() {
|
||||
// load the frm container
|
||||
if(!_f.frm_con) {
|
||||
_f.frm_con = new _f.FrmContainer();
|
||||
}
|
||||
|
||||
if(!frms[doctype])
|
||||
_f.add_frm(doctype, show_doc); // load
|
||||
else
|
||||
show_doc(frms[doctype]); // directly
|
||||
|
||||
}
|
||||
|
||||
show_form();
|
||||
wn.set_route(['Form', encodeURIComponent(doctype), encodeURIComponent('New ' + doctype)].join('/'));
|
||||
}
|
||||
var newdoc = new_doc;
|
||||
|
||||
//
|
||||
// Load Page
|
||||
//
|
||||
var pscript={};
|
||||
var cur_page;
|
||||
function loadpage(page_name, call_back, no_history) {
|
||||
if(!page_name) return;
|
||||
if(page_name=='_home')
|
||||
page_name = home_page;
|
||||
var fn = function(r,rt) {
|
||||
if(wn.pages[page_name]) {
|
||||
// loaded
|
||||
var p = wn.pages[page_name]
|
||||
|
||||
// show
|
||||
page_body.change_to(page_name);
|
||||
|
||||
} else {
|
||||
// new page
|
||||
var p = render_page(page_name);
|
||||
if(!p)return;
|
||||
}
|
||||
|
||||
// execute callback
|
||||
cur_page = page_name;
|
||||
if(call_back)call_back();
|
||||
|
||||
// scroll to top
|
||||
scroll(0,0);
|
||||
|
||||
// update "back"
|
||||
pscript.update_page_history(page_name, no_history)
|
||||
|
||||
// call refresh script
|
||||
try {
|
||||
if(pscript['refresh_'+page_name]) pscript['refresh_'+page_name](); // onload
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
if(get_local('Page', page_name) || wn.pages[page_name])
|
||||
fn();
|
||||
else {
|
||||
args = get_url_dict(); // send everything to the page
|
||||
args.name = page_name;
|
||||
$c('webnotes.widgets.page.getpage', args, fn);
|
||||
}
|
||||
wn.set_route(page_name);
|
||||
}
|
||||
|
||||
//
|
||||
// adds to the url (if called using loadpage and not the url)
|
||||
// - if i do not do this then it will overwrite
|
||||
// this is useful when an argument is passed to the page separated by a /
|
||||
//
|
||||
pscript.update_page_history = function(page_name, no_history) {
|
||||
var arg = null;
|
||||
var t = null;
|
||||
|
||||
// get from page
|
||||
if(window.location.hash) {
|
||||
var t = nav_obj.get_page(window.location.hash)
|
||||
} else if(get_url_arg('page')) {
|
||||
var t = nav_obj.get_page(get_url_arg('page'))
|
||||
}
|
||||
|
||||
if(t && t[1]==page_name) arg = t[2];
|
||||
|
||||
nav_obj.open_notify('Page', page_name, arg, no_history);
|
||||
}
|
||||
|
||||
// Load DocBrowser
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
var doc_browser_page;
|
||||
function loaddocbrowser(dt, label, fields) {
|
||||
wn.require('lib/js/legacy/webpage/docbrowser.js');
|
||||
dt = get_label_doctype(dt);
|
||||
if(!doc_browser_page)
|
||||
doc_browser_page = new ItemBrowserPage();
|
||||
doc_browser_page.show(dt, label, fields);
|
||||
nav_obj.open_notify('List',dt,'');
|
||||
}
|
||||
|
||||
function loaddocbrowser2(dt, label, fields) {
|
||||
wn.pages.doclistview.show(dt);
|
||||
return;
|
||||
wn.set_route('List/' + encodeURICompontent(dt));
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ function Page(page_name, content) {
|
|||
cur_frm = null;
|
||||
}
|
||||
|
||||
this.wrapper = page_body.add_page(page_name, this.page_show);
|
||||
this.wrapper = wn.container.add_page(page_name, this.page_show);
|
||||
this.cont = this.wrapper // bc
|
||||
|
||||
if(content)
|
||||
|
|
@ -85,7 +85,7 @@ function render_page(page_name, menuitem) {
|
|||
}
|
||||
|
||||
// change
|
||||
page_body.change_to(page_name);
|
||||
wn.container.change_to(page_name);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ function PageHeader(parent, main_text, sub_text) {
|
|||
// close btn
|
||||
$y($td(this.t1, 0, 1),{textAlign:'right', padding:'3px'});
|
||||
this.close_btn = $a($td(this.t1, 0, 1), 'span', 'close', {}, '×');
|
||||
this.close_btn.onclick = function() { nav_obj.show_last_open(); };
|
||||
this.close_btn.onclick = function() { window.back(); };
|
||||
|
||||
if(main_text) this.main_head.innerHTML = main_text;
|
||||
if(sub_text) this.sub_head.innerHTML = sub_text;
|
||||
|
|
|
|||
|
|
@ -41,32 +41,37 @@
|
|||
|
||||
wn.provide('_f');
|
||||
|
||||
_f.frms = {};
|
||||
// called from table edit
|
||||
_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;
|
||||
}
|
||||
|
||||
d.cur_frm = f;
|
||||
d.dn = dn;
|
||||
d.table_form = f.meta.istable;
|
||||
|
||||
// show the form
|
||||
f.refresh(dn);
|
||||
if(!_f.frm_dialog) {
|
||||
// make by twin
|
||||
_f.frm_dialog = new _f.FrmDialog();
|
||||
}
|
||||
var d = _f.frm_dialog;
|
||||
|
||||
wn.model.with_doctype(dt, function() {
|
||||
wn.model.with_doc(dt, dn, function(dn) {
|
||||
// load
|
||||
if(!_f.frms[dt]) {
|
||||
_f.frms[dt] = new _f.Frm(dt, d.body);
|
||||
}
|
||||
var f = _f.frms[dt];
|
||||
if(f.meta.istable) {
|
||||
f.parent_doctype = cur_frm.doctype;
|
||||
f.parent_docname = cur_frm.docname;
|
||||
}
|
||||
|
||||
// load
|
||||
if(!frms[dt]) {
|
||||
_f.add_frm(dt, show_dialog, null);
|
||||
} else {
|
||||
show_dialog();
|
||||
}
|
||||
|
||||
d.cur_frm = f;
|
||||
d.dn = dn;
|
||||
d.table_form = f.meta.istable;
|
||||
|
||||
// show the form
|
||||
f.refresh(dn);
|
||||
|
||||
d.dialog.show();
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
_f.Frm = function(doctype, parent) {
|
||||
|
|
@ -85,8 +90,6 @@ _f.Frm = function(doctype, parent) {
|
|||
this.parent = parent;
|
||||
this.tinymce_id_list = [];
|
||||
|
||||
frms[doctype] = this;
|
||||
|
||||
this.setup_meta(doctype);
|
||||
|
||||
// notify on rename
|
||||
|
|
@ -95,6 +98,21 @@ _f.Frm = function(doctype, parent) {
|
|||
|
||||
// ======================================================================================
|
||||
|
||||
_f.Frm.prototype.check_doctype_conflict = function(docname) {
|
||||
var me = this;
|
||||
if(this.doctype=='DocType') {
|
||||
if(wn.views.formview[docname]) {
|
||||
msgprint("Cannot open DocType when its instance is open")
|
||||
throw 'doctype open conflict'
|
||||
}
|
||||
} else {
|
||||
if(wn.views.formview.DocType && wn.views.formview.DocType.frm.opendocs[this.doctype]) {
|
||||
msgprint("Cannot open instance when its DocType is open")
|
||||
throw 'doctype open conflict'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_f.Frm.prototype.setup = function() {
|
||||
|
||||
var me = this;
|
||||
|
|
@ -102,7 +120,7 @@ _f.Frm.prototype.setup = function() {
|
|||
this.fields_dict = {};
|
||||
|
||||
// wrapper
|
||||
this.wrapper = $a(this.parent.body, 'div');
|
||||
this.wrapper = this.parent;
|
||||
|
||||
// create area for print fomrat
|
||||
this.setup_print_layout();
|
||||
|
|
@ -134,7 +152,7 @@ _f.Frm.prototype.setup_print_layout = function() {
|
|||
this.print_btn = $btn($td(t,0,0), 'Print', function() { cur_frm.print_doc() });
|
||||
|
||||
$y($td(t,0,1), {textAlign: 'right'});
|
||||
this.print_close_btn = $btn($td(t,0,1), 'Close', function() { nav_obj.show_last_open(); });
|
||||
this.print_close_btn = $btn($td(t,0,1), 'Close', function() { window.back(); });
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -395,17 +413,6 @@ _f.Frm.prototype.setup_client_script = function() {
|
|||
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
// change the parent - deprecated
|
||||
_f.Frm.prototype.set_parent = function(parent) {
|
||||
if(parent) {
|
||||
this.parent = parent;
|
||||
if(this.wrapper && this.wrapper.parentNode != parent)
|
||||
parent.appendChild(this.wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
_f.Frm.prototype.refresh_print_layout = function() {
|
||||
$ds(this.print_wrapper);
|
||||
$dh(this.page_layout.wrapper);
|
||||
|
|
@ -436,37 +443,16 @@ _f.Frm.prototype.refresh_print_layout = function() {
|
|||
}
|
||||
|
||||
|
||||
// SHOW!
|
||||
// ======================================================================================
|
||||
|
||||
_f.Frm.prototype.hide = function() {
|
||||
$dh(this.wrapper);
|
||||
this.display = 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
_f.Frm.prototype.show_the_frm = function() {
|
||||
// hide other (open) forms
|
||||
if(this.parent.last_displayed && this.parent.last_displayed != this) {
|
||||
this.parent.last_displayed.defocus_rest();
|
||||
this.parent.last_displayed.hide();
|
||||
}
|
||||
|
||||
// show the form
|
||||
if(this.wrapper && this.wrapper.style.display.toLowerCase()=='none') {
|
||||
$ds(this.wrapper);
|
||||
this.display = 1;
|
||||
}
|
||||
|
||||
// show the dialog
|
||||
if(this.meta.in_dialog && !this.parent.dialog.display) {
|
||||
if(!this.meta.istable)
|
||||
this.parent.table_form = false;
|
||||
this.parent.dialog.show();
|
||||
}
|
||||
|
||||
this.parent.last_displayed = this;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
|
@ -479,7 +465,6 @@ _f.Frm.prototype.set_print_heading = function(txt) {
|
|||
_f.Frm.prototype.defocus_rest = function() {
|
||||
// deselect others
|
||||
if(_f.cur_grid_cell) _f.cur_grid_cell.grid.cell_deselect();
|
||||
cur_page = null;
|
||||
}
|
||||
|
||||
// -------- Permissions -------
|
||||
|
|
@ -536,7 +521,7 @@ _f.Frm.prototype.check_doc_perm = function() {
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
nav_obj.show_last_open();
|
||||
window.back();
|
||||
return 0;
|
||||
}
|
||||
return 1
|
||||
|
|
@ -629,15 +614,8 @@ _f.Frm.prototype.refresh = function(docname) {
|
|||
}
|
||||
this.runclientscript('edit_status_changed');
|
||||
}
|
||||
|
||||
// show the record
|
||||
if(!this.display) this.show_the_frm();
|
||||
|
||||
// show the page
|
||||
if(!this.meta.in_dialog) page_body.change_to('Forms');
|
||||
|
||||
$(cur_frm.wrapper).trigger('render_complete');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -768,6 +746,7 @@ _f.Frm.prototype.refresh_dependency = function() {
|
|||
// ======================================================================================
|
||||
|
||||
_f.Frm.prototype.setnewdoc = function(docname) {
|
||||
this.check_doctype_conflict(docname);
|
||||
|
||||
// if loaded
|
||||
if(this.opendocs[docname]) { // already exists
|
||||
|
|
@ -1032,15 +1011,11 @@ _f.Frm.prototype.copy_doc = function(onload, from_amend) {
|
|||
// ======================================================================================
|
||||
|
||||
_f.Frm.prototype.reload_doc = function() {
|
||||
var me = this;
|
||||
if(frms['DocType'] && frms['DocType'].opendocs[me.doctype]) {
|
||||
msgprint("error:Cannot refresh an instance of \"" + me.doctype+ "\" when the DocType is open.");
|
||||
return;
|
||||
}
|
||||
this.check_doctype_conflict(this.docname);
|
||||
|
||||
var me = this;
|
||||
var ret_fn = function(r, rtxt) {
|
||||
// n tweets and last comment
|
||||
|
||||
// n tweets and last comment
|
||||
me.runclientscript('setup', me.doctype, me.docname);
|
||||
me.refresh();
|
||||
}
|
||||
|
|
@ -1109,7 +1084,7 @@ _f.Frm.prototype.savetrash = function() {
|
|||
if(wn.ui.toolbar.recent) wn.ui.toolbar.recent.remove(me.doctype, me.docname);
|
||||
|
||||
// "close"
|
||||
nav_obj.show_last_open();
|
||||
window.back();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1142,7 +1117,7 @@ _f.set_value = function(dt, dn, fn, v) {
|
|||
var d = locals[dt][dn];
|
||||
|
||||
if(!d) {
|
||||
errprint('error:Trying to set a value for "'+dt+','+dn+'" which is not found');
|
||||
console.log('_f.set_value - '+ fn+': "'+dt+','+dn+'" not found');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1152,11 +1127,11 @@ _f.set_value = function(dt, dn, fn, v) {
|
|||
if(changed) {
|
||||
d[fn] = v;
|
||||
d.__unsaved = 1;
|
||||
var frm = frms[d.doctype];
|
||||
var frm = wn.views.formview[d.doctype];
|
||||
try {
|
||||
if(d.parent && d.parenttype) {
|
||||
locals[d.parenttype][d.parent].__unsaved = 1;
|
||||
frm = frms[d.parenttype];
|
||||
frm = wn.views.formview[d.parenttype];
|
||||
}
|
||||
} catch(e) {
|
||||
if(d.parent && d.parenttype)
|
||||
|
|
|
|||
|
|
@ -20,20 +20,6 @@
|
|||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
_f.FrmContainer = function() {
|
||||
this.wrapper = page_body.add_page("Forms", function() {}, function() { });
|
||||
this.last_displayed = null;
|
||||
|
||||
// create hidden
|
||||
$dh(this.wrapper);
|
||||
|
||||
this.body = $a(this.wrapper,'div','frm_container');
|
||||
|
||||
// make by twin
|
||||
_f.frm_dialog = new _f.FrmDialog();
|
||||
}
|
||||
|
||||
|
||||
// FrmDialog - twin of FrmContainer
|
||||
// =======================================================================
|
||||
_f.frm_dialog = null;
|
||||
|
|
@ -96,82 +82,9 @@ _f.FrmDialog = function() {
|
|||
_f.cur_grid.refresh_row(_f.cur_grid_ridx, me.dn);
|
||||
|
||||
// set the new global cur_frm (if applicable)
|
||||
if(page_body.cur_page_label = 'Forms') {
|
||||
cur_frm = _f.frm_con.cur_frm;
|
||||
if(wn.container.page.frm) {
|
||||
cur_frm = wn.container.page.frm;
|
||||
}
|
||||
}
|
||||
this.dialog = d;
|
||||
}
|
||||
|
||||
// Form Factory
|
||||
// =======================================================================
|
||||
_f.add_frm = function(doctype, onload, opt_name, from_archive) {
|
||||
// dont open doctype and docname from the same session
|
||||
if(frms['DocType'] && frms['DocType'].opendocs[doctype]) {
|
||||
msgprint("error:Cannot create an instance of \"" + doctype+ "\" when the DocType is open.");
|
||||
return;
|
||||
}
|
||||
|
||||
// form already created, done
|
||||
if(frms[doctype]) {
|
||||
return frms[doctype];
|
||||
}
|
||||
|
||||
// Load Doctype from server
|
||||
var callback = function(r,rt) {
|
||||
|
||||
if(!locals['DocType'][doctype]) {
|
||||
if(r.exc) { msgprint("Did not load " + doctype, 1); }
|
||||
loadpage('_home');
|
||||
return;
|
||||
}
|
||||
|
||||
if(r.print_access) {
|
||||
if(!_f.temp_access[doctype])
|
||||
_f.temp_access[doctype] = {};
|
||||
_f.temp_access[doctype][opt_name] = 1;
|
||||
}
|
||||
|
||||
|
||||
// show fullpage or in Dialog?
|
||||
var meta = locals['DocType'][doctype];
|
||||
var in_dialog = false;
|
||||
|
||||
// if is table, its in the Dialog!
|
||||
if(meta.istable) meta.in_dialog = 1;
|
||||
|
||||
if(cint(meta.in_dialog)) {
|
||||
var parent = _f.frm_dialog;
|
||||
in_dialog = true;
|
||||
} else {
|
||||
var parent = _f.frm_con;
|
||||
}
|
||||
|
||||
// create the object
|
||||
var f = new _f.Frm(doctype, parent);
|
||||
f.in_dialog = in_dialog;
|
||||
|
||||
if(onload)onload(r,rt);
|
||||
}
|
||||
|
||||
// check if record is new (called from mapper etc)
|
||||
var is_new = 0;
|
||||
if(opt_name && locals[doctype] && locals[doctype][opt_name] && locals[doctype][opt_name].__islocal) {
|
||||
is_new = 1;
|
||||
}
|
||||
|
||||
if(opt_name && !is_new) {
|
||||
// get both
|
||||
var args = {'name':opt_name, 'doctype':doctype, 'getdoctype':1, 'user':user};
|
||||
|
||||
if(get_url_arg('akey')) args['akey'] = get_url_arg('akey');
|
||||
if(from_archive) args['from_archive'] = 1;
|
||||
|
||||
$c('webnotes.widgets.form.load.getdoc', args, callback);
|
||||
} else {
|
||||
// get doctype only
|
||||
$c('webnotes.widgets.form.load.getdoctype', args={'doctype':doctype}, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ _f.FrmHeader.prototype.refresh= function() {
|
|||
|
||||
// Save
|
||||
if(cur_frm.editable && cint(cur_frm.doc.docstatus)==0 && p[WRITE])
|
||||
this.page_head.add_button('Save', function() { cur_frm.save('Save');}, 1, 'icon-ok',1);
|
||||
this.page_head.add_button('Save', function() { cur_frm.save('Save');}, 1, '',1);
|
||||
|
||||
// Submit
|
||||
if(cint(cur_frm.doc.docstatus)==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ _r.ReportContainer = function() {
|
|||
msgprint("Not Allowed");
|
||||
return;
|
||||
}
|
||||
this.wrapper = page_body.add_page("Report Builder", function() { });
|
||||
this.wrapper = wn.container.add_page("Report Builder", function() { });
|
||||
this.wrapper.className ='layout_wrapper';
|
||||
var head_div = $a(this.wrapper, 'div');
|
||||
this.rb_area = $a(this.wrapper, 'div');
|
||||
|
|
@ -563,7 +563,7 @@ _r.ReportBuilder.prototype.validate_permissions = function(onload) {
|
|||
} else {
|
||||
msgprint('No Read Permission');
|
||||
}
|
||||
nav_obj.show_last_open();
|
||||
window.back();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ wn.widgets.form.sidebar = { Sidebar: function(form) {
|
|||
display: function() {
|
||||
return true;
|
||||
},
|
||||
onclick: function() { window.location.href="#!List2/" + me.form.doctype }
|
||||
onclick: function() { window.location.href="#!List/" + me.form.doctype }
|
||||
},
|
||||
|
||||
{
|
||||
|
|
|
|||
16
js/lib/history/history.min.js
vendored
16
js/lib/history/history.min.js
vendored
|
|
@ -8,19 +8,3 @@
|
|||
*/
|
||||
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
|
||||
|
||||
// manage history
|
||||
// load pages via ajax
|
||||
// setup the history adapter
|
||||
// if settings no_history is set, no history will be bound
|
||||
// this can be used to make it work with legacy
|
||||
|
||||
$(document).bind('ready', function() {
|
||||
// standard page openener
|
||||
$(window).bind('hashchange', function() {
|
||||
if(wn.settings.no_history)
|
||||
return;
|
||||
|
||||
// load the state on the browser
|
||||
wn.page.set(location.hash);
|
||||
});
|
||||
})
|
||||
|
|
|
|||
|
|
@ -95,14 +95,7 @@ wn.assets = {
|
|||
wn.dom.eval(txt);
|
||||
},
|
||||
css: function(txt, src) {
|
||||
var se = document.createElement('style');
|
||||
se.type = "text/css";
|
||||
if (se.styleSheet) {
|
||||
se.styleSheet.cssText = txt;
|
||||
} else {
|
||||
se.appendChild(document.createTextNode(txt));
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(se);
|
||||
wn.dom.set_style(txt);
|
||||
},
|
||||
cgi: function(txt, src) {
|
||||
// dynamic content, will return content as
|
||||
|
|
|
|||
13
js/wn/dom.js
13
js/wn/dom.js
|
|
@ -28,12 +28,25 @@ wn.dom.by_id = function(id) {
|
|||
}
|
||||
|
||||
wn.dom.eval = function(txt) {
|
||||
if(!txt) return;
|
||||
var el = document.createElement('script');
|
||||
el.appendChild(document.createTextNode(txt));
|
||||
// execute the script globally
|
||||
document.getElementsByTagName('head')[0].appendChild(el);
|
||||
}
|
||||
|
||||
wn.dom.set_style = function(txt) {
|
||||
if(!txt) return;
|
||||
var se = document.createElement('style');
|
||||
se.type = "text/css";
|
||||
if (se.styleSheet) {
|
||||
se.styleSheet.cssText = txt;
|
||||
} else {
|
||||
se.appendChild(document.createTextNode(txt));
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(se);
|
||||
}
|
||||
|
||||
wn.dom.add = function(parent, newtag, className, cs, innerHTML, onclick) {
|
||||
if(parent && parent.substr)parent = wn.dom.by_id(parent);
|
||||
var c = document.createElement(newtag);
|
||||
|
|
|
|||
|
|
@ -22,11 +22,49 @@
|
|||
|
||||
wn.provide('wn.model');
|
||||
|
||||
wn.model.no_value_type = ['Section Break', 'Column Break', 'HTML', 'Table',
|
||||
'Button', 'Image'];
|
||||
wn.model = {
|
||||
no_value_type: ['Section Break', 'Column Break', 'HTML', 'Table',
|
||||
'Button', 'Image'],
|
||||
|
||||
wn.model.can_delete = function(doctype) {
|
||||
if(!doctype) return false;
|
||||
return locals.DocType[doctype].allow_trash &&
|
||||
wn.boot.profile.can_cancel.indexOf(doctype)!=-1;
|
||||
with_doctype: function(doctype, callback) {
|
||||
if(locals.DocType[doctype]) {
|
||||
callback();
|
||||
} else {
|
||||
wn.call({
|
||||
method:'webnotes.widgets.form.load.getdoctype',
|
||||
args: {
|
||||
doctype: doctype
|
||||
},
|
||||
callback: callback
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
with_doc: function(doctype, name, callback) {
|
||||
if(!name) name = doctype; // single type
|
||||
if(locals[doctype] && locals[doctype][name]) {
|
||||
callback(name);
|
||||
} else {
|
||||
if(name && name.indexOf('New ' + doctype) != -1) {
|
||||
// newdoc
|
||||
name = LocalDB.create(doctype);
|
||||
callback(name);
|
||||
} else {
|
||||
wn.call({
|
||||
method: 'webnotes.widgets.form.load.getdoc',
|
||||
args: {
|
||||
doctype: doctype,
|
||||
name: name
|
||||
},
|
||||
callback: function(r) { callback(name); }
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
can_delete: function(doctype) {
|
||||
if(!doctype) return false;
|
||||
return locals.DocType[doctype].allow_trash &&
|
||||
wn.boot.profile.can_cancel.indexOf(doctype)!=-1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
|
||||
//
|
||||
// MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
wn.page = {
|
||||
set: function(src) {
|
||||
var new_selection = $('.inner div.content[_src="'+ src +'"]');
|
||||
if(!new_selection.length) {
|
||||
// get from server / localstorage
|
||||
wn.assets.execute(src);
|
||||
new_selection = $('.inner div.content[_src="'+ src +'"]');
|
||||
}
|
||||
|
||||
// hide current
|
||||
$('.inner .current_page').removeClass('current_page');
|
||||
|
||||
// show new
|
||||
new_selection.addClass('current_page');
|
||||
|
||||
// get title (the first h1, h2, h3)
|
||||
var title = $('nav ul li a[href*="' + src + '"]').attr('title') || 'No Title'
|
||||
|
||||
// replace state (to url)
|
||||
state = window.location.hash;
|
||||
if(state!=src) {
|
||||
window.location.hash = state;
|
||||
}
|
||||
else {
|
||||
document.title = title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,321 +0,0 @@
|
|||
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
|
||||
//
|
||||
// MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
wn.provide('wn.body');
|
||||
wn.provide('wn.list_views');
|
||||
|
||||
wn.body.ListPage = function(doctype) {
|
||||
wn.require('lib/css/body/list.css');
|
||||
wn.require('lib/js/wn/body/tags.js');
|
||||
wn.require('lib/js/wn/utils/datetime.js');
|
||||
|
||||
var me = this;
|
||||
$.extend(this, {
|
||||
make: function() {
|
||||
// page
|
||||
me.label = 'List/' + doctype;
|
||||
wn.require('lib/js/wn/body/page.js');
|
||||
me.page = new wn.body.Page(me.label, 1);
|
||||
me.page.update_history = function() {
|
||||
window.location.hash = 'List/' + encodeURIComponent(doctype);
|
||||
}
|
||||
var $w = $(me.page.wrapper);
|
||||
$w.append("<div></div><div></div>")
|
||||
me.page_head =
|
||||
new wn.body.PageHead($w.find('> div:eq(0)').get(0),
|
||||
wn.model.label_of(doctype) + ' List');
|
||||
|
||||
me.list =
|
||||
new wn.body.List(me, $w.find('> div:eq(1)').get(0), doctype);
|
||||
|
||||
me.make_sidebar();
|
||||
},
|
||||
|
||||
make_sidebar: function() {
|
||||
me.page.sidebar.style.marginTop = '13px';
|
||||
if(wn.profile.can_read.indexOf(doctype)!=-1) {
|
||||
new wn.ui.Button({
|
||||
parent: me.page.sidebar,
|
||||
css_class: 'blue-pill',
|
||||
label: '+ New ' + wn.model.label_of(doctype),
|
||||
style: {fontSize:'11px', margin: '13px', marginTop:'0px'},
|
||||
onclick: function() {
|
||||
wn.open('Form', doctype);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// sidebar
|
||||
wn.require('lib/js/wn/body/page_sidebar.js')
|
||||
me.sidebar = new wn.body.page_sidebar.Sidebar(me.page.sidebar, {
|
||||
sections: [
|
||||
{
|
||||
title: 'Top Tags',
|
||||
render: function(body) {
|
||||
new wn.body.tags.TagCloud(body, doctype, function(tag) {
|
||||
me.set_tag_filter(tag) });
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
},
|
||||
|
||||
// add a filter when a tag is clicked
|
||||
set_tag_filter: function(tag) {
|
||||
me.list.flist.set_filter_display();
|
||||
var l = tag.label;
|
||||
if(tag.fieldname=='_user_tags') l = '%' + tag.label
|
||||
me.list.flist.add_filter(tag.fieldname, 'like', l);
|
||||
me.list.refresh();
|
||||
}
|
||||
|
||||
});
|
||||
me.make();
|
||||
}
|
||||
|
||||
|
||||
// args (list name)
|
||||
wn.body.List = function(list_page, parent, doctype) {
|
||||
var me = this;
|
||||
me.start = 0;
|
||||
me.page_len = 20;
|
||||
|
||||
$.extend(this, {
|
||||
setup: function() {
|
||||
wn.require('lib/js/wn/model/list.js');
|
||||
|
||||
// doctype for rendering
|
||||
var dt = wn.model.get_doctype(doctype);
|
||||
|
||||
me.preloaded = wn.list.has(doctype);
|
||||
|
||||
// get the list
|
||||
var res = wn.list.get(doctype, null, me.start, me.page_len, 1);
|
||||
me.list = res.message || [];
|
||||
if(res.list_view_js) {
|
||||
eval('me.list_view_obj=' + res.list_view_js);
|
||||
}
|
||||
},
|
||||
|
||||
make: function() {
|
||||
// body
|
||||
me.make_body();
|
||||
me.make_filters();
|
||||
me.setup();
|
||||
me.render(me.list);
|
||||
if(me.preloaded)
|
||||
me.reload();
|
||||
},
|
||||
|
||||
make_body: function() {
|
||||
// new / refresh area
|
||||
me.toolbar_area = wn.dom.add(parent, 'div');
|
||||
|
||||
// list area
|
||||
me.list_area = wn.dom.add(parent, 'div');
|
||||
|
||||
// more btn
|
||||
me.more_btn_area = wn.dom.add(parent, 'div', 'more_btn_area');
|
||||
me.nothing_more = wn.dom.add(parent, 'div', 'nothing_more round');
|
||||
|
||||
},
|
||||
|
||||
make_filters: function() {
|
||||
me.filter_area = wn.dom.add(me.toolbar_area, 'div');
|
||||
wn.require('lib/js/wn/body/filter.js');
|
||||
me.flist = new wn.body.FilterList(me, me.filter_area, doctype);
|
||||
|
||||
},
|
||||
|
||||
reload: function() {
|
||||
wn.list.diff(doctype, (me.list.length ? me.list[0].modified : null),
|
||||
me.render_reload);
|
||||
},
|
||||
|
||||
render_reload: function(res) {
|
||||
me.list = res.new_list;
|
||||
me.list_area.innerHTML = ''
|
||||
|
||||
if(res.list_view_js) {
|
||||
eval('me.list_view_obj=' + res.list_view_js);
|
||||
}
|
||||
|
||||
me.render(me.list);
|
||||
|
||||
// update heading
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
// get the list
|
||||
me.start = 0;
|
||||
me.list = wn.list.get(doctype,
|
||||
me.flist.get_filters(),
|
||||
me.start, me.page_len);
|
||||
me.render(me.list);
|
||||
},
|
||||
|
||||
extend: function() {
|
||||
me.start += me.page_len
|
||||
var add = wn.list.get(doctype, me.flist.get_filters(), me.start, me.page_len);
|
||||
me.list = me.list.concat(add);
|
||||
me.render(add);
|
||||
},
|
||||
|
||||
// render the list
|
||||
render: function(list) {
|
||||
if(me.start==0)
|
||||
me.list_area.innerHTML = '';
|
||||
|
||||
$.each(list, function(i, d) {
|
||||
d.doctype = doctype;
|
||||
if(!d.__deleted)
|
||||
new wn.body.ListItem(me, me.list_area, d);
|
||||
});
|
||||
|
||||
// show filters, they may be hidden later
|
||||
wn.dom.show(me.filter_area);
|
||||
|
||||
if(list.length >= me.page_len) {
|
||||
me.show_more_btn();
|
||||
} else {
|
||||
me.hide_more_btn();
|
||||
}
|
||||
},
|
||||
|
||||
show_more_btn: function() {
|
||||
if(!me.more_btn) {
|
||||
me.more_btn = new wn.ui.Button({
|
||||
parent: me.more_btn_area,
|
||||
label: 'Show more results',
|
||||
onclick: function() {
|
||||
me.extend();
|
||||
},
|
||||
style: {
|
||||
width: '200px',
|
||||
fontSize:'14px'
|
||||
}
|
||||
})
|
||||
}
|
||||
wn.dom.show(me.more_btn_area);
|
||||
wn.dom.hide(me.nothing_more);
|
||||
},
|
||||
|
||||
hide_more_btn: function() {
|
||||
wn.dom.hide(me.more_btn_area);
|
||||
wn.dom.show(me.nothing_more);
|
||||
if(me.list.length) {
|
||||
me.nothing_more.innerHTML = 'Thats it';
|
||||
} else {
|
||||
me.nothing_more.innerHTML = 'No matches :( Try again.';
|
||||
|
||||
if(!me.flist.get_filters().length) {
|
||||
wn.dom.hide(me.filter_area);
|
||||
|
||||
// new link
|
||||
if(wn.profile.can_create.indexOf(doctype)!=-1) {
|
||||
$(me.nothing_more).html('<div class="new_link">\
|
||||
<span class="link_type" onclick="wn.open(\'Form\', \'%(doctype)s\')">\
|
||||
Click here to create your first %(doctype_label)s\
|
||||
</span>\
|
||||
</div>'.repl({
|
||||
doctype:doctype,
|
||||
doctype_label: wn.model.label_of(doctype)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
me.make();
|
||||
}
|
||||
|
||||
// title (link), owner, last update, delete / archive, tags
|
||||
wn.body.ListItem = function(list, parent, args) {
|
||||
var me = this;
|
||||
$.extend(this, {
|
||||
make: function() {
|
||||
me.wrapper = wn.dom.add(parent, 'div', 'list_item');
|
||||
me.wrapper.innerHTML = '<div>\
|
||||
<span class="pre_subject"></span>\
|
||||
<span class="link_type subject">%(label)s</span>\
|
||||
<span class="post_subject"></span>\
|
||||
<span class="wn-icon ic-round_minus delete_btn"></span>\
|
||||
<span class="user_info">%(owner)s %(timestamp)s</span>\
|
||||
</div>\
|
||||
<div class="list_view"></div>'.repl({
|
||||
label: args.label || args.name,
|
||||
owner: args.owner,
|
||||
timestamp: wn.utils.datetime.when(args.modified)
|
||||
});
|
||||
|
||||
$w = $(me.wrapper);
|
||||
// hide delete if no perms
|
||||
if(!(wn.model.get_doctype(args.doctype).get_perm()[0] || {}).cancel) {
|
||||
$w.find('.delete_btn').css('display','none');
|
||||
} else {
|
||||
$w.find('.delete_btn').click(function() {
|
||||
wn.require('lib/js/wn/ui/confirm.js');
|
||||
if(wn.ui.confirm('You sure you want to delete?', function() {
|
||||
wn.http.post({
|
||||
args: {
|
||||
cmd:'webnotes.widgets.menus.delete_doc',
|
||||
doctype:args.doctype,
|
||||
name:args.name
|
||||
}
|
||||
});
|
||||
$w.slideUp();
|
||||
}));
|
||||
})
|
||||
}
|
||||
|
||||
// open
|
||||
$w.find('.subject')
|
||||
.bind('click', function() {
|
||||
wn.open('Form', args.doctype, args.name);
|
||||
});
|
||||
|
||||
// render body
|
||||
me.render_body($w);
|
||||
},
|
||||
|
||||
render_body: function($w) {
|
||||
var lv = list.list_view_obj
|
||||
if(lv) {
|
||||
if(lv.subject) {
|
||||
$w.find('.subject').html(lv.subject.repl(args));
|
||||
}
|
||||
if(lv.render) {
|
||||
lv.render($w, args);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
render_tag: function() {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
me.make();
|
||||
}
|
||||
49
js/wn/router.js
Normal file
49
js/wn/router.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// route urls to their virtual pages
|
||||
|
||||
wn.route = function() {
|
||||
var route = window.location.hash;
|
||||
wn._cur_route = location.hash;
|
||||
|
||||
if(route.substr(0,1)=='#') route = route.substr(1);
|
||||
if(route.substr(0,1)=='!') route = route.substr(1);
|
||||
|
||||
route = $.map(route.split('/'), function(r) { return decodeURIComponent(r); });
|
||||
|
||||
switch (route[0]) {
|
||||
case "List":
|
||||
wn.views.doclistview.show(route[1]);
|
||||
break;
|
||||
case "Form":
|
||||
if(route.length>3) {
|
||||
route[2] = route.splice(2).join('/');
|
||||
}
|
||||
wn.views.formview.show(route[1], route[2]);
|
||||
break;
|
||||
case "Report":
|
||||
wn.views.reportview.show(route[1], route[2]);
|
||||
break;
|
||||
default:
|
||||
wn.views.pageview.show(route[0]);
|
||||
}
|
||||
}
|
||||
|
||||
wn.set_route = function(route) {
|
||||
window.location.hash = route;
|
||||
}
|
||||
|
||||
wn._cur_route = null;
|
||||
|
||||
$(window).bind('hashchange', function() {
|
||||
if(location.hash==wn._cur_route)
|
||||
return;
|
||||
wn.route();
|
||||
|
||||
// analytics code
|
||||
if(wn.boot.analytics_code) {
|
||||
try {
|
||||
eval(wn.boot.analytics_code);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
46
js/wn/views/container.js
Normal file
46
js/wn/views/container.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// page container
|
||||
wn.provide('wn.pages');
|
||||
wn.provide('wn.views');
|
||||
|
||||
wn.views.Container = Class.extend({
|
||||
init: function() {
|
||||
this.container = $('#body_div').get(0);
|
||||
this.page = null; // current page
|
||||
},
|
||||
add_page: function(label, onshow, onhide) {
|
||||
var page = $('<div class="content"></div>')
|
||||
.appendTo(this.container).get(0);
|
||||
if(onshow)
|
||||
$(page).bind('show', onshow);
|
||||
if(onshow)
|
||||
$(page).bind('hide', onhide);
|
||||
page.label = label;
|
||||
wn.pages[label] = page;
|
||||
return page;
|
||||
},
|
||||
change_to: function(label) {
|
||||
if(label.tagName) {
|
||||
// if sent the div, get the table
|
||||
var page = label;
|
||||
} else {
|
||||
var page = wn.pages[label];
|
||||
}
|
||||
if(!page) {
|
||||
console.log('Page not found ' + label);
|
||||
return;
|
||||
}
|
||||
|
||||
// hide current
|
||||
if(this.page) {
|
||||
$(this.page).css('left', '-1000px');
|
||||
}
|
||||
|
||||
// show new
|
||||
this.page = page;
|
||||
$(this.page).css('left', '0px');
|
||||
return this.page;
|
||||
},
|
||||
show: function(label) {
|
||||
return this.change_to(label);
|
||||
}
|
||||
});
|
||||
|
|
@ -20,24 +20,26 @@
|
|||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
wn.provide('wn.pages.doclistview');
|
||||
wn.provide('wn.views.doclistview');
|
||||
wn.provide('wn.doclistviews');
|
||||
|
||||
wn.pages.doclistview.pages = {};
|
||||
wn.pages.doclistview.show = function(doctype) {
|
||||
wn.views.doclistview.pages = {};
|
||||
wn.views.doclistview.show = function(doctype) {
|
||||
var pagename = doctype + ' List';
|
||||
var page = wn.pages.doclistview.pages[pagename];
|
||||
if(!page) {
|
||||
var page = page_body.add_page(pagename);
|
||||
page.doclistview = new wn.pages.DocListView(doctype, page);
|
||||
wn.pages.doclistview.pages[pagename] = page;
|
||||
}
|
||||
|
||||
document.title = page.doclistview.label;
|
||||
page_body.change_to(pagename);
|
||||
wn.model.with_doctype(doctype, function() {
|
||||
var page = wn.views.doclistview.pages[pagename];
|
||||
if(!page) {
|
||||
var page = wn.container.add_page(pagename);
|
||||
page.doclistview = new wn.views.DocListView(doctype, page);
|
||||
wn.views.doclistview.pages[pagename] = page;
|
||||
}
|
||||
|
||||
document.title = page.doclistview.label;
|
||||
wn.container.change_to(pagename);
|
||||
})
|
||||
}
|
||||
|
||||
wn.pages.DocListView = wn.ui.Listing.extend({
|
||||
wn.views.DocListView = wn.ui.Listing.extend({
|
||||
init: function(doctype, page) {
|
||||
this.doctype = get_label_doctype(doctype);
|
||||
this.$page = $(page);
|
||||
|
|
@ -45,7 +47,7 @@ wn.pages.DocListView = wn.ui.Listing.extend({
|
|||
this.label = (this.label.toLowerCase().substr(-4) == 'list') ?
|
||||
this.label : (this.label + ' List');
|
||||
this.make_page();
|
||||
this.load_doctype();
|
||||
this.setup();
|
||||
},
|
||||
|
||||
make_page: function() {
|
||||
|
|
@ -69,22 +71,16 @@ wn.pages.DocListView = wn.ui.Listing.extend({
|
|||
</div>', {label: this.label}));
|
||||
},
|
||||
|
||||
load_doctype: function() {
|
||||
setup: function() {
|
||||
var me = this;
|
||||
wn.call({
|
||||
method: 'webnotes.widgets.form.load.getdoctype',
|
||||
args: {doctype: me.doctype},
|
||||
callback: function() {
|
||||
me.can_delete = wn.model.can_delete(me.doctype);
|
||||
me.meta = locals.DocType[me.doctype];
|
||||
me.$page.find('.wnlist-area').empty(),
|
||||
me.setup_docstatus_filter();
|
||||
me.setup_listview();
|
||||
me.init_list();
|
||||
me.init_stats();
|
||||
me.add_delete_option();
|
||||
}
|
||||
});
|
||||
me.can_delete = wn.model.can_delete(me.doctype);
|
||||
me.meta = locals.DocType[me.doctype];
|
||||
me.$page.find('.wnlist-area').empty(),
|
||||
me.setup_docstatus_filter();
|
||||
me.setup_listview();
|
||||
me.init_list();
|
||||
me.init_stats();
|
||||
me.add_delete_option();
|
||||
},
|
||||
setup_docstatus_filter: function() {
|
||||
var me = this;
|
||||
|
|
@ -104,7 +100,7 @@ wn.pages.DocListView = wn.ui.Listing.extend({
|
|||
eval(this.meta.__listjs);
|
||||
this.listview = new wn.doclistviews[this.doctype](this);
|
||||
} else {
|
||||
this.listview = new wn.pages.ListView(this);
|
||||
this.listview = new wn.views.ListView(this);
|
||||
}
|
||||
this.listview.parent = this;
|
||||
},
|
||||
|
|
@ -281,7 +277,7 @@ wn.pages.DocListView = wn.ui.Listing.extend({
|
|||
}
|
||||
});
|
||||
|
||||
wn.pages.ListView = Class.extend({
|
||||
wn.views.ListView = Class.extend({
|
||||
init: function(doclistview) {
|
||||
this.doclistview = doclistview;
|
||||
this.doctype = doclistview.doctype;
|
||||
19
js/wn/views/formview.js
Normal file
19
js/wn/views/formview.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// render formview
|
||||
|
||||
wn.provide('wn.views.formview');
|
||||
|
||||
wn.views.formview = {
|
||||
show: function(dt, dn) {
|
||||
// show doctype
|
||||
wn.model.with_doctype(dt, function() {
|
||||
wn.model.with_doc(dt, dn, function(dn) {
|
||||
if(!wn.views.formview[dt]) {
|
||||
wn.views.formview[dt] = wn.container.add_page('Form - ' + dt);
|
||||
wn.views.formview[dt].frm = new _f.Frm(dt, wn.views.formview[dt]);
|
||||
}
|
||||
wn.container.change_to('Form - ' + dt);
|
||||
wn.views.formview[dt].frm.refresh(dn);
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
63
js/wn/views/pageview.js
Normal file
63
js/wn/views/pageview.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
wn.provide('wn.views.pageview');
|
||||
|
||||
wn.views.pageview = {
|
||||
pages: {},
|
||||
with_page: function(name, callback) {
|
||||
if(!locals.Page[name]) {
|
||||
wn.call({
|
||||
method: 'webnotes.widgets.page.getpage',
|
||||
args: {'name':name },
|
||||
callback: callback
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
show: function(name) {
|
||||
wn.views.pageview.with_page(name, function() {
|
||||
if(!wn.pages[name]) {
|
||||
wn.views.pageview.pages[name] = new wn.views.Page(name);
|
||||
}
|
||||
wn.container.change_to(name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
wn.views.Page = Class.extend({
|
||||
init: function(name) {
|
||||
this.name = name;
|
||||
this.render();
|
||||
},
|
||||
render: function() {
|
||||
var me = this;
|
||||
|
||||
this.pagedoc = locals.Page[this.name];
|
||||
this.wrapper = wn.container.add_page(this.name);
|
||||
|
||||
// set content, script and style
|
||||
this.wrapper.innerHTML = this.pagedoc.content;
|
||||
wn.dom.eval(this.pagedoc.__script || this.pagedoc.script || '');
|
||||
wn.dom.set_style(this.pagedoc.style);
|
||||
|
||||
this.trigger('onload');
|
||||
|
||||
// set events
|
||||
$(this.wrapper).bind('show', function() {
|
||||
cur_frm = null;
|
||||
me.trigger('onshow');
|
||||
});
|
||||
},
|
||||
trigger: function(event) {
|
||||
var me = this;
|
||||
try {
|
||||
if(pscript[event+'_'+this.name]) {
|
||||
pscript[event+'_'+this.name](me.wrapper);
|
||||
}
|
||||
if(me.wrapper[event]) {
|
||||
me.wrapper[event](me.wrapper);
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
})
|
||||
32
js/wn/views/reportview.js
Normal file
32
js/wn/views/reportview.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
wn.views.reportview = {
|
||||
show: function(dt, rep_name) {
|
||||
wn.require('lib/js/legacy/report.compressed.js');
|
||||
dt = get_label_doctype(dt);
|
||||
|
||||
if(!_r.rb_con) {
|
||||
// first load
|
||||
_r.rb_con = new _r.ReportContainer();
|
||||
}
|
||||
|
||||
_r.rb_con.set_dt(dt, function(rb) {
|
||||
if(rep_name) {
|
||||
var t = rb.current_loaded;
|
||||
rb.load_criteria(rep_name);
|
||||
|
||||
// call onload
|
||||
if(onload)
|
||||
onload(rb);
|
||||
|
||||
// if loaded, then run
|
||||
if((rb.dt) && (!rb.dt.has_data() || rb.current_loaded!=t))
|
||||
rb.dt.run();
|
||||
|
||||
}
|
||||
|
||||
// show
|
||||
if(!rb.forbidden) {
|
||||
wn.container.change_to('Report Builder');
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ class Document:
|
|||
for f in forbidden:
|
||||
if f in self.name:
|
||||
webnotes.msgprint('%s not allowed in ID (name)' % f, raise_exception =1)
|
||||
|
||||
|
||||
# Insert
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue