Changeset 5d73623 in iPeer


Ignore:
Timestamp:
2012-12-14T16:56:00-08:00 (6 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
491567c
Parents:
c88a90a
git-author:
Compass <pan.luo@…> (12/14/2012 03:04:00 PM)
git-committer:
Compass <pan.luo@…> (12/14/2012 04:56:00 PM)
Message:

Replaced simple eval preview form with real form

Unify the two forms and populated preview data in the view, instead of
element.

Location:
app/views
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • app/views/evaluations/simple_eval_form.ctp

    rc88a90a r5d73623  
    1 <script type="text/javascript" language="javascript">
    2   function updateCount(allPoints,commentsRequired) {
    3     <?php
    4       $ids = array();
    5       foreach($groupMembers as $row) {
    6         $user = $row['User'];
    7         array_push($ids, $user['id']);
    8       }
    9       foreach ($ids as $id) {
    10         echo "floatPoints = document.getElementById('point".$id."');";
    11         echo "intPoints = Math.round(parseFloat(floatPoints.value));";
    12         echo "floatPoints.value = intPoints;";
    13       }
    14       echo "var totalPoints = 0;\n";
    15       echo "var emptyComments = 0;\n";
    16       foreach ($ids as $id) {
    17         // counting total points
    18         echo "if ((!isNaN(parseFloat(document.getElementById('point".$id."').value)))) {";
    19         echo "totalPoints += parseFloat(document.getElementById('point".$id."').value);}\n";
    20         // counting total number of comments
    21         echo "if(document.getElementById('comment".$id."').value.length == 0) {";
    22         echo "emptyComments++;}\n";
    23       }
    24       echo "var submitButton = document.getElementById('submit0');";
    25       echo "if (totalPoints == parseFloat(allPoints)) {";
    26       echo "  if (commentsRequired == 0) {";
    27       echo "    $('statusMsg').innerHTML = '".__('All points are allocated.', true)."';";
    28 
    29       echo "    submitButton.disabled = false;";
    30       echo "  }";
    31       echo "  else if (commentsRequired == 1 && emptyComments != 0) {";
    32       echo "    $('statusMsg').innerHTML = '".__('All points are allocated.<br />There are still ', true)."<font color=red>' + emptyComments + '</font> ".__('comments to be filled.', true)." ';";
    33       echo "    submitButton.disabled = true;";
    34       echo "  }";
    35       echo "  else if (commentsRequired == 1 && emptyComments == 0) {";
    36       echo "    $('statusMsg').innerHTML = '".__('All points are allocated.<br />All comments are filled.', true)." ';";
    37       echo "    submitButton.disabled = false;";
    38       echo "  }";
    39       echo "}";
    40 
    41       echo "else if (totalPoints > parseFloat(allPoints)) {";
    42       echo "  diff = totalPoints - parseFloat(allPoints);";
    43       echo "  if (commentsRequired == 0) {";
    44       echo "    $('statusMsg').innerHTML = '".__('Too many points, need to unallocate', true)." <font color=red>' + diff + '</font> ".__('points.')." ';";
    45       echo "  }";
    46       echo "  else if (commentsRequired == 1 && emptyComments != 0) {";
    47       echo "    $('statusMsg').innerHTML = '".__('Too many points, need to unallocate', true)." <font color=red>' + diff + '</font> ".__('points.<br />There are still', true)." <font color=red>' + emptyComments + '</font> ".__('comments to be filled.', true)." ';";
    48       echo "  }";
    49       echo "  else if (commentsRequired == 1 && emptyComments == 0) {";
    50       echo "    $('statusMsg').innerHTML = '".__('Too many points, need to unallocate', true)." <font color=red>' + diff + '</font ".__('points.<br />All comments are filled.', true)." ';";
    51       echo "  }";
    52       echo "  submitButton.disabled = true;";
    53       echo "}";
    54 
    55       echo "else if (totalPoints < parseFloat(allPoints)) {";
    56       echo "  diff = parseFloat(allPoints) - totalPoints;";
    57       echo "  if (commentsRequired == 0) {";
    58       echo "    $('statusMsg').innerHTML = '".__('Please allocate', true)." <font color=green>' + diff + '</font> ".__('more points.', true)."';";
    59       echo "  }";
    60       echo "  else if (commentsRequired == 1 && emptyComments != 0) {";
    61       echo "    $('statusMsg').innerHTML = '".__('Please allocate', true)." <font color=green>' + diff + '</font>".__(' more points.<br />There are still', true)." <font color=red>' + emptyComments+ '</font>".__('comments to be filled.', true)."';";
    62       echo "  }";
    63       echo "  else if (commentsRequired == 1 && emptyComments == 0) {";
    64       echo "    $('statusMsg').innerHTML = '".__('Please allocate', true)." <font color=green>' + diff + '</font>".__(' more points.<br />All comments are filled.', true)."';";
    65       echo "  }";
    66       echo "  submitButton.disabled = true;";
    67       echo "}";
    68 
    69       echo "else {submitButton.disabled = true;}";
    70 
    71       echo "$('total').innerHTML = totalPoints;";
    72     ?>
    73   }
    74 
    75         function distribute() {
    761<?php
    77       echo "\n";
    78       for ($z = 0; $z < count($groupMembers); $z++) {
    79           $user = $groupMembers[$z]['User'];
    80           $id = $user['id'];
    81           echo "var v$z = parseInt($('score$id').innerHTML);";
    82           echo "\n";
    83       }
    84       for ($z = 0; $z < count($groupMembers); $z++) {
    85           $user = $groupMembers[$z]['User'];
    86           //TODO: if(!is_bool($groupMembers[$z]) && $groupMembers[$z]!==NULL){ //happens with groups of size1
    87           $id = $user['id']; // this is a  null object for some reason
    88           $string = "document.forms['evalForm'].elements['point$id'].value = Math.floor((v$z/(";
    89           echo "\n";
    90           for ($a = 0; $a < count($groupMembers); $a++) {
    91               $plus = ( $a == 0 ? "" : "+" );
    92               $string .= $plus . "v$a";
    93           }
    94 
    95           $total = $remaining;
    96           $string .= "))*$total);";
    97           echo $string;
    98           echo "\n";
    99           echo "var s$z = parseFloat(document.forms['evalForm'].elements['point$id'].value);";
    100           //}
    101       }
    102       echo "\n";
    103 
    104       $t_string = "$('total').innerHTML = Math.round(";
    105       for ($b = 0; $b < count($groupMembers); $b++) {
    106           $plus = ( $b == 0 ? "" : "+" );
    107           $t_string .= $plus . "s$b";
    108       }
    109 
    110       $t_string .= ");";
    111       echo $t_string;
    112       $com_req = $event['Event']['com_req'];
    113       echo "updateCount($remaining, $com_req);";
    114 ?>
    115     }<?php
    116 ?>
    117     //-->
    118 </script>
    119 
    120 <?php echo empty($params['data']['Evaluation']['id']) ? null : $html->hidden('Evaluation/id'); ?>
    121 <form name="evalForm" id="evalForm" method="POST" action="<?php echo $html->url('makeEvaluation/'.$event['Event']['id'].'/'.$event['Group']['id']) ?>">
    122 <input type="hidden" name="event_id" value="<?php echo $event['Event']['id']?>"/>
    123 <input type="hidden" name="group_id" value="<?php echo $event['Group']['id']?>"/>
    124 <input type="hidden" name="course_id" value="<?php echo $courseId?>"/>
    125 <input type="hidden" name="data[Evaluation][evaluator_id]" value="<?php echo $userId ?>"/>
    126 <input type="hidden" name="evaluateeCount" value="<?php echo $evaluateeCount?>"/>
    127 
    128 <table class="standardtable">
    129     <tr>
    130         <th colspan="4"><?php __('Evaluation Event Detail')?></th>
    131     </tr>
    132     <tr>
    133         <td width="10%"><?php __('Evaluator')?>:</td>
    134         <td width="25%"><?php echo $fullName ?></td>
    135         <td width="10%"><?php __('Evaluating')?>:</td>
    136         <td width="25%"><?php echo $event['Group']['group_name'] ?></td>
    137     </tr>
    138     <tr>
    139         <td><?php __('Event Name')?>:</td>
    140         <td><?php echo $event['Event']['title'] ?></td>
    141         <td><?php __('Due Date')?>:</td>
    142         <td><?php echo Toolkit::formatDate($event['Event']['due_date']) ?></td>
    143     </tr>
    144     <tr>
    145         <td><?php __('Description')?>:&nbsp;</td>
    146         <td colspan="3"><?php echo $event['Event']['description'] ?></td>
    147     </tr>
    148     <tr>
    149         <td colspan="4" style="text-align: left;">
    150             <span class="instruction-icon"><?php __(' Instructions')?>:</span>
    151             <ul class="instructions">
    152             <li><?php __("Rate your peer's relative performance by using the slider. [Weight 1-10]")?></li>
    153             <li><?php __('Click "Distribute" button to distribute points.')?></li>
    154             <li><?php __('Allocate any remaining point.')?></li>
    155             <li><?php __('Enter Comments')?> <?php echo  $event['Event']['com_req']? '<font color="red"> (Must) </font>' : '(Optional)' ;?> .</li>
    156             <li><font color="red"><blink><?php __('NOTE:')?></blink></font> <?php __('"Submit Evaluation" button will only be enabled when all points, and comments (if required), are filled!')?></li>
    157             </ul>
    158 
    159             <div style="text-align:left; margin-left:3em;"><a href="#" onClick="javascript:$('penalty').toggle();return false;">( <?php __('Show/Hide late penalty policy')?> )</a></div>
    160             <div id ="penalty" style ="border:1px solid red; margin: 0.5em 0 0 3em; width: 450px; padding:0.5em; color:darkred; display:none">
    161 
    162 <?php if(!empty($penalty)){
    163     foreach($penalty as $day){
    164         $mult = ($day['Penalty']['days_late']>1)?'s':'';
    165         echo $day['Penalty']['days_late'].' day'.$mult.' late: '.$day['Penalty']['percent_penalty'].'% deduction. </br>';
    166     }
    167     echo $penaltyFinal['Penalty']['percent_penalty'].'% is deducted afterwards.';
    168 } else {
    169     echo 'No penalty is specified for this evaluation.';
    170 }
    171 
    172 ?>
    173 
    174   </div>
    175         </td>
    176     </tr>
    177 </table>
    178 
    179 
    180     </br>
    181 <table class="standardtable">
    182     <tr>
    183         <th width="20%"><?php __('Member(s)')?></th>
    184         <th width="20%"><?php __('Relative Weight')?></th>
    185         <th width="15%"><?php __('Mark')?></th>
    186         <th><?php __('Comment')?>  <?php echo $event['Event']['com_req']? '<font color=red>*</font>' : __('(Optional)', true) ;?></th>
    187     </tr>
    188 <?php foreach ($groupMembers as $row): $user = $row['User'];?>
    189     <tr>
    190         <td><?php echo $user['first_name'].' '.$user['last_name']?>
    191       <input type="hidden" name="memberIDs[]" value="<?php echo $user['id']?>"/></td>
    192       <td width="110">
    193         <table><tr>
    194         <td width="5">Min.</td>
    195         <td width="110">
    196         <div id="track<?php echo $user['id']?>" style="width:120px;background-color:#aaa;height:10px;">
    197           <div id="handle<?php echo $user['id']?>" style="width:10px;height:15px;background-color:#fa7e04;cursor:move;"> </div>
    198         </div>
    199         <div style="height:10px;padding-top:10px;" align="center" id="score<?php echo $user['id']?>"></div>&nbsp;&nbsp;
    200       </td>
    201       <td width="5">Max.</td>
    202       </tr></table>
    203                 </td>
    204                  <td><input type="text" name="points[]" id="point<?php echo $user['id']?>" value="<?php echo empty($params['data']['Evaluation']['point'.$user['id']])? '' : $params['data']['Evaluation']['point'.$user['id']] ?>" size="5" onchange="updateCount(<?php echo $remaining?>,<?php echo $event['Event']['com_req']?>);">
    205     </td>
    206                  <td><input type="text" name="comments[]" id="comment<?php echo $user['id']?>" value="<?php echo empty($params['data']['Evaluation']['comment_'.$user['id']])? '' : $params['data']['Evaluation']['comment_'.$user['id']] ?>" size="50" onchange="updateCount(<?php echo $remaining?>,<?php echo $event['Event']['com_req']?>);">
    207       <script type="text/javascript" language="javascript">
    208 
    209             function onSlide(v){
    210                 $(<?php echo "'score".$user['id']."'"?>).innerHTML=(v+1);
    211             }
    212 
    213             var defaultValue = 4;
    214 
    215             new Control.Slider(
    216                 <?php echo "'handle".$user['id']."'"?>,
    217                 <?php echo "'track".$user['id']."'"?>,
    218                 {values:        [0,1,2,3,4,5,6,7,8,9],
    219                  range:         $R(0,9),
    220                  increment:     10,
    221                  sliderValue:   defaultValue,
    222                  onSlide:       onSlide,
    223                  onChange:      onSlide
    224                 }
    225             );
    226 
    227             onSlide(defaultValue);
    228     </script></td>
    229     </tr>
    230     <?php endforeach; ?>
    231     <tr>
    232         <td colspan="3" align="right" id="statusMsg"></td>
    233         <td>
    234           <?php __('Points Allocated/Total:')?>&nbsp;
    235           <div id="total" style="padding-top: 5px;display: inline;">0</div> /
    236           <div id="remaining" style="padding-top: 5px;display: inline;" ><?php echo $remaining?></div>&nbsp;
    237           <input type="button" name="distr" id="distr_button" value="<?php __('Distribute')?>" onClick="distribute()"/>
    238         </td>
    239     </tr>
    240 
    241   <tr>
    242     <td colspan="4" align="center"><?php
    243       if (!isset($preview)) {
    244         echo $form->submit(__('Submit Evaluation', true), array('id' => 'submit0', 'disabled' => 'true', 'onClick' => "javascript:return confirm('".__('Once you submit the input, you cannot change them. Please review your input before submitting. Are you sure you want to submit?', true)."')", 'div'=>'submitSimple'));
    245       }
    246       ?></td>
    247     </tr>
    248 </table>
    249 </form>
     2echo $this->element('evaluations/simple_eval_form');
  • app/views/simple_evaluations/view.ctp

    rc88a90a r5d73623  
    1 <table width="100%"  border="0" cellpadding="8" cellspacing="0" bgcolor="#FFFFFF">
    2   <tr>
    3     <td>
    4     <form name="frm" id="frm" method="POST" action="<?php echo $html->url(empty($data['SimpleEvaluation']['id'])?'add':'edit') ?>" onSubmit="return validate()">
    5       <?php echo empty($data['SimpleEvaluation']['id']) ? null : $this->Form->hidden('id'); ?>
    6       <input type="hidden" name="required" id="required" value="point_per_member" />
    7       <table width="95%" border="0" align="center" cellpadding="4" cellspacing="2">
    8         <tr class="tableheader">
    9           <td colspan="3" align="center"><?php __('View Simple Evaluation')?></td>
    10         </tr>
    11         <tr class="tablecell2">
    12                 <td width="254" id="newtitle_label"><?php __('Evaluation Name')?>:</td>
    13                 <td width="405" align="left">
    14                 <?php echo $data['SimpleEvaluation']['name']  ?>
    15           </td>
    16           <td width="243" id="newtitle_msg" class="error"/>
    17         </tr>
    18         <tr class="tablecell2">
    19                 <td id="description_label"><?php __('Description')?>:</td>
    20                 <td align="left"><?php echo $data['SimpleEvaluation']['description']  ?></td>
    21                 <td id="description_msg" class="error"/>
    22         </tr>
    23         <tr class="tablecell2">
    24                 <td id="point_per_member_label"><?php __('Base Point Per Member')?>:</td>
    25                 <td align="left"><?php echo $data['SimpleEvaluation']['point_per_member']
    26                 ?>
    27                 </td>
    28                 <td id="point_per_member_msg" class="error"/>
    29         </tr>
    30         <tr class="tablecell2">
    31             <td id="availability"><?php __('Availability')?>:</td>
    32             <td align="left"><?php echo $data['SimpleEvaluation']['availability']
    33             ?>
    34             </td>
    35         </tr>
    36         <tr class="tablecell2">
    37           <td colspan="3" align="center">
    38             <?php if (!empty($popUp) && $popUp) { ?>
    39             <input type="button" name="Close" value="<?php __('Close')?>" onClick="window.close()">
    40             <?php } else { ?>
    41             <input type="button" name="Back" value="<?php __('Back')?>" onClick="javascript:(history.length > 1) ? history.back() : window.close();">
    42             <?php }?>
     1<form name="frm" id="frm" method="POST" action="<?php echo $html->url(empty($data['SimpleEvaluation']['id'])?'add':'edit') ?>" onSubmit="return validate()">
     2<?php echo empty($data['SimpleEvaluation']['id']) ? null : $this->Form->hidden('id'); ?>
     3<input type="hidden" name="required" id="required" value="point_per_member" />
    434
    44         </td>
    45       </table>
     5<table class="standardtable">
     6    <tr><th colspan="2" align="center"><?php __('View Simple Evaluation')?></th></tr>
     7    <tr>
     8        <td width="254" id="newtitle_label"><?php __('Evaluation Name')?>:</td>
     9        <td align="left"><?php echo $data['SimpleEvaluation']['name']?></td>
     10    </tr>
     11    <tr>
     12        <td id="description_label"><?php __('Description')?>:</td>
     13        <td><?php echo $data['SimpleEvaluation']['description']  ?></td>
     14    </tr>
     15    <tr>
     16        <td id="point_per_member_label"><?php __('Base Point Per Member')?>:</td>
     17        <td><?php echo $data['SimpleEvaluation']['point_per_member']?></td>
     18    </tr>
     19    <tr>
     20        <td id="availability"><?php __('Availability')?>:</td>
     21        <td><?php echo $data['SimpleEvaluation']['availability']?></td>
     22    </tr>
     23    <tr>
     24      <td colspan="2" align="center">
     25        <?php if (!empty($popUp) && $popUp) { ?>
     26        <input type="button" name="Close" value="<?php __('Close')?>" onClick="window.close()">
     27        <?php } else { ?>
     28        <input type="button" name="Back" value="<?php __('Back')?>" onClick="javascript:(history.length > 1) ? history.back() : window.close();">
     29        <?php }?>
     30    </td>
     31</table>
    4632
    4733</form>
    48 </td>
    49 </tr>
     34
     35<br />
     36
     37<table class="standardtable">
     38  <tr>
     39    <th onclick="$('rpreview').toggle();">
     40        <?php echo $html->image('layout/icon_ipeer_logo.gif',array('border'=>'0','alt'=>'icon_ipeer_logo'))?><?php __(' Simple Evaluation Preview')?>
     41    </th>
     42  </tr>
    5043</table>
    5144
    52 
    53 
    54 <table class="title" width="100%"  border="0" cellspacing="0" cellpadding="0">
    55   <tr>
    56   <td><?php echo $html->image('layout/icon_ipeer_logo.gif',array('border'=>'0','alt'=>'icon_ipeer_logo'))?><?php __(' Simple Evaluation Preview')?> </td>
    57   <td><div align="right"><a href="#rpreview" onclick="showhide('rpreview'); toggle(this);"><?php echo empty($data) ? '[+]' : '[-]'; ?></a></div></td>
    58   </tr>
    59 </table>
    60 <div id="rpreview" <?php echo empty($data) ? 'style="display: none; background: #FFF;">' : 'style="display: block; background: #FFF;">'; ?>
    61 <br />
    62 
    63 <br />
     45<div id="rpreview" style="display: none;">
    6446<?php
    65 //$params = array('controller'=>'simpleevaluations','data'=>$this->controller->EvaluationHelper->formatEventObj($data), 'evaluate'=>0);
    66 echo $this->element('evaluations/simple_preview', array('current_user' => $user,
    67                                                         'course_id' => 0));
     47echo $this->element('evaluations/simple_eval_form', array(
     48    'event' => array(
     49        'Event' => array(
     50            'id' => 0,
     51            'title' => 'Preview Event',
     52            'due_date' => Toolkit::formatDate(time()+(5*24*60*60)),
     53            'description' => 'Preview for simple evaluation event.',
     54            'com_req' => true,
     55        ),
     56        'Group' => array(
     57            'id' => 0,
     58            'group_name' => 'Demo Group',
     59        ),
     60    ),
     61    'groupMembers' => array(
     62        array(
     63            'User' => array(
     64                'id' => 1,
     65                'first_name' => 'Demo',
     66                'last_name'  => 'Student1',
     67            ),
     68        ),
     69        array(
     70            'User' => array(
     71                'id' => 2,
     72                'first_name' => 'Demo',
     73                'last_name'  => 'Student2',
     74            ),
     75        ),
     76        array(
     77            'User' => array(
     78                'id' => 3,
     79                'first_name' => 'Demo',
     80                'last_name'  => 'Student3',
     81            ),
     82        ),
     83    ),
     84    'courseId' => 0,
     85    'userId' => 0,
     86    'evaluateeCount' => 2,
     87    'fullName' => User::get('full_name'),
     88    'remaining' => $data['SimpleEvaluation']['point_per_member'] * 3,
     89    'preview' => true,
     90));
    6891?>
    6992</div>
Note: See TracChangeset for help on using the changeset viewer.