[freeside-commits] branch FREESIDE_3_BRANCH updated. 3bc8dfe2724a177e12fd56c7dfeeb7c8a6f8548f
Jonathan Prykop
jonathan at 420.am
Fri Mar 11 14:54:44 PST 2016
The branch, FREESIDE_3_BRANCH has been updated
via 3bc8dfe2724a177e12fd56c7dfeeb7c8a6f8548f (commit)
from bb7ce163175cc18dad25f3ee50958440b330175b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3bc8dfe2724a177e12fd56c7dfeeb7c8a6f8548f
Author: Jonathan Prykop <jonathan at freeside.biz>
Date: Fri Mar 11 16:53:05 2016 -0600
RT#40806: Enter invoice details from order package page [v3, only detail-table refactor, no new functionality]
diff --git a/httemplate/edit/cust_pkg_detail.html b/httemplate/edit/cust_pkg_detail.html
index b1e60da..a1a6db6 100644
--- a/httemplate/edit/cust_pkg_detail.html
+++ b/httemplate/edit/cust_pkg_detail.html
@@ -1,9 +1,4 @@
-<% include("/elements/header-popup.html", $title, '',
- ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
- )
-%>
-
-%# <% include('/elements/error.html') %>
+<& /elements/header-popup.html, $title &>
<FORM ACTION="process/cust_pkg_detail.html" NAME="DetailForm" ID="DetailForm" METHOD="POST">
@@ -40,17 +35,10 @@
<TD COLSPAN=2><% ucfirst($name{$detailtype}) %>: </TD>
</TR>
-% my $row = 0;
-% for ( @details ) {
-
- <TR>
- <TD></TD>
- <TD>
- <INPUT TYPE="text" NAME="detail<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $_->detail |h %>" rownum="<% $row++ %>" onkeyup="possiblyAddRow" onchange="possiblyAddRow" >
- </TD>
- </TR>
-
-% }
+<& elements/detail-table.html,
+ id => 'DetailTable',
+ details => \@details,
+ &>
</TABLE>
@@ -59,48 +47,6 @@
</FORM>
-<SCRIPT TYPE="text/javascript">
-
- var rownum = <% $row %>;
-
- function possiblyAddRow() {
- if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
- addRow();
- }
- }
-
- function addRow() {
-
- var table = document.getElementById('DetailTable');
- var tablebody = table.getElementsByTagName('tbody').item(0);
-
- var row = document.createElement('TR');
-
- var empty_cell = document.createElement('TD');
- row.appendChild(empty_cell);
-
- var detail_cell = document.createElement('TD');
-
- var detail_input = document.createElement('INPUT');
- detail_input.setAttribute('name', 'detail'+rownum);
- detail_input.setAttribute('id', 'detail'+rownum);
- detail_input.setAttribute('size', 60);
- detail_input.setAttribute('maxLength', 65);
- detail_input.setAttribute('rownum', rownum);
- detail_input.onkeyup = possiblyAddRow;
- detail_input.onchange = possiblyAddRow;
- detail_cell.appendChild(detail_input);
-
- row.appendChild(detail_cell);
-
- tablebody.appendChild(row);
-
- rownum++;
-
- }
-
-</SCRIPT>
-
</BODY>
</HTML>
<%init>
@@ -136,7 +82,7 @@ my $cust_pkg = qsearchs({
my $part_pkg = $cust_pkg->part_pkg;
-my @details = $cust_pkg->cust_pkg_detail($detailtype);
+my @details = map { $_->detail } $cust_pkg->cust_pkg_detail($detailtype);
my $title = ( scalar(@details) ? 'Edit ' : 'Add ' ). $name{$detailtype};
diff --git a/httemplate/edit/elements/detail-table.html b/httemplate/edit/elements/detail-table.html
new file mode 100644
index 0000000..496ba31
--- /dev/null
+++ b/httemplate/edit/elements/detail-table.html
@@ -0,0 +1,85 @@
+<%doc>
+Common code for editing invoice/quotation details/comments.
+
+Expects to be the last element in a two-column table with specified id
+
+ <& /edit/elements/detail-table.html,
+ id => 'element_id', # required
+ details => \@details, # plain text strings, existing details
+ label => 'Comments', # optional, shows on first row only
+ field => 'comment', # input field name/id, appended with rownum, default 'detail'
+ &>
+
+</%doc>
+
+<SCRIPT>
+% unless ($detail_table_init) {
+% $detail_table_init = 1;
+
+ var detail_table_info = {};
+ detail_table_info.rownum = {};
+ detail_table_info.label = {};
+ detail_table_info.field = {};
+
+ function possiblyAddDetailRow(tableid,rownum) {
+ if (( detail_table_info.rownum[tableid] - rownum == 1 ) || !detail_table_info.rownum[tableid]) {
+ addDetailRow(tableid);
+ }
+ }
+
+ function addDetailRow(tableid,newtext) {
+
+ var table = document.getElementById(tableid);
+ var newrownum = detail_table_info.rownum[tableid];
+ var newfield = detail_table_info.field[tableid] + newrownum;
+
+ var row = document.createElement('TR');
+
+ var empty_cell = document.createElement('TD');
+ if (!newrownum) {
+ empty_cell.innerHTML = detail_table_info.label[tableid];
+ empty_cell.style.textAlign = 'right';
+ }
+ row.appendChild(empty_cell);
+
+ var detail_cell = document.createElement('TD');
+
+ var detail_input = document.createElement('INPUT');
+ detail_input.setAttribute('name', newfield);
+ detail_input.setAttribute('id', newfield);
+ detail_input.setAttribute('size', 60);
+ detail_input.setAttribute('maxLength', 65);
+ detail_input.onkeyup = function () { possiblyAddDetailRow(tableid,newrownum) };
+ detail_input.onchange = function () { possiblyAddDetailRow(tableid,newrownum) };
+ detail_input.value = newtext || '';
+ detail_cell.appendChild(detail_input);
+
+ row.appendChild(detail_cell);
+
+ table.appendChild(row);
+
+ detail_table_info.rownum[tableid]++;
+
+ }
+% } # end init
+ detail_table_info.label['<% $id %>'] = '<% emt($label) %>';
+ detail_table_info.field['<% $id %>'] = '<% $field %>';
+ detail_table_info.rownum['<% $id %>'] = 0;
+% foreach my $detail ( @details ) {
+ addDetailRow('<% $id %>','<% $detail %>');
+% }
+</SCRIPT>
+
+<%shared>
+my $detail_table_init = 0;
+</%shared>
+<%init>
+my %opt = @_;
+
+my @details = $opt{'details'} ? @{ $opt{'details'} } : ();
+push(@details,'') if $details[$#details] || !@details;
+my $id = $opt{'id'} or die "No id specified";
+my $label = $opt{'label'} || '';
+my $field = $opt{'field'} || 'detail';
+
+</%init>
diff --git a/httemplate/edit/quotation_pkg_detail.html b/httemplate/edit/quotation_pkg_detail.html
index ae09b9c..036bffd 100644
--- a/httemplate/edit/quotation_pkg_detail.html
+++ b/httemplate/edit/quotation_pkg_detail.html
@@ -1,9 +1,4 @@
-<% include("/elements/header-popup.html", $title, '',
- ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
- )
-%>
-
-%# <% include('/elements/error.html') %>
+<& /elements/header-popup.html, $title &>
<FORM ACTION="process/quotation_pkg_detail.html" NAME="DetailForm" ID="DetailForm" METHOD="POST">
@@ -35,17 +30,11 @@
</TD>
</TR>
-% my $row = 0;
-% for ( @details ) {
-
- <TR>
- <TD ALIGN="right"><% $row ? '' : 'Detail' %></TD>
- <TD>
- <INPUT TYPE="text" NAME="detail<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $_ |h %>" rownum="<% $row++ %>" onkeyup="possiblyAddRow" onchange="possiblyAddrow">
- </TD>
- </TR>
-
-% }
+<& elements/detail-table.html,
+ id => 'DetailTable',
+ details => \@details,
+ label => 'Details',
+ &>
</TABLE>
@@ -54,53 +43,6 @@
</FORM>
-<SCRIPT TYPE="text/javascript">
-% # abject false laziness with edit/cust_pkg_detail.html
-
- var rownum = <% $row %>;
-
- function possiblyAddRow() {
- if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
- addRow();
- }
- }
-
- function addRow() {
-
- var table = document.getElementById('DetailTable');
- var tablebody = table.getElementsByTagName('tbody').item(0);
-
- var row = document.createElement('TR');
-
- var empty_cell = document.createElement('TD');
- if (!rownum) {
- empty_cell.innerHTML = 'Detail:'
- empty_cell.style.textAlign = 'right';
- }
- row.appendChild(empty_cell);
-
- var detail_cell = document.createElement('TD');
-
- var detail_input = document.createElement('INPUT');
- detail_input.setAttribute('name', 'detail'+rownum);
- detail_input.setAttribute('id', 'detail'+rownum);
- detail_input.setAttribute('size', 60);
- detail_input.setAttribute('maxLength', 65);
- detail_input.setAttribute('rownum', rownum);
- detail_input.onkeyup = possiblyAddRow;
- detail_input.onchange = possiblyAddRow;
- detail_cell.appendChild(detail_input);
-
- row.appendChild(detail_cell);
-
- tablebody.appendChild(row);
-
- rownum++;
-
- }
-
-</SCRIPT>
-
</BODY>
</HTML>
<%init>
-----------------------------------------------------------------------
Summary of changes:
httemplate/edit/cust_pkg_detail.html | 66 ++-------------------
httemplate/edit/elements/detail-table.html | 85 ++++++++++++++++++++++++++++
httemplate/edit/quotation_pkg_detail.html | 70 ++---------------------
3 files changed, 97 insertions(+), 124 deletions(-)
create mode 100644 httemplate/edit/elements/detail-table.html
More information about the freeside-commits
mailing list