瀏覽代碼

[fix] grid sorting

version-14
Rushabh Mehta 9 年之前
父節點
當前提交
ac6053b47f
共有 3 個檔案被更改,包括 47 行新增25 行删除
  1. +4
    -1
      frappe/desk/doctype/todo/todo.json
  2. +7
    -6
      frappe/public/js/frappe/form/control.js
  3. +36
    -18
      frappe/public/js/frappe/form/grid.js

+ 4
- 1
frappe/desk/doctype/todo/todo.json 查看文件

@@ -3,6 +3,7 @@
"allow_import": 0,
"allow_rename": 0,
"autoname": "hash",
"beta": 0,
"creation": "2012-07-03 13:30:35",
"custom": 0,
"docstatus": 0,
@@ -397,13 +398,14 @@
"hide_toolbar": 0,
"icon": "icon-check",
"idx": 2,
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-04-12 02:50:32.042427",
"modified": "2016-06-15 13:11:14.435351",
"modified_by": "Administrator",
"module": "Desk",
"name": "ToDo",
@@ -450,6 +452,7 @@
"write": 1
}
],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"search_fields": "description, reference_type, reference_name",


+ 7
- 6
frappe/public/js/frappe/form/control.js 查看文件

@@ -267,6 +267,13 @@ frappe.ui.form.ControlInput = frappe.ui.form.Control.extend({
}

this.$wrapper.on("refresh", function() {
if(me.only_input) {
// show disabled input if only_input is true
// since there is no disp_area
make_input();
update_input();
}

if(me.disp_status != "None") {
// refresh value
if(me.doctype && me.docname) {
@@ -280,12 +287,6 @@ frappe.ui.form.ControlInput = frappe.ui.form.Control.extend({
make_input();
update_input();
} else {
if(me.only_input) {
// show disabled input if only_input is true
// since there is no disp_area
make_input();
update_input();
}
$(me.input_area).toggle(me.only_input ? true : false);
$(me.input_area).find("input").prop("disabled", true);
if (me.disp_area) {


+ 36
- 18
frappe/public/js/frappe/form/grid.js 查看文件

@@ -107,7 +107,8 @@ frappe.ui.form.Grid = Class.extend({
this.truncate_rows(data);
this.grid_rows_by_docname = {};

for(var ri in data) {

for(var ri=0;ri < data.length; ri++) {
var d = data[ri];

if(this.grid_rows[ri]) {
@@ -123,7 +124,7 @@ frappe.ui.form.Grid = Class.extend({
frm: this.frm,
grid: this
});
this.grid_rows.push(grid_row)
this.grid_rows.push(grid_row);
}

this.grid_rows_by_docname[d.name] = grid_row;
@@ -205,7 +206,7 @@ frappe.ui.form.Grid = Class.extend({
&& this.display_status==this.last_display_status
&& this.frm.docname==this.last_docname
&& !$.map(this.grid_rows, function(g, i) {
return (g.doc && g.doc.name==data[i].name) ? null : true;
return (g && g.doc && g.doc.name==data[i].name) ? null : true;
}).length;

return same;
@@ -222,9 +223,8 @@ frappe.ui.form.Grid = Class.extend({
onUpdate: function(event, ui) {
me.frm.doc[me.df.fieldname] = [];
$rows.find(".grid-row").each(function(i, item) {
var doc = $(item).data("doc");
var doc = locals[me.doctype][$(item).attr('data-name')];
doc.idx = i + 1;
$(this).find(".row-index").html(i + 1);
me.frm.doc[me.df.fieldname].push(doc);
});

@@ -271,6 +271,9 @@ frappe.ui.form.Grid = Class.extend({
get_docfield: function(fieldname) {
return frappe.meta.get_docfield(this.doctype, fieldname, this.frm ? this.frm.docname : null);
},
get_grid_row: function(docname) {
return this.grid_rows_by_docname[docname];
},
get_field: function(fieldname) {
// Note: workaround for get_query
if(!this.fieldinfo[fieldname])
@@ -306,7 +309,8 @@ frappe.ui.form.Grid = Class.extend({
set_focus_on_new_row: function() {
var me = this;
setTimeout(function() {
me.grid_rows[me.grid_rows.length - 1].row.find('input:first').focus();
me.grid_rows[me.grid_rows.length - 1].row
.find('input,textarea,select').filter(':visible:first').focus();
});
},

@@ -546,7 +550,6 @@ frappe.ui.form.GridRow = Class.extend({
}
});

this.set_row_index();
this.render_row();
if(this.doc) {
this.set_data();
@@ -555,8 +558,10 @@ frappe.ui.form.GridRow = Class.extend({
set_row_index: function() {
if(this.doc) {
this.wrapper
.attr('data-name', this.doc.name)
.attr("data-idx", this.doc.idx)
.find(".row-index, .grid-form-row-index").html(this.doc.idx)

}
},
remove: function() {
@@ -597,6 +602,7 @@ frappe.ui.form.GridRow = Class.extend({
},
render_row: function(refresh) {
var me = this;
this.set_row_index();

// index (1, 2, 3 etc)
if(!this.row_index) {
@@ -621,8 +627,9 @@ frappe.ui.form.GridRow = Class.extend({
}
}


$(this.frm.wrapper).trigger("grid-row-render", [this]);
if(this.doc) {
$(this.frm.wrapper).trigger("grid-row-render", [this]);
}
},

setup_columns: function() {
@@ -914,16 +921,27 @@ frappe.ui.form.GridRow = Class.extend({
});
return visible_columns;
},
set_field_property: function(fieldname, property, value) {
// set a field property for open form / grid form
var me = this;

var set_property = function(field) {
if(!field) return;
field.df[property] = value;
field.refresh();
me.layout && me.layout.refresh_sections();
}

set_property(this.fields_dict[fieldname]);
set_property(this.on_grid_fields_dict[fieldname]);
},
toggle_reqd: function(fieldname, reqd) {
var field = this.fields_dict[fieldname];
field.df.reqd = reqd ? 1 : 0;
field.refresh();
this.layout.refresh_sections();
this.set_field_property(fieldname, 'reqd', reqd ? 1 : 0);
},
toggle_display: function(fieldname, show) {
var field = this.fields_dict[fieldname];
field.df.hidden = show ? 0 : 1;
field.refresh();
this.layout.refresh_sections();
}
this.set_field_property(fieldname, 'hidden', show ? 0 : 1);
},
toggle_editable: function(fieldname, editable) {
this.set_field_property(fieldname, 'read_only', editable ? 0 : 1);
},
});

Loading…
取消
儲存