[form] [ui] added footer, attachments and started comments
This commit is contained in:
parent
e19d69ffde
commit
fe0c95124e
10 changed files with 45 additions and 841 deletions
|
|
@ -149,7 +149,6 @@
|
|||
"lib/public/js/legacy/widgets/form/form_fields.js",
|
||||
"lib/public/js/legacy/widgets/form/print_format.js",
|
||||
"lib/public/js/legacy/widgets/form/clientscriptAPI.js",
|
||||
"lib/public/js/legacy/widgets/form/form_comments.js",
|
||||
"lib/public/js/legacy/wn/widgets/form/sidebar.js",
|
||||
"lib/public/js/legacy/wn/widgets/form/comments.js",
|
||||
|
||||
|
|
@ -158,6 +157,8 @@
|
|||
"lib/public/js/wn/form/editors.js",
|
||||
"lib/public/js/wn/form/grid.js",
|
||||
"lib/public/js/wn/form/attachments.js",
|
||||
"lib/public/js/wn/form/footer.js",
|
||||
"lib/public/js/wn/form/comments.js",
|
||||
"lib/public/js/wn/form/linked_with.js",
|
||||
"lib/public/js/wn/form/states.js",
|
||||
"lib/public/js/wn/form/assign_to.js",
|
||||
|
|
|
|||
|
|
@ -152,19 +152,31 @@ a {
|
|||
outline: none;
|
||||
}
|
||||
|
||||
/* form grid */
|
||||
|
||||
.rows .grid-row .divider {
|
||||
padding-bottom: 8px;
|
||||
margin-bottom: 8px;
|
||||
border-bottom: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
/*.rows .grid-row:last-child .divider {
|
||||
border-bottom: 0px;
|
||||
margin-bottom: 0px;
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
*/
|
||||
.rows .grid-row .data-row, .rows .grid-row .panel-heading {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* form footer */
|
||||
|
||||
.form-footer {
|
||||
background-color: #f2f2f2;
|
||||
margin-top: 15px;
|
||||
padding-top: 15px;
|
||||
padding-bottom: 15px;
|
||||
border-top: 1px dashed #ddd;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.form-attachments {
|
||||
border: 1px dashed #ddd;
|
||||
padding: 15px;
|
||||
padding-top: 0px;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 207 B |
|
|
@ -30,10 +30,10 @@
|
|||
+ this.head
|
||||
+ this.body
|
||||
+ this.layout
|
||||
+ this.footer
|
||||
+ this.sidebar
|
||||
+ this.print_wrapper
|
||||
+ this.head
|
||||
+ this.footer
|
||||
*/
|
||||
|
||||
wn.provide('_f');
|
||||
|
|
@ -127,6 +127,11 @@ _f.Frm.prototype.setup = function() {
|
|||
|
||||
this.setup_header();
|
||||
|
||||
this.footer = new wn.ui.form.Footer({
|
||||
frm: this,
|
||||
parent: this.layout_main
|
||||
})
|
||||
|
||||
this.setup_done = true;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +141,7 @@ _f.Frm.prototype.setup_print_layout = function() {
|
|||
this.print_wrapper = $('<div>\
|
||||
<form class="form-inline">\
|
||||
<select class="col-span-2 preview-select"></select> \
|
||||
<button class="btn btn-edit"><i class="icon-edit"></i> Edit</button>\
|
||||
<button class="btn btn-edit btn-info"><i class="icon-edit"></i> Edit</button>\
|
||||
</form>\
|
||||
<hr>\
|
||||
<div class="print-format-area clear-fix" style="min-height: 400px;"></div>\
|
||||
|
|
@ -172,7 +177,6 @@ _f.Frm.prototype.setup_std_layout = function() {
|
|||
this.main = this.form_wrapper;
|
||||
this.body_header = $a(this.main, 'div');
|
||||
this.body = $a(this.main, 'div');
|
||||
this.footer = $a(this.main, 'div');
|
||||
|
||||
if(this.heading) {
|
||||
this.page_head = new PageHeader(this.head, this);
|
||||
|
|
@ -192,9 +196,6 @@ _f.Frm.prototype.setup_std_layout = function() {
|
|||
this.states = new wn.ui.form.States({
|
||||
frm: this
|
||||
});
|
||||
|
||||
// footer
|
||||
this.setup_footer();
|
||||
}
|
||||
|
||||
_f.Frm.prototype.setup_header = function() {
|
||||
|
|
@ -283,28 +284,6 @@ _f.Frm.prototype.setup_meta = function(doctype) {
|
|||
this.setup_print();
|
||||
}
|
||||
|
||||
_f.Frm.prototype.setup_footer = function() {
|
||||
var me = this;
|
||||
|
||||
// footer toolbar
|
||||
var f = this.footer;
|
||||
|
||||
// save buttom
|
||||
f.save_area = $a(this.footer,'div','',{display:'none', marginTop:'11px'});
|
||||
f.help_area = $a(this.footer,'div');
|
||||
|
||||
var b = $("<button class='btn btn-info'><i class='icon-save'></i> Save</button>")
|
||||
.click(function() { me.save("Save", null, me); }).appendTo(f.save_area);
|
||||
|
||||
// show / hide save
|
||||
f.show_save = function() {
|
||||
$ds(me.footer.save_area);
|
||||
}
|
||||
|
||||
f.hide_save = function() {
|
||||
$dh(me.footer.save_area);
|
||||
}
|
||||
}
|
||||
|
||||
_f.Frm.prototype.set_intro = function(txt) {
|
||||
wn.utils.set_intro(this, this.body, txt);
|
||||
|
|
@ -493,9 +472,6 @@ _f.Frm.prototype.refresh = function(docname) {
|
|||
|
||||
// dependent fields
|
||||
this.refresh_dependency();
|
||||
|
||||
// footer
|
||||
this.refresh_footer();
|
||||
|
||||
// call onload post render for callbacks to be fired
|
||||
if(this.cscript.is_onload) {
|
||||
|
|
@ -523,20 +499,6 @@ _f.Frm.prototype.refresh = function(docname) {
|
|||
}
|
||||
}
|
||||
|
||||
_f.Frm.prototype.refresh_footer = function() {
|
||||
var f = this.footer;
|
||||
if(f.save_area) {
|
||||
// if save button is there in the header
|
||||
if(this.frm_head && this.appframe.toolbar
|
||||
&& this.appframe.buttons.Save && !this.save_disabled
|
||||
&& (this.fields && this.fields.length > 7)) {
|
||||
f.show_save();
|
||||
} else {
|
||||
f.hide_save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_f.Frm.prototype.refresh_field = function(fname) {
|
||||
cur_frm.fields_dict[fname] && cur_frm.fields_dict[fname].refresh
|
||||
&& cur_frm.fields_dict[fname].refresh();
|
||||
|
|
|
|||
|
|
@ -1,293 +0,0 @@
|
|||
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
|
||||
//
|
||||
// MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
_f.FormGrid = function(field) {
|
||||
this.field = field;
|
||||
this.doctype = field.df.options;
|
||||
|
||||
if(!this.doctype) {
|
||||
show_alert('No Options for table ' + field.df.label);
|
||||
}
|
||||
|
||||
this.col_break_width = cint(this.field.col_break_width);
|
||||
if(!this.col_break_width) this.col_break_width = 100;
|
||||
|
||||
$y(field.wrapper,{marginTop:'8px'});
|
||||
this.init(field.wrapper, field.df.width);
|
||||
this.setup();
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype = new _f.Grid();
|
||||
|
||||
_f.FormGrid.prototype.setup = function() {
|
||||
this.make_columns();
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.make_buttons = function() {
|
||||
var me = this;
|
||||
this.tbar_btns = {};
|
||||
this.tbar_btns['Del'] = this.make_tbar_link($td(this.tbar_tab,0,0),wn._('Del'),
|
||||
function() { me.delete_row(); }, 'icon-remove-sign');
|
||||
this.tbar_btns['Ins'] = this.make_tbar_link($td(this.tbar_tab,0,1),wn._('Ins'),
|
||||
function() { me.insert_row(); }, 'icon-plus');
|
||||
this.tbar_btns['Up'] = this.make_tbar_link($td(this.tbar_tab,0,2),wn._('Up'),
|
||||
function() { me.move_row(true); }, 'icon-arrow-up');
|
||||
this.tbar_btns['Dn'] = this.make_tbar_link($td(this.tbar_tab,0,3),wn._('Dn'),
|
||||
function() { me.move_row(false); }, 'icon-arrow-down');
|
||||
|
||||
for(var i in this.btns)
|
||||
this.btns[i].isactive = true;
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.make_tbar_link = function(parent, label, fn, icon) {
|
||||
|
||||
var div = $a(parent,'div','',{cursor:'pointer'});
|
||||
var t = make_table(div, 1, 2, '90%', ['20px',null]);
|
||||
var img = $a($td(t,0,0), 'i' , icon);
|
||||
|
||||
$y($td(t,0,0),{textAlign:'right'});
|
||||
|
||||
var l = $a($td(t,0,1),'span','link_type',{color:'#333'});
|
||||
l.style.fontSize = '11px';
|
||||
l.innerHTML = label;
|
||||
div.onclick = fn;
|
||||
div.show = function() { $ds(this); }
|
||||
div.hide = function() { $dh(this); }
|
||||
|
||||
$td(t,0,0).isactive = 1;
|
||||
$td(t,0,1).isactive = 1;
|
||||
l.isactive = 1;
|
||||
div.isactive = 1;
|
||||
img.isactive = 1;
|
||||
|
||||
return div;
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.make_columns = function() {
|
||||
var p = this.field.perm;
|
||||
if(p[this.field.df.permlevel] && p[this.field.df.permlevel][READ]) { // if read
|
||||
var gl = wn.meta.docfield_list[this.field.df.options];
|
||||
|
||||
if(!gl) {
|
||||
alert('Table details not found "'+this.field.df.options+'"');
|
||||
}
|
||||
|
||||
gl.sort(function(a,b) { return a.idx - b.idx});
|
||||
|
||||
for(var i=0;i<gl.length;i++) {
|
||||
this.insert_column(this.field.df.options, gl[i].fieldname, gl[i].fieldtype, gl[i].label, gl[i].width, gl[i].options, this.field.perm, gl[i].reqd, gl[i]);
|
||||
|
||||
// hide it even if it is hidden at start..
|
||||
// so that it can be brought back once
|
||||
// also, hide column if no permissions found
|
||||
if(gl[i].hidden || !(p[gl[i].permlevel] && p[gl[i].permlevel][READ])) {
|
||||
this.set_column_disp(gl[i].fieldname, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.set_column_label = function(fieldname, label) {
|
||||
for(var i=0;i<this.head_row.cells.length;i++) {
|
||||
var c = this.head_row.cells[i];
|
||||
if(c.fieldname == fieldname) {
|
||||
c.innerHTML = '<div class="grid_head_div">'+label+'</div>';
|
||||
c.cur_label = label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.get_children = function() {
|
||||
return getchildren(this.doctype, this.field.frm.docname, this.field.df.fieldname, this.field.frm.doctype);
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.refresh = function() {
|
||||
var docset = this.get_children();
|
||||
var data = [];
|
||||
|
||||
//alert(docset.length);
|
||||
for(var i=0; i<docset.length; i++) {
|
||||
locals[this.doctype][docset[i].name].idx = i+1;
|
||||
data[data.length] = docset[i].name;
|
||||
}
|
||||
this.set_data(data);
|
||||
|
||||
// if form open, refresh form
|
||||
if(_f.frm_dialog && _f.frm_dialog.dialog.display && _f.frm_dialog.cur_frm) {
|
||||
_f.frm_dialog.cur_frm.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.set_unsaved = function() {
|
||||
// set unsaved
|
||||
cur_frm.dirty();
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.insert_row = function() {
|
||||
var d = this.new_row_doc();
|
||||
var ci = _f.cur_grid_cell.cellIndex;
|
||||
var row_idx = _f.cur_grid_cell.row.rowIndex;
|
||||
d.idx = row_idx+1;
|
||||
for(var ri = row_idx; ri<this.tab.rows.length; ri++) {
|
||||
var r = this.tab.rows[ri];
|
||||
if(r.docname)
|
||||
locals[this.doctype][r.docname].idx++;
|
||||
}
|
||||
// refresh
|
||||
this.refresh();
|
||||
this.cell_select('', row_idx, ci);
|
||||
|
||||
if(this.onrowadd) this.onrowadd(cur_frm.doc, d.doctype, d.name);
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.new_row_doc = function() {
|
||||
// create row doc
|
||||
var n = wn.model.make_new_doc_and_get_name(this.doctype);
|
||||
var d = locals[this.doctype][n];
|
||||
d.parent = this.field.frm.docname;
|
||||
d.parentfield = this.field.df.fieldname;
|
||||
d.parenttype = this.field.frm.doctype;
|
||||
this.set_unsaved();
|
||||
return d;
|
||||
}
|
||||
_f.FormGrid.prototype.add_newrow = function() {
|
||||
var r = this.tab.rows[this.tab.rows.length - 1];
|
||||
if(!r.is_newrow)
|
||||
throw 'Adding a row which is not flagged as new';
|
||||
|
||||
var d = this.new_row_doc();
|
||||
d.idx = r.rowIndex + 1;
|
||||
|
||||
// set row
|
||||
r.docname = d.name;
|
||||
//r.cells[0].div.innerHTML = r.rowIndex + 1;
|
||||
r.is_newrow = false;
|
||||
this.set_cell_value(r.cells[0]);
|
||||
|
||||
// one more
|
||||
this.make_newrow();
|
||||
this.refresh_row(r.rowIndex, d.name); // added 26-Mar-09
|
||||
|
||||
if(this.onrowadd) this.onrowadd(cur_frm.doc, d.doctype, d.name);
|
||||
|
||||
return d.name;
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.make_newrow = function(from_add_btn) {
|
||||
if(!this.can_add_rows) // No Addition
|
||||
return;
|
||||
|
||||
// check if exists
|
||||
if(this.tab.rows.length) {
|
||||
var r = this.tab.rows[this.tab.rows.length - 1];
|
||||
if(r.is_newrow)
|
||||
return;
|
||||
}
|
||||
|
||||
// make new
|
||||
var r = this.append_row();
|
||||
r.cells[0].div.innerHTML = '<b style="font-size: 18px;">*</b>';
|
||||
r.is_newrow = true;
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.check_selected = function() {
|
||||
if(!_f.cur_grid_cell) {
|
||||
show_alert(wn._('Select a cell first'));
|
||||
return false;
|
||||
}
|
||||
if(_f.cur_grid_cell.grid != this) {
|
||||
show_alert(wn._('Select a cell first'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.delete_row = function(dt, dn) {
|
||||
if(dt && dn) {
|
||||
wn.model.clear_doc(dt, dn);
|
||||
this.refresh();
|
||||
} else {
|
||||
if(!this.check_selected()) return;
|
||||
var r = _f.cur_grid_cell.row;
|
||||
if(r.is_newrow)return;
|
||||
|
||||
var ci = _f.cur_grid_cell.cellIndex;
|
||||
var ri = _f.cur_grid_cell.row.rowIndex;
|
||||
|
||||
wn.model.clear_doc(this.doctype, r.docname);
|
||||
|
||||
this.refresh();
|
||||
if(ri < (this.tab.rows.length-1))
|
||||
this.cell_select(null, ri, ci);
|
||||
else _f.cur_grid_cell = null;
|
||||
}
|
||||
this.set_unsaved();
|
||||
|
||||
if(this.on_row_delete) this.on_row_delete(cur_frm.doc, dt, dn);
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.clear_table = function() {
|
||||
var me = this;
|
||||
$.each(this.get_children(), function(i, d) {
|
||||
wn.model.clear_doc(d.doctype, d.name);
|
||||
if(me.on_row_delete) me.on_row_delete(cur_frm.doc, d.doctype, d.name);
|
||||
});
|
||||
this.refresh();
|
||||
this.set_unsaved();
|
||||
}
|
||||
|
||||
_f.FormGrid.prototype.move_row = function(up) {
|
||||
|
||||
if(!this.check_selected()) return;
|
||||
var r = _f.cur_grid_cell.row;
|
||||
if(r.is_newrow)return;
|
||||
|
||||
if(up && r.rowIndex > 0) {
|
||||
var swap_row = this.tab.rows[r.rowIndex - 1];
|
||||
} else if (!up) {
|
||||
var len = this.tab.rows.length;
|
||||
if(this.tab.rows[len-1].is_newrow)
|
||||
len = len - 1;
|
||||
if(r.rowIndex < (len-1))
|
||||
var swap_row = this.tab.rows[r.rowIndex + 1];
|
||||
}
|
||||
|
||||
if(swap_row) {
|
||||
var cidx = _f.cur_grid_cell.cellIndex;
|
||||
this.cell_deselect();
|
||||
|
||||
// swap index
|
||||
var aidx = locals[this.doctype][r.docname].idx;
|
||||
locals[this.doctype][r.docname].idx = locals[this.doctype][swap_row.docname].idx;
|
||||
locals[this.doctype][swap_row.docname].idx = aidx;
|
||||
|
||||
// swap rows
|
||||
var adocname = swap_row.docname;
|
||||
this.refresh_row(swap_row.rowIndex, r.docname);
|
||||
this.refresh_row(r.rowIndex, adocname);
|
||||
|
||||
this.cell_select(this.tab.rows[swap_row.rowIndex].cells[cidx]);
|
||||
|
||||
this.set_unsaved();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,492 +0,0 @@
|
|||
// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
|
||||
//
|
||||
// MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
// _f.Grid
|
||||
|
||||
_f.cur_grid_cell = null;
|
||||
_f.Grid = function(parent) { }
|
||||
|
||||
_f.Grid.prototype.init = function(parent, row_height) {
|
||||
|
||||
var me = this;
|
||||
this.col_idx_by_name = {}
|
||||
this.alt_row_bg = '#F2F2FF';
|
||||
this.row_height = row_height;
|
||||
|
||||
// make the grid
|
||||
if(!row_height)this.row_height = '26px';
|
||||
this.make_ui(parent);
|
||||
|
||||
// Sr No
|
||||
this.insert_column('', '', 'Int', 'Sr', '50px', '', [1,0,0]);
|
||||
|
||||
if(this.oninit)this.oninit();
|
||||
|
||||
// bind clicks
|
||||
$(this.wrapper).bind('keydown', function(e) {
|
||||
me.notify_keypress(e, e.which);
|
||||
})
|
||||
|
||||
// reset grid heights after complete is triggerd on the form
|
||||
$(cur_frm.wrapper).bind('render_complete', function() {
|
||||
me.set_ht();
|
||||
});
|
||||
}
|
||||
|
||||
_f.Grid.prototype.make_ui = function(parent) {
|
||||
|
||||
var ht = make_table($a(parent, 'div'), 1, 2, '100%', ['55%','45%']);
|
||||
this.main_title = $td(ht,0,0); this.main_title.className = 'columnHeading';
|
||||
$td(ht,0,1).style.textAlign = 'right';
|
||||
this.tbar_div = $a($td(ht,0,1), 'div', 'grid_tbarlinks');
|
||||
this.tbar_tab = make_table(this.tbar_div,1,4,'100%',['25%','25%','25%','25%']);
|
||||
|
||||
this.wrapper = $a(parent, 'div', 'grid_wrapper round');
|
||||
|
||||
this.head_wrapper = $a(this.wrapper, 'div', 'grid_head_wrapper');
|
||||
|
||||
this.head_tab = $a(this.head_wrapper, 'table', 'grid_head_table');
|
||||
this.head_row = this.head_tab.insertRow(0);
|
||||
|
||||
this.tab_wrapper = $a(this.wrapper, 'div', 'grid_tab_wrapper');
|
||||
this.tab = $a(this.tab_wrapper, 'table', 'grid_table');
|
||||
|
||||
var me = this;
|
||||
|
||||
this.wrapper.onscroll = function() { me.head_wrapper.style.top = me.wrapper.scrollTop+'px'; }
|
||||
}
|
||||
|
||||
_f.Grid.prototype.show = function() {
|
||||
if(this.can_edit && this.field.df['default'].toLowerCase()!='no toolbar') {
|
||||
$ds(this.tbar_div);
|
||||
if(this.can_add_rows) {
|
||||
$td(this.tbar_tab, 0, 0).style.display = 'table-cell';
|
||||
$td(this.tbar_tab, 0, 1).style.display = 'table-cell';
|
||||
} else {
|
||||
$td(this.tbar_tab, 0, 0).style.display = 'none';
|
||||
$td(this.tbar_tab, 0, 1).style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
$dh(this.tbar_div);
|
||||
}
|
||||
$ds(this.wrapper);
|
||||
}
|
||||
_f.Grid.prototype.hide = function() {
|
||||
$dh(this.wrapper); $dh(this.tbar_div);
|
||||
}
|
||||
|
||||
_f.Grid.prototype.insert_column = function(doctype, fieldname, fieldtype, label, width, options, perm, reqd, df) {
|
||||
|
||||
var idx = this.head_row.cells.length;
|
||||
if(!width)width = '100px';
|
||||
if(fieldtype=="Currency" && cint(width) < 100) width = "100px";
|
||||
if(fieldtype=="Link" && cint(width) < 150) width = "150px";
|
||||
width= cint(width) + 'px';
|
||||
|
||||
var col = this.head_row.insertCell(idx);
|
||||
|
||||
col.df = df;
|
||||
col.doctype = doctype; // for report (fields may be from diff doctypes)
|
||||
col.fieldname = fieldname;
|
||||
col.fieldtype = fieldtype;
|
||||
$(col).attr("data-grid-fieldname", doctype + "-" + fieldname);
|
||||
col.innerHTML = wn._(label);
|
||||
col.title = label;
|
||||
col.label = label;
|
||||
if(reqd)
|
||||
col.style.color = "#D22";
|
||||
|
||||
col.style.width = width;
|
||||
col.options = options;
|
||||
col.perm = perm;
|
||||
|
||||
this.col_idx_by_name[fieldname] = idx;
|
||||
}
|
||||
|
||||
_f.Grid.prototype.reset_table_width = function() {
|
||||
var w = 0;
|
||||
$.each(this.head_row.cells, function(i, cell) {
|
||||
if((cell.style.display || '').toLowerCase()!='none')
|
||||
w += cint(cell.style.width);
|
||||
})
|
||||
|
||||
this.head_tab.style.width = w + 'px';
|
||||
this.tab.style.width = w + 'px';
|
||||
}
|
||||
|
||||
_f.Grid.prototype.set_column_disp = function(fieldname, show) {
|
||||
var cidx = this.col_idx_by_name[fieldname];
|
||||
if(!cidx) {
|
||||
msgprint('Trying to hide unknown column: ' + fieldname);
|
||||
return;
|
||||
}
|
||||
|
||||
var disp = show ? 'table-cell' : 'none';
|
||||
|
||||
// head
|
||||
this.head_row.cells[cidx].style.display = disp;
|
||||
|
||||
// body
|
||||
for(var i=0, len=this.tab.rows.length; i<len; i++) {
|
||||
var cell = this.tab.rows[i].cells[cidx];
|
||||
cell.style.display = disp;
|
||||
}
|
||||
|
||||
// reset table width
|
||||
this.reset_table_width();
|
||||
}
|
||||
|
||||
_f.Grid.prototype.toggle_reqd = function(fieldname, reqd) {
|
||||
// IMPORTANT: this should be called in refresh event
|
||||
var grid_field = this.get_field(fieldname);
|
||||
grid_field.df.reqd = reqd ? true : false;
|
||||
grid_field.refresh();
|
||||
$(grid_field.grid.head_row).find('[data-grid-fieldname="' + grid_field.grid.doctype
|
||||
+ '-' + fieldname + '"]').css({ color: reqd ? "#D22" : "black" });
|
||||
}
|
||||
|
||||
_f.Grid.prototype.append_row = function(idx, docname) {
|
||||
if(!idx)idx = this.tab.rows.length;
|
||||
var row = this.tab.insertRow(idx);
|
||||
row.docname = docname;
|
||||
|
||||
if(idx % 2)var odd=true; else var odd=false;
|
||||
|
||||
var me = this;
|
||||
// make cells
|
||||
for(var i=0; i<this.head_row.cells.length; i++){
|
||||
var cell = row.insertCell(i);
|
||||
var hc = this.head_row.cells[i];
|
||||
|
||||
// ape style of head
|
||||
cell.style.width = hc.style.width;
|
||||
cell.style.display = hc.style.display;
|
||||
|
||||
cell.row = row;
|
||||
cell.grid = this;
|
||||
cell.className = 'grid_cell';
|
||||
|
||||
cell.div = $a(cell, 'div', 'grid_cell_div');
|
||||
if(this.row_height) {
|
||||
cell.div.style.height = this.row_height; }
|
||||
cell.div.cell = cell;
|
||||
$(cell.div).click(function(e) {
|
||||
me.cell_select(this.cell);
|
||||
// cell selected, don't do anything else
|
||||
// like deselect it
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
if(odd) {
|
||||
$bg(cell, this.alt_row_bg); cell.is_odd = 1;
|
||||
cell.div.style.border = '2px solid ' + this.alt_row_bg;
|
||||
} else $bg(cell,'#FFF');
|
||||
|
||||
if(!hc.fieldname) cell.div.style.cursor = 'default'; // Index
|
||||
}
|
||||
|
||||
this.set_ht();
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
_f.Grid.prototype.refresh_cell = function(docname, fieldname) {
|
||||
for(var r=0;r<this.tab.rows.length;r++) {
|
||||
if(this.tab.rows[r].docname==docname) {
|
||||
for(var c=0;c<this.head_row.cells.length;c++) {
|
||||
var hc = this.head_row.cells[c];
|
||||
if(hc.fieldname==fieldname) {
|
||||
this.set_cell_value(this.tab.rows[r].cells[c]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for form edit
|
||||
_f.cur_grid;
|
||||
_f.cur_grid_ridx;
|
||||
|
||||
_f.Grid.prototype.set_cell_value = function(cell) {
|
||||
// if newrow
|
||||
if(cell.row.is_newrow)return;
|
||||
|
||||
// show static
|
||||
var hc = this.head_row.cells[cell.cellIndex];
|
||||
if(hc.fieldname)
|
||||
var doc = locals[hc.doctype][cell.row.docname];
|
||||
|
||||
if(hc.fieldname && doc) {
|
||||
var v = locals[hc.doctype][cell.row.docname][hc.fieldname];
|
||||
} else {
|
||||
var v = (cell.row.rowIndex + 1); // Index
|
||||
}
|
||||
|
||||
if(v==null){ v=''; }
|
||||
var me = this;
|
||||
|
||||
// variations
|
||||
if(cell.cellIndex) {
|
||||
$(cell.div).html(wn.format(v, hc.df, {for_print:
|
||||
((doc && doc.docstatus==0 && !cint(hc.df ? hc.df.read_only : 1)) ? true : false)}));
|
||||
} else {
|
||||
// Index column
|
||||
cell.div.style.padding = '2px';
|
||||
cell.div.style.textAlign = 'left';
|
||||
|
||||
cell.div.innerHTML = '';
|
||||
|
||||
$("<span>").html(cell.row.rowIndex + 1).appendTo(cell.div);
|
||||
|
||||
$(cell.div).click(function() {
|
||||
if(me.can_edit) {
|
||||
me.cell_deselect();
|
||||
cell.div.style.border = '2px solid #88F';
|
||||
_f.cur_grid_cell = cell;
|
||||
}
|
||||
});
|
||||
|
||||
if(this.can_edit) {
|
||||
$("<a title='Edit Row'><i class='icon-edit'></i></a>")
|
||||
.click(function() {
|
||||
_f.cur_grid = me;
|
||||
_f.cur_grid_ridx = cell.row.rowIndex;
|
||||
_f.edit_record(me.doctype, cell.row.docname, 1);
|
||||
})
|
||||
.css({"margin-left": "4px"})
|
||||
.appendTo(cell.div)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if clicked on whitespace
|
||||
// and a grid cell is selected
|
||||
// deselect the cell
|
||||
$(document).bind('click', function(e) {
|
||||
var me = this;
|
||||
var is_target_toolbar = function() {
|
||||
return $(e.target).parents('.grid_tbarlinks').length;
|
||||
}
|
||||
|
||||
var is_target_input = function() {
|
||||
// select opened
|
||||
if(e.target.tagName.toLowerCase()=='option') return true;
|
||||
|
||||
// autosuggest openend
|
||||
//if(wn._autosugg_open) return true;
|
||||
|
||||
return $(e.target).parents().get().indexOf(_f.cur_grid_cell)!=-1;
|
||||
}
|
||||
|
||||
if(_f.cur_grid_cell && !is_target_input() && !is_target_toolbar()) {
|
||||
if(!(text_dialog && text_dialog.display)
|
||||
&& !datepicker_active && !(selector && selector.display)) {
|
||||
setTimeout('_f.cur_grid_cell.grid.cell_deselect()', 500);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_f.Grid.prototype.cell_deselect = function() {
|
||||
if(_f.cur_grid_cell) {
|
||||
var c = _f.cur_grid_cell;
|
||||
c.grid.remove_template(c);
|
||||
c.div.className = 'grid_cell_div';
|
||||
if(c.is_odd) c.div.style.border = '2px solid ' + c.grid.alt_row_bg;
|
||||
else c.div.style.border = '2px solid #FFF';
|
||||
_f.cur_grid_cell = null;
|
||||
}
|
||||
}
|
||||
|
||||
_f.Grid.prototype.cell_select = function(cell, ri, ci) {
|
||||
if(cell && _f.cur_grid_cell==cell && cell.hc) return;
|
||||
|
||||
if(ri!=null && ci!=null)
|
||||
cell = this.tab.rows[ri].cells[ci];
|
||||
|
||||
var hc = this.head_row.cells[cell.cellIndex];
|
||||
|
||||
if(!hc.doctype) return;
|
||||
|
||||
if(!hc.template) {
|
||||
this.make_template(hc);
|
||||
}
|
||||
|
||||
hc.template.perm = this.field ? this.field.perm : hc.perm; // get latest permissions
|
||||
|
||||
if(hc.fieldname && hc.template.get_status()=='Write') {
|
||||
this.cell_deselect();
|
||||
cell.div.style.border = '2px solid #88F';
|
||||
_f.cur_grid_cell = cell;
|
||||
this.add_template(cell);
|
||||
}
|
||||
}
|
||||
|
||||
_f.Grid.prototype.add_template = function(cell) {
|
||||
if(!cell.row.docname && this.add_newrow) { // activate new row here
|
||||
this.add_newrow();
|
||||
this.cell_select(cell);
|
||||
} else {
|
||||
var hc = this.head_row.cells[cell.cellIndex];
|
||||
cell.div.innerHTML = '';
|
||||
cell.div.appendChild(hc.template.wrapper);
|
||||
hc.template.activate(cell.row.docname);
|
||||
hc.template.activated=1;
|
||||
cell.hc = hc;
|
||||
|
||||
if(hc.template.input && hc.template.input.set_width) {
|
||||
hc.template.input.set_width($(cell).width());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_f.Grid.prototype.get_field = function(fieldname) { // get template
|
||||
for(var i=0;i<this.head_row.cells.length;i++) {
|
||||
var hc = this.head_row.cells[i];
|
||||
if(hc.fieldname == fieldname) {
|
||||
if(!hc.template) {
|
||||
this.make_template(hc);
|
||||
}
|
||||
return hc.template;
|
||||
}
|
||||
}
|
||||
return {} // did not find, return empty object not to throw error in get_query
|
||||
}
|
||||
|
||||
|
||||
_f.grid_date_cell = '';
|
||||
_f.grid_refresh_date = function() {
|
||||
_f.grid_date_cell.grid.set_cell_value(_f.grid_date_cell);
|
||||
}
|
||||
_f.grid_refresh_field = function(temp, input) {
|
||||
if($(input).val() != _f.get_value(temp.doctype, temp.docname, temp.df.fieldname))
|
||||
$(input).trigger('change');
|
||||
}
|
||||
|
||||
_f.Grid.prototype.remove_template = function(cell) {
|
||||
var hc = this.head_row.cells[cell.cellIndex];
|
||||
|
||||
if(!hc.template)return;
|
||||
if(!hc.template.activated)return;
|
||||
|
||||
if(hc.template && hc.template.wrapper.parentNode)
|
||||
cell.div.removeChild(hc.template.wrapper);
|
||||
this.set_cell_value(cell);
|
||||
hc.template.activated=0;
|
||||
}
|
||||
|
||||
_f.Grid.prototype.notify_keypress = function(e, keycode) {
|
||||
if(keycode>=37 && keycode<=40 && e.shiftKey) {
|
||||
if(text_dialog && text_dialog.display) {
|
||||
return;
|
||||
}
|
||||
} else
|
||||
return;
|
||||
|
||||
if(!_f.cur_grid_cell) return;
|
||||
if(_f.cur_grid_cell.grid != this) return;
|
||||
var ri = _f.cur_grid_cell.row.rowIndex;
|
||||
var ci = _f.cur_grid_cell.cellIndex;
|
||||
switch(keycode) {
|
||||
case 38: // up
|
||||
if (ri > 0) {
|
||||
this.cell_select('', ri - 1, ci);
|
||||
} break;
|
||||
case 40: // down
|
||||
if (ri < (this.tab.rows.length - 1)) {
|
||||
this.cell_select('', ri + 1, ci);
|
||||
} break;
|
||||
case 39: // right
|
||||
if (ci < (this.head_row.cells.length - 1)) {
|
||||
this.cell_select('', ri, ci + 1);
|
||||
} break;
|
||||
case 37: // left
|
||||
if (ci > 1) {
|
||||
this.cell_select('', ri, ci - 1);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
_f.Grid.prototype.make_template = function(hc) {
|
||||
hc.template = make_field(wn.meta.get_docfield(hc.doctype, hc.fieldname), hc.doctype,
|
||||
'', this.field.frm, true);
|
||||
hc.template.grid = this;
|
||||
}
|
||||
|
||||
_f.Grid.prototype.append_rows = function(n) {
|
||||
for(var i=0;i<n;i++) this.append_row();
|
||||
}
|
||||
|
||||
_f.Grid.prototype.truncate_rows = function(n) {
|
||||
for(var i=0;i<n;i++) this.tab.deleteRow(this.tab.rows.length-1);
|
||||
}
|
||||
|
||||
_f.Grid.prototype.set_data = function(data) {
|
||||
|
||||
// deselect if not done yet
|
||||
this.cell_deselect();
|
||||
|
||||
// set table widths
|
||||
this.reset_table_width();
|
||||
|
||||
// append if reqd
|
||||
if(data.length > this.tab.rows.length)
|
||||
this.append_rows(data.length - this.tab.rows.length);
|
||||
|
||||
// truncate if reqd
|
||||
if(data.length < this.tab.rows.length)
|
||||
this.truncate_rows(this.tab.rows.length - data.length);
|
||||
|
||||
// set data
|
||||
for(var ridx=0;ridx<data.length;ridx++) {
|
||||
this.refresh_row(ridx, data[ridx]);
|
||||
}
|
||||
|
||||
if(this.can_add_rows && this.make_newrow) {
|
||||
this.make_newrow();
|
||||
}
|
||||
|
||||
if(this.wrapper.onscroll)this.wrapper.onscroll();
|
||||
}
|
||||
|
||||
_f.Grid.prototype.set_ht = function() {
|
||||
var max_ht = cint(0.37 * screen.width);
|
||||
var ht = $(this.tab).height() + $(this.head_tab).height() + 30;
|
||||
|
||||
if(ht < 100)
|
||||
ht=100;
|
||||
|
||||
if(ht > max_ht) ht = max_ht;
|
||||
|
||||
ht += 4;
|
||||
$y(this.wrapper,{height:ht+'px'});
|
||||
}
|
||||
|
||||
_f.Grid.prototype.refresh_row = function(ridx, docname) {
|
||||
var row = this.tab.rows[ridx];
|
||||
row.docname = docname;
|
||||
row.is_newrow = false;
|
||||
|
||||
for(var cidx=0; cidx<row.cells.length; cidx++) {
|
||||
this.set_cell_value(row.cells[cidx]);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,10 +30,10 @@ wn.ui.form.Attachments = Class.extend({
|
|||
make: function() {
|
||||
var me = this;
|
||||
this.wrapper = $('<div>\
|
||||
<div class="alert-list"></div>\
|
||||
<div class="attachment-list"></div>\
|
||||
<button class="btn btn-small"><i class="icon-plus"></i></button>\
|
||||
</div>').appendTo(this.parent);
|
||||
this.$list = this.wrapper.find(".alert-list");
|
||||
this.$list = this.wrapper.find(".attachment-list");
|
||||
|
||||
this.parent.find(".btn").click(function() {
|
||||
me.new_attachment();
|
||||
|
|
@ -51,7 +51,7 @@ wn.ui.form.Attachments = Class.extend({
|
|||
},
|
||||
refresh: function() {
|
||||
var doc = this.frm.doc;
|
||||
if(doc.__islocal || !this.frm.meta.allow_attach) {
|
||||
if(doc.__islocal) {
|
||||
this.parent.toggle(false);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,8 +131,10 @@ wn.ui.form.States = Class.extend({
|
|||
});
|
||||
|
||||
// disable the button if user cannot change state
|
||||
var is_final = !$ul.find("li").length;
|
||||
this.workflow_button
|
||||
.attr('disabled', $ul.find("li").length ? false : true);
|
||||
.attr('disabled', is_final);
|
||||
this.workflow_button.find(".caret").toggle(is_final ? false : true)
|
||||
},
|
||||
|
||||
set_default_state: function() {
|
||||
|
|
|
|||
|
|
@ -14,11 +14,21 @@ wn.ui.form.Toolbar = Class.extend({
|
|||
this.make_file_menu();
|
||||
this.make_view_menu();
|
||||
this.set_title_button();
|
||||
this.set_title_image();
|
||||
this.show_title_as_dirty();
|
||||
},
|
||||
get_dropdown_menu: function(label) {
|
||||
return this.appframe.add_dropdown(label);
|
||||
},
|
||||
set_title_image: function() {
|
||||
var img = this.frm.appframe.$w.find('.title-status-img').toggle(false);
|
||||
if(this.frm.doc.docstatus==1) {
|
||||
img.attr("src", "lib/images/ui/submitted.png").toggle(true);
|
||||
}
|
||||
else if(this.frm.doc.docstatus==2) {
|
||||
img.attr("src", "lib/images/ui/cancelled.png").toggle(true);
|
||||
}
|
||||
},
|
||||
make_file_menu: function() {
|
||||
var me = this;
|
||||
var p = this.frm.perm[0];
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ wn.ui.AppFrame = Class.extend({
|
|||
</ul>\
|
||||
</div>\
|
||||
<div class="toolbar-area"></div -->\
|
||||
<img class="title-status-img hidden-phone"\
|
||||
style="position: absolute; top: 10px; left: 40%; width: 160px; display:none" />\
|
||||
<div class="title-button-area btn-group pull-right" style="margin-top: 10px;"></div>\
|
||||
<div class="title-area"><h3 style="display: inline-block">\
|
||||
<span class="title-icon"></span><span class="title-text"></span></h3></div>\
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue