')
.appendTo(this.wrapper);
this.frm.sections.push(this.section);
var section = this.section[0];
section.df = df;
if(df) {
if(df.label) {
this.labelled_section_count++;
$('
")
.css({
"font-weight": "bold",
})
.appendTo(this.section);
if(this.frm.sections.length > 1)
this.section.css({
"margin-top": "15px",
"border-top": "1px solid #ddd"
});
}
if(df.description) {
$('
')
.appendTo(this.section)
.css({"height": "20px"});
}
this.frm.fields_dict[df.fieldname] = section;
this.frm.fields.push(section);
}
// for bc
this.section.body = $('
').appendTo(this.section);
section.row = {
wrapper: section
};
section.refresh = function() {
$(this).toggle(!this.df.hidden)
}
this.column = null;
if(df && df.hidden) {
this.section.toggle(false);
}
return this.section;
},
setup_tabbing: function() {
var me = this;
this.wrapper.on("keydown", function(ev) {
if(ev.which==9) {
var current = $(ev.target).trigger("change"),
doctype = current.attr("data-doctype"),
fieldname = current.attr("data-fieldname");
if(doctype)
return me.handle_tab(doctype, fieldname);
}
})
},
handle_tab: function(doctype, fieldname) {
var me = this,
grid_row = null;
next = null,
fields = me.frm.fields,
in_grid = false;
// in grid
if(doctype != me.frm.doctype) {
grid_row =me.get_open_grid_row()
fields = grid_row.fields;
}
for(var i=0, len=fields.length; i < len; i++) {
if(fields[i].df.fieldname==fieldname) {
if(i==len-1) {
// last field in this group
if(grid_row) {
// in grid
if(grid_row.doc.idx==grid_row.grid.grid_rows.length) {
// last row, close it and find next field
grid_row.toggle_view(false, function() {
me.handle_tab(grid_row.grid.df.parent, grid_row.grid.df.fieldname);
})
} else {
// next row
grid_row.grid.grid_rows[grid_row.doc.idx].toggle_view(true);
}
} else {
// last field - to title buttons
}
} else {
me.focus_on_next_field(i, fields);
}
break;
}
}
return false;
},
focus_on_next_field: function(start_idx, fields) {
// loop to find next eligible fields
for(var ii= start_idx + 1, len = fields.length; ii < len; ii++) {
if(fields[ii].disp_status=="Write") {
var next = fields[ii];
// next is table, show the table
if(next.df.fieldtype=="Table") {
if(!next.grid.grid_rows.length) {
next.grid.add_new_row(1);
} else {
next.grid.grid_rows[0].toggle_view(true);
}
}
else if(next.editor) {
next.editor.set_focus();
}
else if(next.$input) {
next.$input.focus();
}
break;
}
}
},
get_open_grid_row: function() {
return $(".grid-row-open").data("grid_row");
},
// dashboard
clear_dashboard: function() {
this.dashboard.empty();
},
add_doctype_badge: function(doctype, fieldname) {
if(wn.model.can_read(doctype)) {
this.add_badge(wn._(doctype), function() {
wn.route_options = {};
wn.route_options[fieldname] = cur_frm.doc.name;
wn.set_route("List", doctype);
}).attr("data-doctype", doctype);
}
},
add_badge: function(label, onclick) {
var badge = $(repl('
', {label:label}))
.appendTo(this.dashboard)
badge.find(".badge-link").click(onclick);
return badge.find(".alert-badge");
},
set_badge_count: function(data) {
var me = this;
$.each(data, function(doctype, count) {
$(me.dashboard)
.find(".alert-badge[data-doctype='"+doctype+"'] .badge")
.html(cint(count));
});
},
})