From aa33c83c9cf420f0a825fda4d3b47e0e0a6dcd91 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Wed, 2 May 2012 23:02:49 -0400 Subject: [PATCH] Major JS cleanup and misc improvements to the quote editor Content-Type: text/plain; charset="utf-8" Adds missing page heading... thanks oleonard. Adds beginning of click-for-help elements. Refactors delete functionality to allow selecting of quotes to delete, enabling multi-delete. Refactors saving added quote functionality so that striking saves the new quote. Refactors canceling aded quote functionality so that striking cancles the new quote. --- koha-tmpl/intranet-tmpl/prog/en/css/datatables.css | 8 + .../intranet-tmpl/prog/en/modules/tools/quotes.tt | 178 +++++++++++--------- tools/quotes/quotes_ajax.pl | 14 +- 3 files changed, 115 insertions(+), 85 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/datatables.css b/koha-tmpl/intranet-tmpl/prog/en/css/datatables.css index ad97a48..a4c6f4f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/datatables.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/datatables.css @@ -200,6 +200,14 @@ input { border-radius: 5px; } +tr.odd.selected td { + background-color: #D3D3D3; +} + +tr.even.selected td { + background-color: #D3D3D3; +} + /* table.display { width: 100%; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt index 5858700..874ccdf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt @@ -3,6 +3,7 @@ [% INCLUDE 'doc-head-close.inc' %] + [% INCLUDE 'datatables-strings.inc' %] @@ -12,18 +13,18 @@ var oTable; /* oTable needs to be global */ var sEmptyTable = _('No quotes available. Please use the \"Add Quote\" button to add a quote.'); /* override the default message in datatables-strings.inc */ $(document).ready(function() { + /* NOTE: This is an ajax-source datatable and *not* a server-side sourced datatable. */ + /* See the datatable docs if you don't understand this difference. */ oTable = $("#quotes_editor").dataTable({ "bAutoWidth" : false, "bProcessing" : true, - //"bServerSide" : true, "bPaginate" : true, "sPaginationType" : "full_numbers", "sAjaxSource" : "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", "aoColumns" : [ { "sWidth": "3%" }, { "sWidth": "11%" }, - { "sWidth": "65%" }, - { "sWidth": "10%" }, + { "sWidth": "75%" }, { "sWidth": "11%" }, ], "oLanguage" : { @@ -33,13 +34,18 @@ return true; }, "fnRowCallback": function( nRow, aData, iDisplayIndex ) { - noEditFields = [0,3,4]; /* id, timestamp, action */ - quoteID = $('td', nRow)[0].innerHTML; - /* console.log('Quote ID: '+quoteID); */ - /* do foo on various cells in the current row */ - $('td:eq(1)', nRow).attr("id", quoteID); /* we use the id attribute to carry the quote id */ - $('td:eq(2)', nRow).attr("id", quoteID); - $('td:eq(4)', nRow).html(''); + /* do foo on the current row and its child nodes */ + var noEditFields = []; + var quoteID = $('td', nRow)[0].innerHTML; + $(nRow).attr("id", quoteID); /* set row ids to quote id */ + $('td:eq(0)', nRow).click(function() {$(this.parentNode).toggleClass('selected',this.clicked);}); /* add row selectors */ + $('td:eq(0)', nRow).attr("title", "Click ID to select/deselect quote"); + if (isNaN(quoteID)) { + noEditFields = [0,1,2,3]; /* all fields when adding a quote */ + } + else { + noEditFields = [0,3]; /* id, timestamp */ + } /* apply no_edit id to noEditFields */ for (i=0; i', + '', + '0000-00-00 00:00:00', + ], + false + ); + oTable.fnPageChange( 'last' ); + $('#quoteSource').focus(); + } + + function fnClickDeleteRow() { + var idsToDelete = oTable.$('.selected').map(function() { + return this.id; + }).get().join(', '); + if (confirm('Are you sure you wish to delete quote(s) '+idsToDelete+'?')) { + oTable.$('.selected').each(function(){ + var quoteID = $(this).attr('id'); + $.ajax({ + url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", + type: "POST", + data: { + "id" : quoteID, + "action" : "delete", + }, + /* Delete the row from the datatable */ + success: function(){ + oTable.fnDeleteRow(this); + oTable.fnReloadAjax(null, null, true); + } + }); + }); + } + else { + return; + } + } //]]> @@ -151,22 +171,24 @@
-
    -
  • - - - Click Source or Text field to edit contents. Press to save changes. -
  • -
+
    +
  • + + + + Click Source or Text field to edit contents. Press <Enter> to save changes. +
  • +
+

Quote Editor

- + - + @@ -176,7 +198,7 @@ - +
IDID Source Text Last DisplayedActions
Loading data...
diff --git a/tools/quotes/quotes_ajax.pl b/tools/quotes/quotes_ajax.pl index 1e1e655..eb54550 100755 --- a/tools/quotes/quotes_ajax.pl +++ b/tools/quotes/quotes_ajax.pl @@ -55,6 +55,10 @@ if ($params->{'action'} eq 'add') { warn sprintf('Database returned the following error: %s', $sth->errstr); exit 0; } + my $new_quote_id = $dbh->{q{mysql_insertid}}; # ALERT: mysqlism here + $sth = $dbh->prepare('SELECT * FROM quotes WHERE id = ?;'); + $sth->execute($new_quote_id); + print to_json($sth->fetchall_arrayref); exit 1; } elsif ($params->{'action'} eq 'edit') { @@ -65,7 +69,7 @@ elsif ($params->{'action'} eq 'edit') { warn sprintf('Database returned the following error: %s', $sth->errstr); exit 0; } - print $params->{'value'}; + print $sth->fetchrow_array(); exit 1; } elsif ($params->{'action'} eq 'delete') { @@ -82,19 +86,15 @@ else { my $iTotalRecords = ''; my $sth = ''; - # FIXME: the use of "Action" in the SELECTs below is a hack to supply the fifth column; there should be a nicer way todo this... if (my $filter = $params->{'sSearch'}) { # This seems a bit brute force and ungraceful, but it provides a very general, simple search on all fields my $like = " id LIKE \"%$filter%\" OR source LIKE \"%$filter%\" OR text LIKE \"%$filter%\" OR timestamp LIKE \"%$filter%\""; $iTotalRecords = $dbh->selectrow_array("SELECT count(*) FROM quotes WHERE $like;"); - # At present we only support sorting by a single column - #$sth = $dbh->prepare("SELECT *, \"Action\" FROM quotes WHERE $like ORDER BY $sort_columns->[$params->{'iSortCol_0'}] $params->{'sSortDiri_0'} LIMIT $params->{'iDisplayStart'}, $params->{'iDisplayLength'};"); - $sth = $dbh->prepare("SELECT *, \"Action\" FROM quotes;"); + $sth = $dbh->prepare("SELECT * FROM quotes;"); } else { $iTotalRecords = $dbh->selectrow_array('SELECT count(*) FROM quotes;'); - #$sth = $dbh->prepare("SELECT *, \"Action\" FROM quotes ORDER BY $sort_columns->[$params->{'iSortCol_0'}] $params->{'sSortDiri_0'} LIMIT $params->{'iDisplayStart'}, $params->{'iDisplayLength'};"); - $sth = $dbh->prepare("SELECT *, \"Action\" FROM quotes;"); + $sth = $dbh->prepare("SELECT * FROM quotes;"); } $sth->execute(); -- 1.7.0.4