[cleanups] to form.js and query_report refreshing

This commit is contained in:
Rushabh Mehta 2017-03-14 16:58:26 +05:30
parent d836d1367f
commit 2ea62c8f79
6 changed files with 35 additions and 28 deletions

View file

@ -59,7 +59,7 @@
max-height: 200px;
border-right: 1px solid #d1d8dd;
}
.grid-static-col.bold {
.editable-form .grid-static-col.bold {
font-weight: bold;
background-color: #fffdf4;
}

View file

@ -59,7 +59,7 @@ frappe.form.formatters = {
if(value) {
return '<i class="octicon octicon-check" style="margin-right: 3px;"></i>';
} else {
return '<i class="fa fa-square-o text-extra-muted" style="margin-right: 3px; margin-bottom: -2px; font-size: 14px;"></i>';
return '<i class="fa fa-square text-extra-muted" style="margin-right: 3px; margin-bottom: -2px;"></i>';
}
},
Link: function(value, docfield, options, doc) {

View file

@ -25,6 +25,7 @@ frappe.standard_pages["query-report"] = function() {
frappe.views.QueryReport = Class.extend({
init: function(opts) {
$.extend(this, opts);
this.flags = {};
// globalify for slickgrid
this.page = this.parent.page;
this.parent.query_report = this;
@ -298,6 +299,10 @@ frappe.views.QueryReport = Class.extend({
// run report on change
f.$input.on("change", function() {
if(!me.flags.filter_set) {
// don't trigger change while setting filters
return;
}
f.$input.blur();
if (f.on_change) {
f.on_change(me);
@ -314,10 +319,11 @@ frappe.views.QueryReport = Class.extend({
$(this.parent).find('.page-form').toggle($filters.length ? true : false);
this.setting_filters = true;
this.set_route_filters()
this.set_route_filters();
this.setting_filters = false;
this.set_filters_by_name();
this.flags.filters_set = true;
},
clear_filters: function() {
this.filters = [];

View file

@ -121,21 +121,6 @@ get_field_obj = function(fn) {
return cur_frm.fields_dict[fn];
}
// set missing values in given doc
set_missing_values = function(doc, dict) {
// dict contains fieldname as key and "default value" as value
var fields_to_set = {};
for (var i in dict) {
var v = dict[i];
if (!doc[i]) {
fields_to_set[i] = v;
}
}
if (fields_to_set) { set_multiple(doc.doctype, doc.name, fields_to_set); }
}
_f.Frm.prototype.get_doc = function() {
return locals[this.doctype][this.docname];
}
@ -204,15 +189,15 @@ _f.Frm.prototype.get_docfield = function(fieldname1, fieldname2) {
_f.Frm.prototype.set_df_property = function(fieldname, property, value, docname, table_field) {
if (!docname && !table_field){
var field = this.get_docfield(fieldname);
var df = this.get_docfield(fieldname);
} else {
var grid = cur_frm.fields_dict[table_field].grid,
fname = frappe.utils.filter_dict(grid.docfields, {'fieldname': fieldname});
if (fname && fname.length)
var field = frappe.meta.get_docfield(fname[0].parent, fieldname, docname);
var df = frappe.meta.get_docfield(fname[0].parent, fieldname, docname);
}
if(field) {
field[property] = value;
if(df && df[property] != value) {
df[property] = value;
refresh_field(fieldname, table_field);
};
}
@ -500,3 +485,13 @@ _f.Frm.prototype.make_new = function(doctype) {
});
}
}
_f.Frm.prototype.update_in_all_rows = function(table_fieldname, fieldname, value) {
// update the child value in all tables where it is missing
if(!value) return;
var cl = doc[table_fieldname] || [];
for(var i = 0; i < cl.length; i++){
if(!cl[i][fieldname]) cl[i][fieldname] = value;
}
refresh_field("items");
}

View file

@ -85,6 +85,7 @@ _f.Frm.prototype.setup = function() {
// wrapper
this.wrapper = this.parent;
this.$wrapper = $(this.wrapper);
frappe.ui.make_app_page({
parent: this.wrapper,
single_column: this.meta.hide_toolbar
@ -124,7 +125,7 @@ _f.Frm.prototype.setup = function() {
_f.Frm.prototype.setup_drag_drop = function() {
var me = this;
$(this.wrapper).on('dragenter dragover', false)
this.$wrapper.on('dragenter dragover', false)
.on('drop', function (e) {
var dataTransfer = e.originalEvent.dataTransfer;
if (!(dataTransfer && dataTransfer.files && dataTransfer.files.length > 0)) {
@ -457,7 +458,6 @@ _f.Frm.prototype.refresh = function(docname) {
}
if(is_a_different_doc) {
$(this.wrapper).removeClass('validated-form')
if(this.show_print_first && this.doc.docstatus===1) {
// show print view
this.print_doc();
@ -472,6 +472,12 @@ _f.Frm.prototype.refresh = function(docname) {
}
}
// set status classes
this.$wrapper.removeClass('validated-form')
.toggleClass('editable-form', this.doc.docstatus===0)
.toggleClass('submitted-form', this.doc.docstatus===1)
.toggleClass('cancelled-form', this.doc.docstatus===2);
this.show_if_needs_refresh();
}
}
@ -537,7 +543,7 @@ _f.Frm.prototype.render_form = function(is_a_different_doc) {
this.refresh_header(is_a_different_doc);
}
$(this.wrapper).trigger('render_complete');
this.$wrapper.trigger('render_complete');
if(!this.hidden) {
this.layout.show_empty_form_message();
@ -555,7 +561,7 @@ _f.Frm.prototype.refresh_field = function(fname) {
_f.Frm.prototype.refresh_fields = function() {
this.layout.refresh(this.doc);
this.layout.primary_button = $(this.wrapper).find(".btn-primary");
this.layout.primary_button = this.$wrapper.find(".btn-primary");
// cleanup activities after refresh
this.cleanup_refresh(this);
@ -842,7 +848,7 @@ _f.Frm.prototype.save_or_update = function() {
_f.Frm.prototype.dirty = function() {
this.doc.__unsaved = 1;
$(this.wrapper).trigger('dirty');
this.$wrapper.trigger('dirty');
}
_f.Frm.prototype.get_docinfo = function() {

View file

@ -75,7 +75,7 @@
border-right: 1px solid @border-color;
}
.grid-static-col.bold {
.editable-form .grid-static-col.bold {
font-weight: bold;
background-color: @extra-light-yellow;
}