Merge branch 'master' of github.com:webnotes/wnframework into cms2
This commit is contained in:
commit
b8e4d337d5
26 changed files with 212 additions and 103 deletions
2
js/core.min.js
vendored
2
js/core.min.js
vendored
|
|
@ -273,7 +273,7 @@ wn.request.cleanup=function(opts,r){if(opts.btn)$(opts.btn).done_working();if(op
|
|||
return;}
|
||||
if(r.server_messages)msgprint(r.server_messages)
|
||||
if(r.exc){console.log(r.exc);};if(r['403']){wn.container.change_to('403');}
|
||||
if(r.docs)LocalDB.sync(r.docs);}
|
||||
if(r.docs){LocalDB.sync(r.docs);}}
|
||||
wn.request.call=function(opts){wn.request.prepare(opts);$.ajax({url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
|
||||
if(opts.error)opts.error(xhr)}})}
|
||||
wn.call=function(opts){var args=$.extend({},opts.args)
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@ function get_local(dt, dn) { return locals[dt] ? locals[dt][dn] : null; }
|
|||
|
||||
LocalDB.sync = function(list) {
|
||||
if(list._kl)list = expand_doclist(list);
|
||||
if (list) {
|
||||
LocalDB.clear_locals(list[0].doctype, list[0].name);
|
||||
}
|
||||
for(var i=0;i<list.length;i++) {
|
||||
var d = list[i];
|
||||
if(!d.name) // get name (local if required)
|
||||
|
|
@ -96,6 +99,15 @@ LocalDB.sync = function(list) {
|
|||
}
|
||||
}
|
||||
|
||||
LocalDB.clear_locals = function(dt, dn) {
|
||||
var doclist = make_doclist(dt, dn, 1);
|
||||
// console.dir(['in clear', doclist]);
|
||||
$.each(doclist, function(i, v) {
|
||||
v && delete locals[v.doctype][v.name];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Get Local Name
|
||||
// ======================================================================================
|
||||
|
||||
|
|
@ -269,6 +281,7 @@ LocalDB.copy=function(dt, dn, from_amend) {
|
|||
// ======================================================================================
|
||||
|
||||
function make_doclist(dt, dn, deleted) {
|
||||
if(!locals[dt]) { return []; }
|
||||
var dl = [];
|
||||
dl[0] = locals[dt][dn];
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ $c_get_values = function(args, doc, dt, dn, user_callback) {
|
|||
|
||||
get_server_fields = function(method, arg, table_field, doc, dt, dn, allow_edit, call_back) {
|
||||
if(!allow_edit)freeze('Fetching Data...');
|
||||
$c('runserverobj', args={'method':method, 'docs':compress_doclist([doc]), 'arg':arg},
|
||||
$c('runserverobj', args={'method':method, 'docs':compress_doclist(make_doclist(doc.doctype, doc.name)), 'arg':arg},
|
||||
function(r, rt) {
|
||||
if (r.message) {
|
||||
var d = locals[dt][dn];
|
||||
|
|
|
|||
|
|
@ -643,10 +643,21 @@ LinkField.prototype.make_input = function() {
|
|||
};
|
||||
|
||||
$(this.txt).change(function() {
|
||||
if(!$(this).val()) {
|
||||
var val = $(this).val();//me.get_value();
|
||||
|
||||
me.set_input_value_executed = false;
|
||||
|
||||
if(!val) {
|
||||
if(selector && selector.display)
|
||||
return;
|
||||
me.set_input_value('');
|
||||
} else {
|
||||
// SetTimeout hack! if in put is set via autocomplete, do not validate twice
|
||||
setTimeout(function() {
|
||||
if (!me.set_input_value_executed) {
|
||||
me.set_input_value(val);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -662,7 +673,7 @@ LinkField.prototype.get_custom_query = function() {
|
|||
|
||||
LinkField.prototype.setup_buttons = function() {
|
||||
var me = this;
|
||||
|
||||
|
||||
// magnifier - search
|
||||
me.btn.onclick = function() {
|
||||
selector.set(me, me.df.options, me.df.label);
|
||||
|
|
@ -701,6 +712,10 @@ LinkField.prototype.setup_buttons = function() {
|
|||
|
||||
LinkField.prototype.set_input_value = function(val) {
|
||||
var me = this;
|
||||
|
||||
// SetTimeout hack! if in put is set via autocomplete, do not validate twice
|
||||
me.set_input_value_executed = true;
|
||||
|
||||
var from_selector = false;
|
||||
if(selector && selector.display) from_selector = true;
|
||||
|
||||
|
|
@ -735,7 +750,12 @@ LinkField.prototype.set_input_value = function(val) {
|
|||
return;
|
||||
}
|
||||
|
||||
me.validate_link(val, from_selector);
|
||||
}
|
||||
|
||||
LinkField.prototype.validate_link = function(val, from_selector) {
|
||||
// validate the value just entered
|
||||
var me = this;
|
||||
var fetch = '';
|
||||
if(cur_frm.fetch_dict[me.df.fieldname])
|
||||
fetch = cur_frm.fetch_dict[me.df.fieldname].columns.join(', ');
|
||||
|
|
@ -745,7 +765,7 @@ LinkField.prototype.set_input_value = function(val) {
|
|||
'options':me.df.options,
|
||||
'fetch': fetch
|
||||
},
|
||||
function(r,rt) {
|
||||
function(r,rt) {
|
||||
if(r.message=='Ok') {
|
||||
// set fetch values
|
||||
if($(me.txt).val()!=val) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ wn.provide('_f');
|
|||
|
||||
_f.frms = {};
|
||||
|
||||
_f.Frm = function(doctype, parent) {
|
||||
_f.Frm = function(doctype, parent, in_form) {
|
||||
this.docname = '';
|
||||
this.doctype = doctype;
|
||||
this.display = 0;
|
||||
|
|
@ -61,6 +61,9 @@ _f.Frm = function(doctype, parent) {
|
|||
|
||||
this.setup_meta(doctype);
|
||||
|
||||
// show in form instead of in dialog, when called using url (router.js)
|
||||
this.in_form = in_form ? true : false;
|
||||
|
||||
// notify on rename
|
||||
var me = this;
|
||||
$(document).bind('rename', function(event, dt, old_name, new_name) {
|
||||
|
|
@ -142,8 +145,8 @@ _f.Frm.prototype.onhide = function() { if(_f.cur_grid_cell) _f.cur_grid_cell.gri
|
|||
_f.Frm.prototype.setup_std_layout = function() {
|
||||
this.page_layout = new wn.PageLayout({
|
||||
parent: this.wrapper,
|
||||
main_width: this.meta.in_dialog ? '100%' : '75%',
|
||||
sidebar_width: this.meta.in_dialog ? '0%' : '25%'
|
||||
main_width: (this.meta.in_dialog && !this.in_form) ? '100%' : '75%',
|
||||
sidebar_width: (this.meta.in_dialog && !this.in_form) ? '0%' : '25%'
|
||||
})
|
||||
|
||||
// only tray
|
||||
|
|
@ -153,7 +156,7 @@ _f.Frm.prototype.setup_std_layout = function() {
|
|||
this.layout = new Layout(this.page_layout.body, '100%');
|
||||
|
||||
// sidebar
|
||||
if(this.meta.in_dialog) {
|
||||
if(this.meta.in_dialog && !this.in_form) {
|
||||
// hide sidebar
|
||||
$(this.page_layout.wrapper).removeClass('layout-wrapper-background');
|
||||
$(this.page_layout.main).removeClass('layout-main-section');
|
||||
|
|
@ -164,11 +167,11 @@ _f.Frm.prototype.setup_std_layout = function() {
|
|||
}
|
||||
|
||||
// footer
|
||||
this.setup_footer();
|
||||
this.setup_footer();
|
||||
|
||||
|
||||
// header - no headers for tables and guests
|
||||
if(!(this.meta.istable || user=='Guest' || this.meta.in_dialog))
|
||||
if(!(this.meta.istable || user=='Guest' || (this.meta.in_dialog && !this.in_form)))
|
||||
this.frm_head = new _f.FrmHeader(this.page_layout.head, this);
|
||||
|
||||
// bg colour
|
||||
|
|
@ -246,7 +249,7 @@ _f.Frm.prototype.email_doc = function() {
|
|||
|
||||
_f.Frm.prototype.rename_notify = function(dt, old, name) {
|
||||
// from form
|
||||
if(this.meta.in_dialog)
|
||||
if(this.meta.in_dialog && !this.in_form)
|
||||
return;
|
||||
|
||||
if(this.docname == old)
|
||||
|
|
@ -276,7 +279,7 @@ _f.Frm.prototype.rename_notify = function(dt, old, name) {
|
|||
// ======================================================================================
|
||||
|
||||
|
||||
_f.Frm.prototype.setup_meta = function() {
|
||||
_f.Frm.prototype.setup_meta = function(doctype) {
|
||||
this.meta = get_local('DocType',this.doctype);
|
||||
this.perm = get_perm(this.doctype); // for create
|
||||
if(this.meta.istable) { this.meta.in_dialog = 1 }
|
||||
|
|
@ -471,7 +474,7 @@ _f.Frm.prototype.get_doc_perms = function() {
|
|||
_f.Frm.prototype.refresh_header = function() {
|
||||
// set title
|
||||
// main title
|
||||
if(!this.meta.in_dialog) {
|
||||
if(!this.meta.in_dialog || this.in_form) {
|
||||
set_title(this.meta.issingle ? this.doctype : this.docname);
|
||||
}
|
||||
|
||||
|
|
@ -514,7 +517,7 @@ _f.Frm.prototype.check_doc_perm = function() {
|
|||
_f.Frm.prototype.refresh = function(docname) {
|
||||
// record switch
|
||||
if(docname) {
|
||||
if(this.docname != docname && !this.meta.in_dialog && !this.meta.istable) scroll(0, 0);
|
||||
if(this.docname != docname && (!this.meta.in_dialog || this.in_form) && !this.meta.istable) scroll(0, 0);
|
||||
this.docname = docname;
|
||||
}
|
||||
if(!this.meta.istable) {
|
||||
|
|
@ -613,7 +616,7 @@ _f.Frm.prototype.refresh = function(docname) {
|
|||
_f.Frm.prototype.refresh_footer = function() {
|
||||
var f = this.page_layout.footer;
|
||||
if(f.save_area) {
|
||||
if(get_url_arg('embed') || (this.editable && !this.meta.in_dialog && this.doc.docstatus==0 && !this.meta.istable && this.get_doc_perms()[WRITE])) {
|
||||
if(get_url_arg('embed') || (this.editable && (!this.meta.in_dialog || this.in_form) && this.doc.docstatus==0 && !this.meta.istable && this.get_doc_perms()[WRITE])) {
|
||||
f.show_save();
|
||||
} else {
|
||||
f.hide_save();
|
||||
|
|
@ -1075,7 +1078,7 @@ _f.Frm.prototype.savetrash = function() {
|
|||
if(wn.ui.toolbar.recent) wn.ui.toolbar.recent.remove(me.doctype, me.docname);
|
||||
|
||||
// "close"
|
||||
window.back();
|
||||
window.history.back();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -478,6 +478,8 @@ _r.ReportBuilder.prototype.setup_filters_and_cols = function() {
|
|||
_r.ReportBuilder.prototype.set_filters_from_route = function() {
|
||||
// add filters from route
|
||||
var route = wn.get_route();
|
||||
//save this for checking changes in filter
|
||||
this.current_route = wn.get_route_str();
|
||||
if(route.length>3) {
|
||||
for(var i=3; i<route.length; i++) {
|
||||
var p = route[i].split('=');
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ wn.widgets.form.sidebar = { Sidebar: function(form) {
|
|||
type: 'link',
|
||||
label: 'Delete',
|
||||
display: function() {
|
||||
return me.form.meta.allow_trash && cint(me.form.doc.docstatus) != 2
|
||||
&& (!me.form.doc.__islocal) && me.form.perm[0][CANCEL]
|
||||
return (cint(me.form.doc.docstatus) != 1) && !me.form.doc.__islocal
|
||||
&& wn.model.can_delete(me.form.doctype);
|
||||
},
|
||||
icon: 'icon-remove-sign',
|
||||
onclick: function() { me.form.savetrash() }
|
||||
|
|
|
|||
|
|
@ -74,7 +74,9 @@ wn.request.cleanup = function(opts, r) {
|
|||
}
|
||||
|
||||
// sync docs
|
||||
if(r.docs) LocalDB.sync(r.docs);
|
||||
if(r.docs) {
|
||||
LocalDB.sync(r.docs);
|
||||
}
|
||||
}
|
||||
|
||||
wn.request.call = function(opts) {
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ wn.views.DocListView = wn.ui.Listing.extend({
|
|||
this.allow_delete = true;
|
||||
},
|
||||
init_list: function(auto_run) {
|
||||
var me = this;
|
||||
// init list
|
||||
this.make({
|
||||
method: 'webnotes.widgets.doclistview.get',
|
||||
|
|
@ -138,20 +139,30 @@ wn.views.DocListView = wn.ui.Listing.extend({
|
|||
no_result_message: this.make_no_result(),
|
||||
columns: this.listview.fields
|
||||
});
|
||||
|
||||
// make_new_doc can be overridden so that default values can be prefilled
|
||||
// for example - communication list in customer
|
||||
$(this.wrapper).find('button[list_view_doc="'+me.doctype+'"]').click(function(){
|
||||
me.make_new_doc(me.doctype);
|
||||
});
|
||||
|
||||
if((auto_run !== false) && (auto_run !== 0)) this.run();
|
||||
},
|
||||
|
||||
make_no_result: function() {
|
||||
return repl('<div class="well"><p>No %(doctype_label)s found</p>\
|
||||
var no_result_message = repl('<div class="well">\
|
||||
<p>No %(doctype_label)s found</p>\
|
||||
%(description)s\
|
||||
<hr>\
|
||||
<p><button class="btn btn-info btn-small"\
|
||||
onclick="newdoc(\'%(doctype)s\');"\
|
||||
>Make a new %(doctype_label)s</button>\
|
||||
<p><button class="btn btn-info btn-small" list_view_doc="%(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 || '')
|
||||
description: wn.markdown(locals.DocType[this.doctype].description || ''),
|
||||
});
|
||||
|
||||
return no_result_message;
|
||||
},
|
||||
render_row: function(row, data) {
|
||||
data.doctype = this.doctype;
|
||||
|
|
@ -431,18 +442,7 @@ wn.views.ListView = Class.extend({
|
|||
data.fullname = wn.user_info(data.owner).fullname;
|
||||
data.avatar = wn.user_info(data.owner).image;
|
||||
|
||||
// when
|
||||
data.when = dateutil.str_to_user(data.modified).split(' ')[0];
|
||||
var diff = dateutil.get_diff(dateutil.get_today(), data.modified.split(' ')[0]);
|
||||
if(diff==0) {
|
||||
data.when = dateutil.comment_when(data.modified);
|
||||
}
|
||||
if(diff == 1) {
|
||||
data.when = 'Yesterday'
|
||||
}
|
||||
if(diff == 2) {
|
||||
data.when = '2 days ago'
|
||||
}
|
||||
this.prepare_when(data, data.modified);
|
||||
|
||||
// docstatus
|
||||
if(data.docstatus==0 || data.docstatus==null) {
|
||||
|
|
@ -463,6 +463,23 @@ wn.views.ListView = Class.extend({
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
prepare_when: function(data, date_str) {
|
||||
if (!date_str) date_str = data.modified;
|
||||
// when
|
||||
data.when = dateutil.str_to_user(date_str).split(' ')[0];
|
||||
var diff = dateutil.get_diff(dateutil.get_today(), date_str.split(' ')[0]);
|
||||
if(diff==0) {
|
||||
data.when = dateutil.comment_when(date_str);
|
||||
}
|
||||
if(diff == 1) {
|
||||
data.when = 'Yesterday'
|
||||
}
|
||||
if(diff == 2) {
|
||||
data.when = '2 days ago'
|
||||
}
|
||||
},
|
||||
|
||||
add_user_tags: function(parent, data) {
|
||||
var me = this;
|
||||
if(data._user_tags) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ wn.views.formview = {
|
|||
}
|
||||
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.views.formview[dt].frm = new _f.Frm(dt, wn.views.formview[dt], true);
|
||||
}
|
||||
wn.container.change_to('Form - ' + dt);
|
||||
wn.views.formview[dt].frm.refresh(dn);
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ wn.views.reportview = {
|
|||
|
||||
_r.rb_con.set_dt(dt, function(rb) {
|
||||
if(rep_name) {
|
||||
var t = rb.current_loaded;
|
||||
var route_changed = (rb.current_route != wn.get_route_str())
|
||||
rb.load_criteria(rep_name);
|
||||
|
||||
// if loaded, then run
|
||||
if((rb.dt) && (!rb.dt.has_data() || rb.current_loaded!=t)) {
|
||||
// if loaded, then run
|
||||
if(rb.dt && route_changed) {
|
||||
rb.dt.run();
|
||||
}
|
||||
}
|
||||
|
|
@ -192,17 +192,21 @@ wn.views.ReportView = wn.ui.Listing.extend({
|
|||
|
||||
get_order_by: function() {
|
||||
// first
|
||||
var order_by = this.get_full_column_name([this.sort_by_select.val()])
|
||||
var order_by = this.get_selected_table_and_column(this.sort_by_select)
|
||||
+ ' ' + this.sort_order_select.val()
|
||||
|
||||
|
||||
// second
|
||||
if(this.sort_by_next_select.val()) {
|
||||
order_by += ', ' + this.get_full_column_name([this.sort_by_next_select.val()])
|
||||
order_by += ', ' + this.get_selected_table_and_column(this.sort_by_next_select)
|
||||
+ ' ' + this.sort_order_next_select.val()
|
||||
}
|
||||
|
||||
return order_by;
|
||||
},
|
||||
get_selected_table_and_column: function($select) {
|
||||
return this.get_full_column_name([$select.val(),
|
||||
$select.find('option:selected').attr('table')])
|
||||
},
|
||||
|
||||
// get table_name.column_name
|
||||
get_full_column_name: function(v) {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class DocType:
|
|||
Clear fields in the doc
|
||||
"""
|
||||
# Clear table before adding new doctype's fields
|
||||
self.doc.clear_table(self.doclist, 'fields')
|
||||
self.doclist = self.doc.clear_table(self.doclist, 'fields')
|
||||
self.set({ 'list': self.doctype_properties, 'value': None })
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2012-04-14 17:04:27',
|
||||
'creation': '2012-05-15 12:14:22',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-04-15 08:53:32',
|
||||
'modified': '2012-07-02 20:14:52',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
'section_style': u'Simple',
|
||||
'server_code_error': u' ',
|
||||
'show_in_menu': 0,
|
||||
'version': 13
|
||||
'version': 1
|
||||
},
|
||||
|
||||
# These values are common for all DocField
|
||||
|
|
@ -45,12 +45,15 @@
|
|||
|
||||
# These values are common for all DocPerm
|
||||
{
|
||||
'amend': 0,
|
||||
'cancel': 0,
|
||||
'doctype': u'DocPerm',
|
||||
'name': '__common__',
|
||||
'parent': u'DocType',
|
||||
'parentfield': u'permissions',
|
||||
'parenttype': u'DocType',
|
||||
'read': 1
|
||||
'read': 1,
|
||||
'submit': 0
|
||||
},
|
||||
|
||||
# DocType, DocType
|
||||
|
|
@ -61,34 +64,30 @@
|
|||
|
||||
# DocPerm
|
||||
{
|
||||
'doctype': u'DocPerm',
|
||||
'permlevel': 0,
|
||||
'role': u'System Manager'
|
||||
},
|
||||
|
||||
# DocPerm
|
||||
{
|
||||
'doctype': u'DocPerm',
|
||||
'permlevel': 0,
|
||||
'role': u'System Manager'
|
||||
},
|
||||
|
||||
# DocPerm
|
||||
{
|
||||
'cancel': 0,
|
||||
'create': 1,
|
||||
'doctype': u'DocPerm',
|
||||
'permlevel': 0,
|
||||
'role': u'Administrator',
|
||||
'submit': 0,
|
||||
'role': u'System Manager',
|
||||
'write': 1
|
||||
},
|
||||
|
||||
# DocPerm
|
||||
{
|
||||
'create': 1,
|
||||
'doctype': u'DocPerm',
|
||||
'execute': 0,
|
||||
'permlevel': 0,
|
||||
'role': u'Administrator',
|
||||
'write': 1
|
||||
},
|
||||
|
||||
# DocPerm
|
||||
{
|
||||
'create': 0,
|
||||
'doctype': u'DocPerm',
|
||||
'permlevel': 1,
|
||||
'role': u'Administrator'
|
||||
'role': u'Administrator',
|
||||
'write': 0
|
||||
},
|
||||
|
||||
# DocField
|
||||
|
|
@ -117,11 +116,11 @@
|
|||
{
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'module',
|
||||
'fieldtype': u'Link',
|
||||
'fieldtype': u'Data',
|
||||
'label': u'Module',
|
||||
'oldfieldname': u'module',
|
||||
'oldfieldtype': u'Link',
|
||||
'options': u'Module Def',
|
||||
'options': u'Suggest',
|
||||
'reqd': 1
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -267,18 +267,15 @@ class DocType:
|
|||
cur_val = '%.2f' % flt(cur_val)
|
||||
|
||||
if cl['op'] == '=' and to_flds[cl['to_fld']]['fieldtype'] in ['Currency', 'Float']:
|
||||
consistent = sql("""\
|
||||
select name, %s from `tab%s`
|
||||
where name = "%s" and "%s" - %s <= 0.5""" \
|
||||
% (cl['from_fld'], t.from_table, child_obj.fields[t.reference_key],
|
||||
flt(cur_val), cl['from_fld']))
|
||||
consistent = sql("""select name, %s from `tab%s` \
|
||||
where name = %s and %s - %s <= 0.5"""% (cl['from_fld'], t.from_table, '%s', '%s', \
|
||||
cl['from_fld']), (child_obj.fields[t.reference_key], flt(cur_val)))
|
||||
else:
|
||||
consistent = sql("""\
|
||||
select name, %s from `tab%s`
|
||||
where name = "%s" and "%s" %s ifnull(%s, '')""" \
|
||||
% (cl['from_fld'], t.from_table, child_obj.fields[t.reference_key], \
|
||||
consistent = sql("""select name, %s from `tab%s` \
|
||||
where name = %s and %s %s ifnull(%s, '')""" % (cl['from_fld'], t.from_table, \
|
||||
'%s', '%s', cl['op'], cl['from_fld']), (child_obj.fields[t.reference_key], \
|
||||
to_flds[cl['to_fld']]['fieldtype'] in ('Currency', 'Float', 'Int') \
|
||||
and flt(cur_val) or cstr(cur_val), cl['op'], cl['from_fld']))
|
||||
and flt(cur_val) or cstr(cur_val)))
|
||||
|
||||
if not self.ref_doc:
|
||||
det = sql("""select name, parent from `tab%s` where name = \"%s\"""" % (t.from_table, child_obj.fields[t.reference_key]))
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@
|
|||
//
|
||||
|
||||
|
||||
$.extend(cur_frm.cscript,{onload:function(doc,dt,dn){cur_frm.cscript.do_setup(doc);},doctype_or_field:function(doc,dt,dn){doc.doc_type=doc.select_item=doc.doc_name=doc.select_doctype='';refresh_many(['doc_type','select_item','doc_name','select_doctype'])},do_setup:function(doc){$c_obj([doc],'get_setup_data','',function(r,rt){var r=r.message;cur_frm.cscript.set_doctypes(r.doctypes);cur_frm.dt_properties={};cur_frm.df_properties={};for(var i=0;i<r.dt_properties.length;i++)
|
||||
$.extend(cur_frm.cscript,{onload:function(doc,dt,dn){cur_frm.cscript.do_setup(doc);},doctype_or_field:function(doc,dt,dn){doc.doc_type=doc.select_item=doc.doc_name=doc.select_doctype='';refresh_many(['doc_type','select_item','doc_name','select_doctype'])},do_setup:function(doc){$c_obj(make_doclist(doc.doctype, doc.name),'get_setup_data','',function(r,rt){var r=r.message;cur_frm.cscript.set_doctypes(r.doctypes);cur_frm.dt_properties={};cur_frm.df_properties={};for(var i=0;i<r.dt_properties.length;i++)
|
||||
cur_frm.dt_properties[r.dt_properties[i].label]=r.dt_properties[i];for(var i=0;i<r.df_properties.length;i++)
|
||||
cur_frm.df_properties[r.df_properties[i].label]=r.df_properties[i];if(doc.property){}});},set_doctypes:function(r){var dtl=[];for(var i=0;i<r.length;i++)
|
||||
dtl.push(get_doctype_label(r[i]))
|
||||
set_field_options('select_doctype','\n'+dtl.sort().join('\n'))},select_doctype:function(doc,dt,dn){doc.doc_type=get_label_doctype(doc.select_doctype);refresh_field('doc_type');if(doc.doctype_or_field=='DocField')
|
||||
cur_frm.cscript.set_field_ids(doc);else{doc.doc_name=get_label_doctype(doc.select_doctype);refresh_field('doc_name');cur_frm.cscript.set_properties('DocType')}},set_field_ids:function(doc){$c_obj([doc],'get_field_ids','',function(r,rt){var fl=[];cur_frm.field_id_list=[];for(var i=0;i<r.message.length;i++){var f=r.message[i];fl.push(i+1+'-'+f.label+' ('+f.fieldtype+')');cur_frm.field_id_list.push(f);}
|
||||
cur_frm.cscript.set_field_ids(doc);else{doc.doc_name=get_label_doctype(doc.select_doctype);refresh_field('doc_name');cur_frm.cscript.set_properties('DocType')}},set_field_ids:function(doc){$c_obj(make_doclist(doc.doctype, doc.name),'get_field_ids','',function(r,rt){var fl=[];cur_frm.field_id_list=[];for(var i=0;i<r.message.length;i++){var f=r.message[i];fl.push(i+1+'-'+f.label+' ('+f.fieldtype+')');cur_frm.field_id_list.push(f);}
|
||||
set_field_options('select_item','\n'+fl.join('\n'))});},select_item:function(doc,dt,dn){doc.doc_name=cur_frm.field_id_list[cint(doc.select_item.split('-')[0])-1].name;refresh_many(['doc_name']);cur_frm.cscript.set_properties('DocField');},set_properties:function(dt_or_df){var d=cur_frm[(dt_or_df=='DocType'?'dt_properties':'df_properties')];set_field_options('select_property','\n'+keys(d).sort().join('\n'));doc.property=doc.property_type=doc.default_value='';refresh_many(['property','property_type','default_value']);cur_frm.cscript.load_defaults();},load_defaults:function(){$c_obj([locals[cur_frm.doctype][cur_frm.docname]],'get_defaults','',function(r,rt){cur_frm.ps_doc=r.message;});},select_property:function(doc,dt,dn){var d=cur_frm[(doc.doctype_or_field=='DocType'?'dt_properties':'df_properties')];doc.property=d[doc.select_property].fieldname;doc.property_type=d[doc.select_property].fieldtype;doc.default_value=cstr(cur_frm.ps_doc[doc.property]);refresh_many(['property','property_type','default_value']);},validate:function(doc){if(doc.property_type=='Check'&&!in_list(['0','1'],doc.value)){msgprint('Value for a check field can be either 0 or 1');validated=false;}}})
|
||||
|
|
@ -32,7 +32,7 @@ $.extend(cur_frm.cscript, {
|
|||
|
||||
// set doctypes with label
|
||||
do_setup: function(doc) {
|
||||
$c_obj([doc], 'get_setup_data', '', function(r,rt) {
|
||||
$c_obj(make_doclist(doc.doctype, doc.name), 'get_setup_data', '', function(r,rt) {
|
||||
var r = r.message;
|
||||
cur_frm.cscript.set_doctypes(r.doctypes);
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ $.extend(cur_frm.cscript, {
|
|||
|
||||
// load fields for this doctype
|
||||
set_field_ids: function(doc) {
|
||||
$c_obj([doc], 'get_field_ids', '', function(r,rt) {
|
||||
$c_obj(make_doclist(doc.doctype, doc.name), 'get_field_ids', '', function(r,rt) {
|
||||
var fl = [];
|
||||
cur_frm.field_id_list = [];
|
||||
for(var i=0; i<r.message.length; i++) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
//
|
||||
|
||||
|
||||
cur_frm.cscript['Server (Python)']=function(doc,dt,dn){$c_obj([doc],'execute_server','',function(r,rt){doc=locals[doc.doctype][doc.name];if(r.exc){doc.response=r.exc;}else{doc.response='Worked!'}
|
||||
cur_frm.cscript['Server (Python)']=function(doc,dt,dn){$c_obj(make_doclist(doc.doctype, doc.name),'execute_server','',function(r,rt){doc=locals[doc.doctype][doc.name];if(r.exc){doc.response=r.exc;}else{doc.response='Worked!'}
|
||||
refresh_field('response');})}
|
||||
cur_frm.cscript['Client (JS)']=function(doc,dt,dn){try{doc.response=eval(doc.script);}catch(e){doc.response=e.toString()
|
||||
+'\nMessage:'+e.message
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
cur_frm.cscript['server_python'] = function(doc, dt, dn) {
|
||||
doc.response = 'Executing...'
|
||||
refresh_field('response');
|
||||
$c_obj([doc], 'execute_server', '', function(r, rt) {
|
||||
$c_obj(make_doclist(doc.doctype, doc.name), 'execute_server', '', function(r, rt) {
|
||||
doc = locals[doc.doctype][doc.name];
|
||||
if(r.exc) {
|
||||
doc.response = r.exc;
|
||||
|
|
|
|||
|
|
@ -153,7 +153,11 @@ def upload():
|
|||
# doctype
|
||||
doctype = rows[0][0].split(':')[1].strip()
|
||||
doctype_dl = webnotes.model.doctype.get(doctype, form=0)
|
||||
|
||||
|
||||
if doctype in ['Customer', 'Supplier'] and len(rows[8:]) > 100:
|
||||
webnotes.msgprint("Please upload only upto 100 %ss at a time" % doctype)
|
||||
raise Exception
|
||||
|
||||
parenttype, parentfield = None, None
|
||||
if len(rows[1]) > 0 and ':' in rows[1][0]:
|
||||
parenttype = rows[1][0].split(':')[1].strip()
|
||||
|
|
@ -177,6 +181,7 @@ def upload():
|
|||
delete_child_rows(rows, doctype)
|
||||
|
||||
for row in rows[8:]:
|
||||
if not row: continue
|
||||
d = dict(zip(columns, row[1:]))
|
||||
d['doctype'] = doctype
|
||||
|
||||
|
|
|
|||
|
|
@ -142,8 +142,8 @@ class Installer:
|
|||
webnotes.conn.sql("""create table __CacheItem(
|
||||
`key` VARCHAR(180) NOT NULL PRIMARY KEY,
|
||||
`value` LONGTEXT,
|
||||
`expires_on` TIMESTAMP
|
||||
)""")
|
||||
`expires_on` DATETIME
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8""")
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -505,13 +505,21 @@ class Document:
|
|||
"""
|
||||
from webnotes.model.utils import getlist
|
||||
|
||||
for d in getlist(doclist, tablefield):
|
||||
d.fields['__oldparent'] = d.parent
|
||||
d.parent = 'old_parent:' + d.parent # for client to send it back while saving
|
||||
d.docstatus = 2
|
||||
if save and not d.fields.get('__islocal'):
|
||||
d.save()
|
||||
self.fields['__unsaved'] = 1
|
||||
table_list = getlist(doclist, tablefield)
|
||||
delete_list = [d.name for d in table_list]
|
||||
|
||||
if delete_list:
|
||||
#filter doclist
|
||||
doclist = filter(lambda d: d.name not in delete_list, doclist)
|
||||
|
||||
# delete from db
|
||||
webnotes.conn.sql("""\
|
||||
delete from `tab%s`
|
||||
where name in ("%s")""" % (table_list[0].doctype, '", "'.join(delete_list)))
|
||||
|
||||
self.fields['__unsaved'] = 1
|
||||
|
||||
return doclist
|
||||
|
||||
def addchild(self, fieldname, childtype = '', local=0, doclist=None):
|
||||
"""
|
||||
|
|
@ -520,9 +528,6 @@ class Document:
|
|||
* if local is set, it does not save the record
|
||||
* if doclist is passed, it append the record to the doclist
|
||||
"""
|
||||
if not childtype:
|
||||
childtype = db_getchildtype(self.doctype, fieldname)
|
||||
|
||||
d = Document()
|
||||
d.parent = self.name
|
||||
d.parenttype = self.doctype
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ class DocList:
|
|||
from webnotes.model.utils import expand
|
||||
self.docs = expand(data)
|
||||
self.objectify(docname)
|
||||
|
||||
def set_doclist(self, docs):
|
||||
self.doclist = docs
|
||||
self.doc, self.children = docs[0], docs[1:]
|
||||
|
||||
def objectify(self, docname=None):
|
||||
"""
|
||||
|
|
@ -86,8 +90,7 @@ class DocList:
|
|||
from webnotes.model.doc import Document
|
||||
|
||||
self.docs = [Document(fielddata=d) for d in self.docs]
|
||||
self.doclist = self.docs
|
||||
self.doc, self.children = self.docs[0], self.docs[1:]
|
||||
self.set_doclist(self.docs)
|
||||
|
||||
def make_obj(self):
|
||||
"""
|
||||
|
|
@ -189,6 +192,8 @@ class DocList:
|
|||
getattr(self.obj, 'custom_' + method)()
|
||||
|
||||
trigger(method, self.doc)
|
||||
|
||||
self.set_doclist([self.obj.doc] + self.obj.doclist)
|
||||
|
||||
def save_main(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -683,3 +683,18 @@ def get_label_doctype(label):
|
|||
WHERE dt_label=%s""", label)
|
||||
|
||||
return res and res[0][0] or label
|
||||
|
||||
|
||||
def get_system_managers_list():
|
||||
"""Returns a list of system managers' email addresses"""
|
||||
system_managers_list = webnotes.conn.sql("""\
|
||||
SELECT DISTINCT p.name
|
||||
FROM tabUserRole ur, tabProfile p
|
||||
WHERE
|
||||
ur.parent = p.name AND
|
||||
ur.role='System Manager' AND
|
||||
p.docstatus<2 AND
|
||||
p.enabled=1 AND
|
||||
p.name not in ('Administrator', 'Guest')""", as_list=1)
|
||||
|
||||
return [sysman[0] for sysman in system_managers_list]
|
||||
|
|
|
|||
|
|
@ -55,15 +55,33 @@ def get(arg=None):
|
|||
data['tables'] = ', '.join(tables)
|
||||
data['conditions'] = ' and '.join(conditions)
|
||||
data['fields'] = ', '.join(fields)
|
||||
|
||||
if not data.get('order_by'):
|
||||
data['order_by'] = tables[0] + '.modified desc'
|
||||
|
||||
if len(tables) > 1:
|
||||
data['group_by'] = "group by " + tables[0] + ".name"
|
||||
else:
|
||||
data['group_by'] = ''
|
||||
|
||||
check_sort_by_table(data.get('order_by'), tables)
|
||||
|
||||
add_limit(data)
|
||||
|
||||
query = """select %(fields)s from %(tables)s where %(conditions)s
|
||||
order by %(order_by)s %(limit)s""" % data
|
||||
%(group_by)s order by %(order_by)s %(limit)s""" % data
|
||||
|
||||
return webnotes.conn.sql(query, as_dict=1)
|
||||
|
||||
def check_sort_by_table(sort_by, tables):
|
||||
"""check atleast 1 column selected from the sort by table """
|
||||
tbl = sort_by.split('.')[0]
|
||||
if tbl not in tables:
|
||||
if tbl.startswith('`'):
|
||||
tbl = tbl[4:-1]
|
||||
webnotes.msgprint("Please select atleast 1 column from '%s' to sort"\
|
||||
% tbl, raise_exception=1)
|
||||
|
||||
def run_custom_query(data):
|
||||
"""run custom query"""
|
||||
query = data['query']
|
||||
|
|
@ -121,7 +139,7 @@ def build_conditions(filters):
|
|||
|
||||
# match conditions
|
||||
build_match_conditions(data, conditions)
|
||||
|
||||
|
||||
return conditions
|
||||
|
||||
def build_filter_conditions(data, filters, conditions):
|
||||
|
|
@ -164,6 +182,8 @@ def get_tables():
|
|||
# add tables from fields
|
||||
for f in json.loads(data['fields']):
|
||||
table_name = f.split('.')[0]
|
||||
if table_name.lower().startswith('group_concat('):
|
||||
table_name = table_name[13:]
|
||||
# check if ifnull function is used
|
||||
if table_name.lower().startswith('ifnull('):
|
||||
table_name = table_name[7:]
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ def savedocs():
|
|||
# send updated docs
|
||||
webnotes.response['saved'] = '1'
|
||||
webnotes.response['main_doc_name'] = doclist.doc.name
|
||||
webnotes.response['doctype'] = doclist.doc.doctype
|
||||
webnotes.response['docname'] = doclist.doc.name
|
||||
webnotes.response['docs'] = [doclist.doc] + doclist.children
|
||||
|
||||
|
|
|
|||
3
wnf.py
3
wnf.py
|
|
@ -55,7 +55,7 @@ def search_replace_with_prompt(fpath, txt1, txt2):
|
|||
tmp = []
|
||||
for c in content:
|
||||
if c.find(txt1) != -1:
|
||||
print '\n', fpath
|
||||
print fpath
|
||||
print colored(txt1, 'red').join(c[:-1].split(txt1))
|
||||
a = ''
|
||||
while a.lower() not in ['y', 'n', 'skip']:
|
||||
|
|
@ -217,6 +217,7 @@ def run():
|
|||
|
||||
# code replace
|
||||
elif options.replace:
|
||||
print options.replace
|
||||
replace_code('.', options.replace[0], options.replace[1], options.replace[2])
|
||||
|
||||
# git
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue