From 6af5af2671d38ecf87d4a35fd1835f7717379c33 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Sun, 28 Oct 2012 15:14:31 -0400
Subject: [PATCH] Add confirm action diglog handler Impove row highlighter on
 table listing.

---
 scp/css/scp.css |  5 +++
 scp/js/scp.js   | 86 +++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 78 insertions(+), 13 deletions(-)

diff --git a/scp/css/scp.css b/scp/css/scp.css
index 5955c0304..59964d4e6 100644
--- a/scp/css/scp.css
+++ b/scp/css/scp.css
@@ -411,6 +411,11 @@ table.list tbody td { background: #fff; padding: 1px; padding-left:2px; vertical
 table.list tbody tr.odd td { background-color: #f0faff; }
 table.list tbody tr:hover td { background: #ffe; }
 table.list tbody tr.odd:hover td { background: #ffd; }
+/* row highlighting on hover + select */
+table.list tbody tr:hover td, table.list tbody tr.highlight td {  background: #FFFFDD; }
+/* disabled highlighting on nohover */
+table.list tbody tr:hover td.nohover, table.list tbody tr.highlight td.nohover {}
+
 
 table.list tfoot td {
     background:#eee;
diff --git a/scp/js/scp.js b/scp/js/scp.js
index 78fdbe43d..a841d96cd 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -43,10 +43,11 @@ function toogle_all(formObj,highlight){
 
 
 
-function checkbox_checker(formObj, min,max) {
+function checkbox_checker(formObj, min, max) {
 
-
-    var checked=$("input[type=checkbox]:checked").length;
+    var max = max || 0;
+    var min = min || 1;
+    var checked=$('input:checkbox:checked', formObj).length;
     var action= action?action:"process";
     if (max>0 && checked > max ){
         msg="You're limited to only " + max + " selections.\n"
@@ -69,6 +70,73 @@ $(document).ready(function(){
 
     $("input:not(.dp):visible:enabled:first").focus();
     $('table.list tbody tr:odd').addClass('odd');
+    $('table.list input:checkbox').bind('click, change', function() {
+        $(this)
+            .parents("tr:first")
+            .toggleClass("highlight", this.checked);
+     });
+
+    $('#selectAll').click(function(e) {
+        e.preventDefault();
+        var target = $(this).attr('href').substr(1, $(this).attr('href').length);
+        $(this).closest('form')
+            .find('input:checkbox.'+target)
+            .prop('checked', true)
+            .trigger('change');
+
+        return false;
+     });
+
+
+    $('#selectNone').click(function(e) {
+        e.preventDefault();
+        var target = $(this).attr('href').substr(1, $(this).attr('href').length);
+        $(this).closest('form')
+            .find('input:checkbox.'+target)
+            .prop('checked', false)
+            .trigger('change');
+        return false;
+     });
+
+    $('#selectToggle').click(function(e) {
+        e.preventDefault();
+        var target = $(this).attr('href').substr(1, $(this).attr('href').length);
+        $(this).closest('form')
+            .find('input:checkbox.'+target)
+            .each(function() {
+                $(this)
+                    .prop('checked', !$(this).is(':checked'))
+                    .trigger('change');
+             });
+        return false;
+     });
+
+    $('#buttons input:submit.button').bind('click', function(e) {
+
+        var formObj = $(this).closest('form');
+        e.preventDefault();
+        if($('.dialog#confirm-action p#'+this.name+'-confirm').length == 0) {
+            alert('Unknown action '+this.name+' - get technical help.');
+        } else if(checkbox_checker(formObj, 1)) {
+            var action = this.name;
+            $('.dialog#confirm-action').undelegate('.confirm');
+            $('.dialog#confirm-action').delegate('input.confirm', 'click.confirm', function(e) {
+                e.preventDefault();
+                $('.dialog#confirm-action').hide();
+                $('#overlay').hide();
+                $('input#action', formObj).val(action);
+                formObj.submit();
+                return false;
+             });
+            $('#overlay').show();
+            $('.dialog#confirm-action .confirm-action').hide();
+            $('.dialog#confirm-action p#'+this.name+'-confirm')
+            .show()
+            .parent('div').show().trigger('click');
+        } 
+        
+        return false;
+     });
 
     if($.browser.msie) {
         $('.inactive').mouseenter(function() {
@@ -294,17 +362,9 @@ $(document).ready(function(){
         left : ($(window).width() / 2 - 300)
     });
       
-    $('.dialog').delegate('a.close', 'click', function(e) {
-        e.preventDefault();
-        $(this).parent().hide()
-        $('#overlay').hide();
-
-        return false;
-    });
-
-    $('.dialog').delegate('input.close', 'click', function(e) {
+    $('.dialog').delegate('input.close, a.close', 'click', function(e) {
         e.preventDefault();
-        $(this).closest('form').parent().hide()
+        $(this).parents('div.dialog').hide()
         $('#overlay').hide();
 
         return false;
-- 
GitLab