Bugzilla – Attachment 9392 Details for
Bug 7977
Add a "Quote-of-the-day" feature to the OPAC homepage
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Major JS cleanup and misc improvements to the quote editor
Major-JS-cleanup-and-misc-improvements-to-the-quot.patch (text/plain), 17.15 KB, created by
Chris Nighswonger
on 2012-05-03 03:09:25 UTC
(
hide
)
Description:
Major JS cleanup and misc improvements to the quote editor
Filename:
MIME Type:
Creator:
Chris Nighswonger
Created:
2012-05-03 03:09:25 UTC
Size:
17.15 KB
patch
obsolete
>From aa33c83c9cf420f0a825fda4d3b47e0e0a6dcd91 Mon Sep 17 00:00:00 2001 >From: Chris Nighswonger <cnighswonger@foundations.edu> >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 <Enter> > saves the new quote. >Refactors canceling aded quote functionality so that striking <Esc> > 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' %] > <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" /> > <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script> >+ <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/dataTables.fnReloadAjax.js"></script> > [% INCLUDE 'datatables-strings.inc' %] > </script> > <script type="text/javascript" src="[% themelang %]/js/datatables.js"></script> >@@ -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('<input type="button" class="delete" value="Delete" onclick="fnClickDeleteRow('+quoteID+');" />'); >+ /* 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<noEditFields.length; i++) { > $('td', nRow)[noEditFields[i]].setAttribute("id","no_edit"); >@@ -62,81 +68,95 @@ > }); > }); > >- function fnClickAddQuote() { >- var quoteSource = $('#quoteSource').val(); >- var quoteText = $('#quoteText').val() >- /* If passed a quote source, add the quote to the db */ >- if (quoteSource && quoteText) { >- $.ajax({ >- url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", >- type: "POST", >- data: { >- "source" : quoteSource, >- "text" : quoteText, >- "action" : "add", >- }, >- success: function(){oTable.fnDraw(false)} >- }); >+ function fnClickAddQuote(e, node) { >+ console.log('keyCode: '+e.keyCode); >+ console.log('charCode: '+e.charCode); >+ if (e.charCode) { >+ /* some browsers only give charCode, so this will need to be */ >+ /* fixed up to handle that */ >+ console.log('charCode: '+e.charCode); > } >- else { >- alert('Please supply both the text and source of the quote before saving.'); >- } >- } >- >- function fnClickAddRow() { >- /* This adds a row to the datatable */ >- var lastID = $('#quotes_editor tbody tr:last td:first').text(); /* grab the last quote id to validate add request */ >- if (lastID !== '--') { >- $('#quotes_editor').one('draw', function (){ >- var tbody = document.getElementById('quotes_editor'); >- var lastRow = tbody.rows.length; >- var row = tbody.insertRow(lastRow); >- var currentRow = lastRow+1; >- row.innerHTML ='<td id="no_edit">--</td><td><input id="quoteSource" type="text" style="height:14px; width:99%" /></td><td><input id="quoteText" type="text" style="height:14px; width:99%" /></td><td id="no_edit">--</td><td id="no_edit"><input type="button" class="delete" value="Delete" disable="disable"/><input type="button" class="save" value="Save" onclick="fnClickAddQuote();"/><input type="button" class="cancel" value="Cancel" onclick="fnClickDeleteRow();"/></td>'; >- if (currentRow % 2 == 0) { >- row.className="odd"; >- } >- else { >- row.className="even"; >- } >- }); >- oTable.fnPageChange('last', true); >- } >- else { >- alert('You must either save or cancel your current addition before adding another.'); >- } >- } >- >- function fnClickDeleteRow(quoteID) { >- //console.log('Quote ID: '+quoteID); >- if (quoteID) { >- /* Delete the row from the db */ >- if (confirm('Are you sure you wish to delete quote '+quoteID+'?')) { >+ if (e.keyCode == 13) { >+ var quoteSource = $('#quoteSource').val(); >+ var quoteText = $('#quoteText').val() >+ /* If passed a quote source, add the quote to the db */ >+ if (quoteSource && quoteText) { > $.ajax({ > url: "/cgi-bin/koha/tools/quotes/quotes_ajax.pl", > type: "POST", > data: { >- "id" : quoteID, >- "action" : "delete", >+ "source" : quoteSource, >+ "text" : quoteText, >+ "action" : "add", > }, >- /* On a successful delete, redraw the table */ >- success: function(){oTable.fnDraw(false)} >+ success: function(data){ >+ var newQuote = data[0]; >+ var aRow = oTable.fnUpdate( >+ newQuote, >+ node, >+ false, >+ false >+ ); >+ oTable.fnPageChange( 'last' ); >+ $('.add_quote_button').attr('onclick', 'fnClickAddRow()'); // re-enable add button >+ } > }); > } > else { >- return; >+ alert('Please supply both the text and source of the quote before saving.'); > } > } >- else { >- /* Delete the row from the table */ >- if (confirm('Your quote will not be saved! Do you wish to continue?')) { >- $('#quotes_editor tbody tr:last').remove(); >+ else if (e.keyCode == 27) { >+ if (confirm('Are you sure you want to cancel adding this quote?')) { >+ oTable.fnDeleteRow(node); > } > else { > return; > } > } > } >+ >+ function fnClickAddRow() { >+ $('.add_quote_button').removeAttr('onclick'); // disable add button once it has been clicked >+ var aRow = oTable.fnAddData( >+ [ >+ 'NA', // this is hackish to fool the datatable sort routine into placing this row at the end of the list... >+ '<input id="quoteSource" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>', >+ '<input id="quoteText" type="text" style="height:14px; width:99%" onkeydown="fnClickAddQuote(event,this.parentNode.parentNode)"/>', >+ '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; >+ } >+ } > //]]> > </script> > </head> >@@ -151,22 +171,24 @@ > <div id="yui-main"> > <div class="yui-b"> > <div id="toolbar"> >- <ul class="toolbar"> >- <li> >- <input type="button" class="add_quote_button" value="Add Quote" style="border-radius: 5px;" onclick="fnClickAddRow();"/> >- <input type="button" class="import_quote_button" value="Import Quotes" style="border-radius: 5px;" onclick="parent.location='quotes-upload.pl'"/> >- <span class="hint" style="">Click Source or Text field to edit contents. Press <Enter> to save changes.</span> >- </li> >- </ul> >+ <ul class="toolbar"> >+ <li> >+ <input type="button" class="add_quote_button" value="Add Quote" style="border-radius: 5px;" onclick="fnClickAddRow();"/> >+ <input type="button" class="import_quote_button" value="Import Quotes" style="border-radius: 5px;" onclick="parent.location='quotes-upload.pl'"/> >+ <input type="button" class="delete_quote_button" value="Delete Quote(s)" style="border-radius: 5px;" onclick="fnClickDeleteRow();"/> >+ <span class="hint" style="">Click Source or Text field to edit contents. Press <Enter> to save changes.</span> >+ </li> >+ </ul> > </div> >+ <h2>Quote Editor</h2> > <table id="quotes_editor" style="float: left; width: 100%;"> > <thead> > <tr> >- <th>ID</th> >+ <th><span style="cursor: help" onclick="event.stopPropagation();alert('Click on the quote\'s id to select or deselect the quote. Multiple quotes may be selected.');">ID</span></th> > <th>Source</th> > <th>Text</th> > <th>Last Displayed</th> >- <th>Actions</th> >+<!-- <th>Actions</th>--> > </tr> > </thead> > <tbody> >@@ -176,7 +198,7 @@ > <td></td> > <td>Loading data...</td> > <td></td> >- <td></td> >+<!-- <td></td>--> > </tr> > </tbody> > </table> >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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7977
:
9310
|
9321
|
9323
|
9324
|
9325
|
9326
|
9327
|
9328
|
9338
|
9343
|
9373
|
9376
|
9377
|
9378
|
9392
|
9405
|
9406
|
9407
|
9408
|
9409
|
9433
|
9434
|
9435
|
9441
|
9442
|
9443
|
9447
|
9473
|
9474
|
9475
|
9476
|
9477
|
9478
|
9479
|
9480
|
9481
|
9482
|
9483
|
9484
|
9485
|
9486
|
9503
|
9504
|
9505
|
9510
|
9517
|
9521
|
9529
|
9530
|
9531
|
9682
|
9683
|
9711
|
9712
|
9713
|
9714
|
9715
|
9716
|
9717
|
9718
|
9719
|
9720
|
9721
|
9722
|
9723
|
9724
|
9725
|
9726
|
9727
|
9728
|
9729
|
9730
|
9731
|
9732