Merge branch 'handlerupdate' of github.com:webnotes/wnframework into handlerupdate

This commit is contained in:
Rushabh Mehta 2012-03-21 08:15:36 +01:00
commit 32fe4fde38
4 changed files with 23 additions and 15 deletions

13
js/core.min.js vendored
View file

@ -49,6 +49,11 @@ 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'],new_names:{},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/tools.js
*/
wn.markdown=function(txt){if(!wn.md2html){wn.require('lib/js/lib/showdown.js');wn.md2html=new Showdown.converter();}
return wn.md2html.makeHtml(txt);}
/*
* lib/js/wn/misc/user.js
*/
@ -227,13 +232,13 @@ wn.views.DocListView=wn.ui.Listing.extend({init:function(doctype,page){this.doct
<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,no_result_message:this.make_no_result(),columns:this.listview.fields});this.run();},make_no_result:function(){return repl('<div class="well"><p>No %(doctype)s found</p>\
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,no_result_message:this.make_no_result(),columns:this.listview.fields});this.run();},make_no_result:function(){return repl('<div class="well"><p>No %(doctype_label)s found</p>\
%(description)s\
<hr>\
<p><button class="btn btn-info btn-small"\
onclick="wn.set_route(\'Form\', \'New %(doctype)s\');"\
>Make a new %(doctype)s</button>\
</p></div>',{doctype:this.doctype,description:locals.DocType[this.doctype].description||''});},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">\
onclick="wn.set_route(\'Form\', \'%(doctype)s\', \'New %(doctype)s\');"\
>Make a new %(doctype_label)s</button>\
</p></div>',{doctype_label:get_doctype_label(this.doctype),doctype:this.doctype,description:wn.markdown(locals.DocType[this.doctype].description||'')});},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-delete: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

View file

@ -165,13 +165,8 @@ wn.widgets.form.sidebar = { Sidebar: function(form) {
{
title: 'Help',
render: function(wrapper) {
if(!wn.md2html) {
wn.require('lib/js/lib/showdown.js');
wn.md2html = new Showdown.converter();
}
$a(wrapper, 'div', 'help small', {},
wn.md2html.makeHtml(me.form.meta.description));
$(wrapper).html('<div class="help small">'
+ wn.markdown(me.form.meta.description) + '</div>')
},
display: function() { return me.form.meta.description }
}

7
js/wn/misc/tools.js Normal file
View file

@ -0,0 +1,7 @@
wn.markdown = function(txt) {
if(!wn.md2html) {
wn.require('lib/js/lib/showdown.js');
wn.md2html = new Showdown.converter();
}
return wn.md2html.makeHtml(txt);
}

View file

@ -123,15 +123,16 @@ wn.views.DocListView = wn.ui.Listing.extend({
this.run();
},
make_no_result: function() {
return repl('<div class="well"><p>No %(doctype)s found</p>\
return repl('<div class="well"><p>No %(doctype_label)s found</p>\
%(description)s\
<hr>\
<p><button class="btn btn-info btn-small"\
onclick="wn.set_route(\'Form\', \'New %(doctype)s\');"\
>Make a new %(doctype)s</button>\
onclick="wn.set_route(\'Form\', \'%(doctype)s\', \'New %(doctype)s\');"\
>Make a new %(doctype_label)s</button>\
</p></div>', {
doctype_label: get_doctype_label(this.doctype),
doctype: this.doctype,
description: locals.DocType[this.doctype].description || ''
description: wn.markdown(locals.DocType[this.doctype].description || '')
});
},
render_row: function(row, data) {