Author: jfthomps
Date: Wed Sep 24 16:29:55 2014
New Revision: 1627362

URL: http://svn.apache.org/r1627362
Log:
VCL-776 - rework resource code to have a base class for all resources and 
inheriting classes for each resource type

added functionality to track which fields for a resource a users has selected 
to be displayed; stored in browser cookie

resource.php:
-modified viewResources: added check for $_COOKIE[type . selfields] that tracks 
which fields have been selected to be displayed; also pass array generated from 
that to addDisplayCheckboxes
-modified addDisplayCheckboxes: determine if checkbox should be checked or not 
based on content of $selfields

resources.js:
-added this.restype to class definition
-modified toggleResFieldDisplay - added call to this.updateFieldCookie
-added updateFieldCookie - tracks selected fields in a cookie

schedule.js: added definition for Schedule class so that we can set 
this.restype to 'schedule'

managementnode.js: added this.restype to class definition

config.js: added definition for config class

image.js: added this.restype to class definition

computer.js:
-added this.restype to class definition
-modified toggleResFieldDisplay - added call to this.updateFieldCookie

vcl.css: changed widths for computerdlgcontent label and .labeledform

utils.php:
-modified abort: added calls to error_log so that errors will also be logged to 
the php error log; makes it easier for people to debug errors that are sent 
back to a browser but not displayed
-modified getDojoHTML: added dojo.cookie to requires for viewResources


Modified:
    vcl/trunk/web/.ht-inc/resource.php
    vcl/trunk/web/.ht-inc/utils.php
    vcl/trunk/web/css/vcl.css
    vcl/trunk/web/js/resources.js
    vcl/trunk/web/js/resources/computer.js
    vcl/trunk/web/js/resources/config.js
    vcl/trunk/web/js/resources/image.js
    vcl/trunk/web/js/resources/managementnode.js
    vcl/trunk/web/js/resources/schedule.js

Modified: vcl/trunk/web/.ht-inc/resource.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/resource.php?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/resource.php (original)
+++ vcl/trunk/web/.ht-inc/resource.php Wed Sep 24 16:29:55 2014
@@ -254,6 +254,20 @@ class Resource {
                        return;
                }
 
+               $selfields = array();
+               if(array_key_exists("{$this->restype}selfields", $_COOKIE)) {
+                       $tmp = explode('|', 
$_COOKIE["{$this->restype}selfields"]);
+                       foreach($tmp as $pair) {
+                               $pair = explode(':', $pair);
+                               if(count($pair) != 2)
+                                       continue;
+                               $field = $pair[0];
+                               $val = $pair[1];
+                               if(preg_match('/^[a-zA-Z0-9]+$/', $field) && 
($val == 0 || $val == 1))
+                                       $selfields[$field] = $val;
+                       }
+               }
+
                # filters
                $h .= "<div dojoType=\"dijit.TitlePane\" title=\"Filters (click 
to expand)\" ";
                $h .= "open=\"false\">\n";
@@ -270,7 +284,7 @@ class Resource {
 
                $h .= "</span>\n"; # namefilter
                $h .= "<strong>Displayed Fields</strong>:<br>\n";
-               $h .= $this->addDisplayCheckboxes($fields, $resdata[$testid]);
+               $h .= $this->addDisplayCheckboxes($fields, $resdata[$testid], 
$selfields);
                if($this->deletetoggled) {
                        $h .= "<label for=\"showdeleted\"><strong>Include 
Deleted ";
                        $h .= "{$this->restypename}s:</strong>:</label>\n";
@@ -299,7 +313,10 @@ class Resource {
                $h .= "<th field=\"id\" id=\"delcolth\" width=\"{$w[0]}\" 
formatter=\"resource.DeleteBtn\" styles=\"text-align: center;\">&nbsp;</th>\n";
                $h .= "<th field=\"id\" width=\"{$w[1]}\" 
formatter=\"resource.EditBtn\" styles=\"text-align: center;\">&nbsp;</th>\n";
                $h .= "<th field=\"name\" width=\"{$w[2]}\">Name</th>\n";
-               $h .= "<th field=\"owner\" width=\"{$w[3]}\">Owner</th>\n";
+               if(array_key_exists('owner', $selfields) && ! 
$selfields['owner'])
+                       $h .= "<th field=\"owner\" width=\"{$w[3]}\" 
hidden=\"true\">Owner</th>\n";
+               else
+                       $h .= "<th field=\"owner\" 
width=\"{$w[3]}\">Owner</th>\n";
                foreach($fields as $field) {
                        if($field == $this->namefield ||
                           $field == 'name' ||
@@ -308,7 +325,10 @@ class Resource {
                           preg_match('/id$/', $field))
                                continue;
                        $w = $this->fieldWidth($field);
-                       $h .= "<th field=\"$field\" $w hidden=\"true\" 
formatter=\"resource.colformatter\">";
+                       if(array_key_exists($field, $selfields) && 
$selfields[$field])
+                               $h .= "<th field=\"$field\" $w 
formatter=\"resource.colformatter\">";
+                       else
+                               $h .= "<th field=\"$field\" $w hidden=\"true\" 
formatter=\"resource.colformatter\">";
                        $h .= $this->fieldDisplayName($field);
                        $h .= "</th>\n";
                }
@@ -334,11 +354,12 @@ class Resource {
 
        
/////////////////////////////////////////////////////////////////////////////
        ///
-       /// \fn addDisplayCheckboxes($allfields, $sample)
+       /// \fn addDisplayCheckboxes($allfields, $sample, $selfields)
        ///
        /// \param $allfields - array of fields for which to generate checkboxes
        /// \param $sample - sample data item that is used to determine what 
fields
        /// to use for generating checkboxes
+       /// \param $selfields - array of fields that should be selected
        ///
        /// \return html
        ///
@@ -346,7 +367,7 @@ class Resource {
        /// page
        ///
        
/////////////////////////////////////////////////////////////////////////////
-       function addDisplayCheckboxes($allfields, $sample) {
+       function addDisplayCheckboxes($allfields, $sample, $selfields) {
                $fields = array('owner');
                foreach($allfields as $field) {
                        if($field == $this->namefield ||
@@ -364,7 +385,9 @@ class Resource {
                        $cols = 4;
                if($fieldcnt < 6) {
                        foreach($fields as $field) {
-                               if($field == 'name' || $field == 'owner')
+                               if($field == 'owner' && (! 
array_key_exists('owner', $selfields) || $selfields['owner']))
+                                       $h .= "<input type=checkbox 
id=chk$field checked onClick=\"resource.toggleResFieldDisplay(this, 
'$field')\">";
+                               elseif($field == 'name' || 
(array_key_exists($field, $selfields) && $selfields[$field]))
                                        $h .= "<input type=checkbox 
id=chk$field checked onClick=\"resource.toggleResFieldDisplay(this, 
'$field')\">";
                                else
                                        $h .= "<input type=checkbox 
id=chk$field onClick=\"resource.toggleResFieldDisplay(this, '$field')\">";
@@ -380,13 +403,15 @@ class Resource {
                                $mod = $cols;
                                if($cnt % $mod == 0)
                                        $h .= "<tr>\n";
-                               if($field == 'name' || $field == 'owner')
+                               if($field == 'owner' && (! 
array_key_exists('owner', $selfields) || $selfields['owner']))
+                                       $h .= "  <td><input type=checkbox 
id=chk$field checked onClick=\"resource.toggleResFieldDisplay(this, 
'$field')\">";
+                               elseif($field == 'name' || 
(array_key_exists($field, $selfields) && $selfields[$field]))
                                        $h .= "  <td><input type=checkbox 
id=chk$field checked onClick=\"resource.toggleResFieldDisplay(this, 
'$field')\">";
                                else
                                        $h .= "  <td><input type=checkbox 
id=chk$field onClick=\"resource.toggleResFieldDisplay(this, '$field')\">";
                                $h .= "<label for=chk$field>";
                                $h .= $this->fieldDisplayName($field);
-                               $h .= "</label><br>\n";
+                               $h .= "</label><br></td>\n";
                                $cnt++;
                                if($cnt % $mod == 0)
                                        $h .= "</tr>\n";

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Wed Sep 24 16:29:55 2014
@@ -875,14 +875,21 @@ function abort($errcode, $query="") {
        if(ONLINEDEBUG && checkUserHasPerm('View Debug Information')) {
                if($errcode >= 100 && $errcode < 400) {
                        print "<font color=red>" . mysql_error($mysql_link_vcl) 
. "</font><br>\n";
-                       if($ENABLE_ITECSAUTH)
+                       error_log(mysql_error($mysql_link_vcl));
+                       if($ENABLE_ITECSAUTH) {
                                print "<font color=red>" . 
mysql_error($mysql_link_acct) . "</font><br>\n";
+                               error_log(mysql_error($mysql_link_acct));
+                       }
                        print "$query<br>\n";
+                       error_log($query);
                }
                print "ERROR($errcode): " . $ERRORS["$errcode"] . "<BR>\n";
+               error_log("ERROR($errcode): " . $ERRORS["$errcode"]);
+               $backtrace = getBacktraceString(FALSE);
                print "<pre>\n";
-               print getBacktraceString(FALSE);
+               print $backtrace;
                print "</pre>\n";
+               error_log($backtrace);
        }
        else {
                $message = "";
@@ -910,6 +917,7 @@ function abort($errcode, $query="") {
                }
                $message .= getBacktraceString(FALSE);
                $mailParams = "-f" . ENVELOPESENDER;
+               error_log($message);
                mail(ERROREMAIL, "Error with VCL pages ($errcode)", $message, 
'', $mailParams);
                print _("An error has occurred.  If this problem persists, 
please email ");
                print "<a href=\"mailto:"; . HELPEMAIL . "?Subject=" . 
_("Problem%20With%20VCL") . "\">";
@@ -12601,6 +12609,7 @@ function getDojoHTML($refresh) {
                                              'dijit.Tooltip',
                                              'dojox.grid._CheckBoxSelector',
                                              'dijit.Menu',
+                                             'dojo.cookie',
                                              'dijit.Dialog');
                        break;
                case 'groupMapHTML':

Modified: vcl/trunk/web/css/vcl.css
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/css/vcl.css?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/css/vcl.css (original)
+++ vcl/trunk/web/css/vcl.css Wed Sep 24 16:29:55 2014
@@ -501,11 +501,11 @@ body {
 }
 
 #computerdlgcontent label {
-       width: 12em;
+       width: 12.5em;
 }
 
 #computerdlgcontent .labeledform {
-       margin-left: 12.5em;
+       margin-left: 13em;
 }
 
 #advancedoptions label {

Modified: vcl/trunk/web/js/resources.js
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/js/resources.js?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/js/resources.js (original)
+++ vcl/trunk/web/js/resources.js Wed Sep 24 16:29:55 2014
@@ -15,7 +15,9 @@
 * limitations under the License.
 */
 
-function Resource() {}
+function Resource() {
+       this.restype = 'resource';
+}
 
 Resource.prototype.DeleteBtn = function(rscid, rowIndex) {
        var rowdata = this.grid.getItem(rowIndex);
@@ -127,6 +129,38 @@ Resource.prototype.toggleResFieldDisplay
                        break;
                }
        }
+       this.updateFieldCookie(field, obj.checked);
+}
+
+Resource.prototype.updateFieldCookie = function(field, selected) {
+       var data = dojo.cookie(this.restype + 'selfields');
+       if(typeof data === 'undefined') {
+               if(selected)
+                       dojo.cookie(this.restype + 'selfields', field + ':1');
+               else
+                       dojo.cookie(this.restype + 'selfields', field + ':0');
+       }
+       else {
+               var items = data.split('|');
+               for(var i = 0; i < items.length; i++) {
+                       var pair = items[i].split(':');
+                       if(pair[0] == field) {
+                               if(selected)
+                                       items[i] = field + ':1';
+                               else
+                                       items[i] = field + ':0';
+                               break;
+                       }
+               }
+               if(i == items.length) {
+                       if(selected)
+                               items.push(field + ':1');
+                       else
+                               items.push(field + ':0');
+               }
+               data = items.join('|');
+               dojo.cookie(this.restype + 'selfields', data);
+       }
 }
 
 Resource.prototype.nocasesort = function(a, b) {

Modified: vcl/trunk/web/js/resources/computer.js
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/js/resources/computer.js?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/js/resources/computer.js (original)
+++ vcl/trunk/web/js/resources/computer.js Wed Sep 24 16:29:55 2014
@@ -19,6 +19,7 @@ function Computer() {
        Resource.apply(this, Array.prototype.slice.call(arguments));
        this.selids = [];
        this.selectingall = false;
+       this.restype = 'computer';
 }
 Computer.prototype = new Resource();
 
@@ -117,6 +118,7 @@ Computer.prototype.toggleResFieldDisplay
                        break;
                }
        }
+       this.updateFieldCookie(field, obj.checked);
 }
 
 Computer.prototype.GridFilter = function() {

Modified: vcl/trunk/web/js/resources/config.js
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/js/resources/config.js?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/js/resources/config.js (original)
+++ vcl/trunk/web/js/resources/config.js Wed Sep 24 16:29:55 2014
@@ -15,6 +15,14 @@
 * limitations under the License.
 */
 
+function Config() {
+       Resource.apply(this, Array.prototype.slice.call(arguments));
+       this.restype = 'config';
+}
+Config.prototype = new Resource();
+
+var resource = new Config();
+
 var cfgvartimeout = null;
 var nocfgvarupdates = 1;
 var newcfgvarid = 15000001;

Modified: vcl/trunk/web/js/resources/image.js
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/js/resources/image.js?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/js/resources/image.js (original)
+++ vcl/trunk/web/js/resources/image.js Wed Sep 24 16:29:55 2014
@@ -19,6 +19,7 @@ function Image() {
        Resource.apply(this, Array.prototype.slice.call(arguments));
        this.selids = [];
        this.selectingall = false;
+       this.restype = 'image';
 }
 Image.prototype = new Resource();
 

Modified: vcl/trunk/web/js/resources/managementnode.js
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/js/resources/managementnode.js?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/js/resources/managementnode.js (original)
+++ vcl/trunk/web/js/resources/managementnode.js Wed Sep 24 16:29:55 2014
@@ -19,6 +19,7 @@ function ManagementNode() {
        Resource.apply(this, Array.prototype.slice.call(arguments));
        this.selids = [];
        this.selectingall = false;
+       this.restype = 'managementnode';
 }
 ManagementNode.prototype = new Resource();
 

Modified: vcl/trunk/web/js/resources/schedule.js
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/js/resources/schedule.js?rev=1627362&r1=1627361&r2=1627362&view=diff
==============================================================================
--- vcl/trunk/web/js/resources/schedule.js (original)
+++ vcl/trunk/web/js/resources/schedule.js Wed Sep 24 16:29:55 2014
@@ -15,7 +15,13 @@
 * limitations under the License.
 */
 
-var resource = new Resource();
+function Schedule() {
+       Resource.apply(this, Array.prototype.slice.call(arguments));
+       this.restype = 'schedule';
+}
+Schedule.prototype = new Resource();
+
+var resource = new Schedule();
 
 var scheduleTimeData = {
        identifier: 'id',


Reply via email to