Changeset 1342


Ignore:
Timestamp:
02/05/07 16:17:07 (8 years ago)
Author:
ckb6
Message:

Added validation for graph parts and added some memory to the form so that a failed send causes the data not to be lost

Location:
ccsweb/trunk/ccs_mods/graphs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ccsweb/trunk/ccs_mods/graphs/config-graphs.php

    r1273 r1342  
    245245        if (xmlrpc_has_error($rv)) { 
    246246            ccs_notice("Could not update Group: ".xmlrpc_error_string($rv)); 
     247            $group= array("group_name"=>$_REQUEST["group_name"]); 
    247248        } else { 
    248249            ccs_notice("Group details successfully updated."); 
     
    268269        get_if_posted(&$part, "class_id"); 
    269270        get_if_posted(&$part, "group_id"); 
     271        get_if_posted(&$part, "virtical_label"); 
    270272        $rv = do_xmlrpc("addGraphType", array($part), 
    271273            $xmlrpc_conn, TRUE, FALSE); 
    272274        if (xmlrpc_has_error($rv)) { 
    273275            ccs_notice("Could not update Graph: ".xmlrpc_error_string($rv)); 
     276             
     277            $graph= array("title"=>$_REQUEST["title"], "class_id"=>$_REQUEST["class_id"], "virtical_label"=>$_REQUEST["virtical_label"]); 
    274278        } else { 
    275279            ccs_notice("Graph details successfully updated."); 
     
    300304 ********************************************************************/      
    301305}else if ($_REQUEST["do"] == "newpart") {     
     306    $smarty->assign("part", array("type"=>"DEF")); 
    302307    if ($_REQUEST["process"]=="yes") { 
    303308        $part = array(); 
     
    314319        if (xmlrpc_has_error($rv)) { 
    315320            ccs_notice("Could not update Graph part: ".xmlrpc_error_string($rv)); 
     321            $part= array("type"=>$_REQUEST["type"], "graph_order"=>$_REQUEST["graph_order"], "varname"=>$_REQUEST["varname"], "filename"=>$_REQUEST["filename"] , "cf"=>$_REQUEST["cf"] , "colour"=>$_REQUEST["colour"], "text"=>$_REQUEST["text"]); 
     322            //, ""=>$_REQUEST[""]) 
     323            $smarty->assign("part", $part); 
    316324        } else { 
    317325            ccs_notice("Graph part details successfully updated."); 
     
    327335    getVars($_REQUEST["graph_id"]); 
    328336    $smarty->assign("action", "newpart"); 
    329     $smarty->assign("part", array("type"=>"DEF")); 
    330337    $smarty->assign("items", $items); 
    331338    $smarty->assign("group_id", $_REQUEST["group_id"]); 
     
    350357                xmlrpc_error_string($error)); 
    351358        } 
    352         display_groups(); 
     359        display_type(); 
    353360    }else{ 
    354361        $part = do_xmlrpc("getGraphPart", array($_REQUEST["part_id"]), $xmlrpc_conn, TRUE, FALSE); 
     
    378385                xmlrpc_error_string($error)); 
    379386        } 
    380         display_groups(); 
     387        display_group(); 
    381388    }else{ 
    382389        $part = do_xmlrpc("getGraphType", array($_REQUEST["graph_id"]), $xmlrpc_conn, TRUE, FALSE); 
  • ccsweb/trunk/ccs_mods/graphs/config-graphs.tpl

    r1256 r1342  
    2323{include file="header.tpl" title="Graphs"} 
    2424<div id="instructions"> 
    25 This is a list of groups that graphs are grouped in. 
     25Graphs are grouped into groups of similar graphs for ease of viewing. 
    2626<br /> 
    2727<br /> 
  • ccsweb/trunk/ccs_mods/graphs/config-part-div.js

    r1273 r1342  
    2121 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2222 */ 
    23  
     23errCount=0; 
    2424url = "https://" + site + "/mods/graphs/config-graphs.php"; 
    2525 
     
    2828    '#type' : function(element){ 
    2929        element.onchange = type_selected; 
     30    }, 
     31    '#varname' : function(element){ 
     32        element.onchange = validataVarname; 
     33    }, 
     34    '#colour' : function(element){ 
     35        element.onchange = validateColour; 
     36    }, 
     37        '#text' : function(element){ 
     38        element.onchange = validateText; 
     39    }, 
     40        '#cf' : function(element){ 
     41        element.onchange = validateCf; 
     42    }, 
     43        '#graph_order' : function(element){ 
     44        element.onchange = validateOrder; 
    3045    } 
     46     
    3147}; 
    3248 
    3349Behaviour.register(myrules); 
     50Behaviour.addLoadEvent(validateForm); 
     51 
     52function validataVarname(){ 
     53    type_o = $("type"); 
     54    if (type_o) 
     55        type = $F("type"); 
     56    box = document.getElementById("varname");   
     57    if (type == "VRULE"){ 
     58        if (box.value == ""){ 
     59            setError("varname", "Must set a time!"); 
     60            return; 
     61        } 
     62        var anum=/(^\d+$)|(^\d+\.\d+$)/ 
     63        if (!anum.test(box.value)){ 
     64            setError("varname", "Must be a number!"); 
     65            return; 
     66        } 
     67    } 
     68    if (box.value == ""){ 
     69        setError("varname", "Must be supplied!"); 
     70        return; 
     71    } 
     72    clearError("varname"); 
     73} 
     74function validateColour(){ 
     75    box = document.getElementById("colour");    
     76    if (box){ 
     77        if (box.value == ""){ 
     78            setError("colour", "Colour must be given!"); 
     79            return; 
     80        } 
     81        //Hex is required 
     82        var anum=/(^[0123456789ABCDEFabcdef]+$)|(^[0123456789ABCDEFabcdef]+\.[0123456789ABCDEFabcdef]+$)/ 
     83        if (!anum.test(box.value)){ 
     84            setError("colour", "Invalid Characters!"); 
     85            return; 
     86        } 
     87        if (box.value.length != 6){ 
     88            setError("colour", "Need 6 charactors!"); 
     89            return; 
     90        } 
     91    } 
     92 
     93    clearError("colour"); 
     94} 
     95function validateText(){ 
     96    type_o = $("type"); 
     97    if (type_o) 
     98        type = $F("type"); 
     99    box = document.getElementById("text");    
     100    if (box){ 
     101    if (box.value == ""){ 
     102        setError("text", "Chain must be given!"); 
     103        return; 
     104    }} 
     105         
     106    clearError("text"); 
     107} 
     108function validateCf(){ 
     109    clearError("cf"); 
     110} 
     111function validateOrder(){ 
     112    box = document.getElementById("graph_order");    
     113    if (box){ 
     114    if (box.value == ""){ 
     115        setError("order", "Must be given!"); 
     116        return; 
     117    } 
     118    var anum=/(^\d+$)|(^\d+\.\d+$)/ 
     119    if (!anum.test(box.value)){ 
     120        setError("order", "Must be a number!"); 
     121        return; 
     122    }} 
     123    clearError("order"); 
     124} 
     125 
    34126 
    35127// When a type is selected update the variables (and page) 
     
    66158    object.innerHTML = string; 
    67159    Behaviour.apply(); 
     160    validateForm(); 
    68161} 
     162 
     163function validateForm() 
     164{ 
     165    errCount=0; 
     166    validataVarname(); 
     167    validateColour(); 
     168    validateText(); 
     169    validateCf(); 
     170    validateOrder(); 
     171} 
  • ccsweb/trunk/ccs_mods/graphs/config-part-div.tpl

    r1341 r1342  
    2323 
    2424<tr>  
    25     <th width="200" >Type</th><td> 
     25    <th width="200">Type</th><td> 
    2626        <select id="type" name="type" /> 
    2727            <option value="DEF" {if $part.type == "DEF"}selected="selected"{/if}>DEF</option> 
     
    3535            <option value="LINE2" {if $part.type == "LINE2"}selected="selected"{/if}>LINE2</option> 
    3636            <option value="LINE3" {if $part.type == "LINE3"}selected="selected"{/if}>LINE3</option> 
    37             <option value="SHIFT" {if $part.type == "SHIFT"}selected="selected"{/if}>SHIFT</option> 
    3837            <option value="STACK" {if $part.type == "STACK"}selected="selected"{/if}>STACK</option> 
    3938            <option value="AREA" {if $part.type == "AREA"}selected="selected"{/if}>AREA</option> 
     
    4140</tr> 
    4241<tr>     
    43     <th width="200">Order</th> 
     42    <th width="200" id="order-header">Order</th> 
    4443    <td><input type="text" name="graph_order" id="graph_order" value="{$part.graph_order}"/>This field controls the order in which they are used during rendering. If two numbers are the same it is undefined what order they will be used.</td> 
    4544</tr> 
    46 {if $part.type == "LINE1" || $part.type == "LINE2" || $part.type == "LINE2" || $part.type == "AREA" || $part.type == "STACK"} 
     45{if $part.type == "LINE1" || $part.type == "LINE2" || $part.type == "LINE3" || $part.type == "AREA" || $part.type == "STACK"} 
    4746<tr>     
    48     <th width="200">Variable</th><td> 
     47    <th width="200" id="varname-header">Variable</th><td> 
    4948        <select name="varname" id="varname"> 
    5049        {foreach from=$vars item=var} 
     
    5453</td></tr> 
    5554<tr>     
    56     <th width="200">Colour</th> 
    57     <td><input type="text" name="colour" id="colour" value="{$part.colour}"/>The draw colour</td> 
     55    <th width="200" id="colour-header">Colour</th> 
     56    <td><input type="text" name="colour" id="colour" value="{$part.colour}"/>The draw colour in hex (RRGGBB eg FF0000 is red)</td> 
    5857</tr> 
    5958<tr>     
     
    6564{if $part.type == "HRULE"} 
    6665<tr>     
    67     <th width="200">Value</th> 
     66    <th width="200" id="varname-header">Value</th> 
    6867    <td><input type="text" name="varname" id="varname" value="{$part.varname}"/></td> 
    6968</tr> 
    7069<tr>     
    71     <th width="200">Colour</th> 
    72     <td><input type="text" name="colour" id="colour" value="{$part.colour}"/>The draw colour</td> 
     70    <th width="200" id="colour-header">Colour</th> 
     71    <td><input type="text" name="colour" id="colour" value="{$part.colour}"/>The draw colour in hex (RRGGBB eg FF0000 is red)</td> 
    7372</tr> 
    7473<tr>     
     
    7978{if $part.type == "VRULE"} 
    8079<tr>     
    81     <th width="200">Time</th> 
     80    <th width="200" id="varname-header">Time</th> 
    8281    <td><input type="text" name="varname" id="varname" value="{$part.varname}"/>In seconds since 1 Jan 1970</td> 
    8382</tr> 
    8483<tr>     
    85     <th width="200">Colour</th> 
    86     <td><input type="text" name="colour" id="colour" value="{$part.colour}"/>The draw colour</td> 
     84    <th width="200" id="colour-header">Colour</th> 
     85    <td><input type="text" name="colour" id="colour" value="{$part.colour}"/>The draw colour in hex (RRGGBB eg FF0000 is red)</td> 
    8786</tr> 
    8887<tr>     
     
    9493{if $part.type == "PRINT" || $part.type == "GPRINT"} 
    9594<tr>     
    96     <th width="200">Variable</th><td> 
     95    <th width="200" id="varname-header">Variable</th><td> 
    9796        <select name="varname" id="varname"> 
    9897        {foreach from=$vars item=var} 
     
    111110</tr> 
    112111<tr>     
    113     <th width="200">Statement</th> 
     112    <th width="200" id="text-header">Statement</th> 
    114113    <td><input type="text" name="text" id="text" value="{$part.text}"/></td> 
    115114</tr> 
     
    117116{if $part.type == "COMMENT"} 
    118117<tr>     
    119     <th width="200">Comment</th> 
     118    <th width="200" id="text-header">Comment</th> 
    120119    <td><input type="text" name="text" id="text" value="{$part.text}"/></td> 
    121120</tr> 
     
    123122{if $part.type == "DEF"} 
    124123<tr>     
    125     <th width="200">Variable</th> 
     124    <th width="200" id="varname-header">Variable</th> 
    126125    <td><input type="text" name="varname" id="varname" value="{$part.varname}"/>The variable name</td> 
    127126</tr> 
     
    147146{if $part.type == "CDEF"} 
    148147<tr>     
    149     <th width="200">Variable</th> 
     148    <th width="200" id="varname-header">Variable</th> 
    150149    <td><input type="text" name="varname" id="varname" value="{$part.varname}"/>The variable name</td> 
    151150</tr> 
    152151<tr>     
    153     <th width="200">Chain</th> 
     152    <th width="200" id="text-header">Chain</th> 
    154153    <td><input type="text" name="text" id="text" value="{$part.text}"/></td> 
    155154</td></tr>   
Note: See TracChangeset for help on using the changeset viewer.