// 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%', ['60%','40%']); 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'); 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) { var idx = this.head_row.cells.length; if(!width)width = '100px'; if((width+'').slice(-2)!='px') { width= width + 'px'; } var col = this.head_row.insertCell(idx); col.doctype = doctype; // for report (fields may be from diff doctypes) col.fieldname = fieldname; col.fieldtype = fieldtype; col.innerHTML = '