Skip to content

Commit

Permalink
Dev: move inline style to css class in em_core
Browse files Browse the repository at this point in the history
Dev: this allow hidding error to user
Dev: TODO : really hide to user without admin function
  • Loading branch information
Shnoulle committed Dec 22, 2014
1 parent f33cc4f commit 45c4f4b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
44 changes: 25 additions & 19 deletions application/helpers/expressions/em_core_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1410,20 +1410,22 @@ public function GetPrettyPrintString()
$tokens = $this->RDP_tokens;
$errCount = count($errs);
$errIndex = 0;
$aClass=array();
if ($errCount > 0)
{
usort($errs,"cmpErrorTokens");
}
$errSpecificStyle= "style='border-style: solid; border-width: 2px; border-color: red;'";
$stringParts=array();
$numTokens = count($tokens);
$globalErrs=array();
$bHaveError=false;
while ($errIndex < $errCount)
{
if ($errs[$errIndex++][1][1]==0)
{
// General message, associated with position 0
$globalErrs[] = $errs[$errIndex-1][0];
$bHaveError=true;
}
else
{
Expand All @@ -1448,17 +1450,18 @@ public function GetPrettyPrintString()
}
if ($thisTokenHasError)
{
$stringParts[] = "<span title='" . implode('; ',$messages) . "' " . $errSpecificStyle . ">";
$stringParts[] = "<span title='" . implode('; ',$messages) . "' class='em-error'>";
$bHaveError=true;
}
switch ($token[2])
{
case 'DQ_STRING':
$stringParts[] = "<span title='" . implode('; ',$messages) . "' style='color: gray'>\"";
$stringParts[] = "<span title='" . implode('; ',$messages) . "' class='em-var-string'>\"";
$stringParts[] = $token[0]; // htmlspecialchars($token[0],ENT_QUOTES,'UTF-8',false);
$stringParts[] = "\"</span>";
break;
case 'SQ_STRING':
$stringParts[] = "<span title='" . implode('; ',$messages) . "' style='color: gray'>'";
$stringParts[] = "<span title='" . implode('; ',$messages) . "' class='em-var-string'>'";
$stringParts[] = $token[0]; // htmlspecialchars($token[0],ENT_QUOTES,'UTF-8',false);
$stringParts[] = "'</span>";
break;
Expand All @@ -1472,15 +1475,15 @@ public function GetPrettyPrintString()
$messages[] = $funcInfo[2];
$messages[] = $funcInfo[3];
}
$stringParts[] = "<span title='" . implode('; ',$messages) . "' style='color: blue; font-weight: bold'>";
$stringParts[] = "<span title='" . implode('; ',$messages) . "' class='em-function' >";
$stringParts[] = $token[0];
$stringParts[] = "</span>";
}
else
{
if (!$this->RDP_isValidVariable($token[0]))
{
$color = 'red';
$class = 'em-var-error';
$displayName = $token[0];
}
else
Expand Down Expand Up @@ -1568,30 +1571,29 @@ public function GetPrettyPrintString()
}
}
if ($this->groupSeq == -1 || $groupSeq == -1 || $questionSeq == -1 || $this->questionSeq == -1) {
$color = '#996600'; // tan
$class = 'em-var-static';
}
else if ($groupSeq > $this->groupSeq) {
$color = '#FF00FF '; // pink a likely error
elseif ($groupSeq > $this->groupSeq) {
$class = 'em-var-before em-var-diffgroup';
}
else if ($groupSeq < $this->groupSeq) {
$color = 'green';
elseif ($groupSeq < $this->groupSeq) {
$class = 'em-var-after ';
}
else if ($questionSeq > $this->questionSeq) {
$color = 'maroon'; // #228b22 - warning
elseif ($questionSeq > $this->questionSeq) {
$class = 'em-var-before em-var-inpage';
}
else {
$color = '#4C88BE'; // cyan that goes well with the background color
$class = 'em-var-after em-var-inpage';
}
}
// prevent EM prcessing of messages within span
$message = implode('; ',$messages);
$message = str_replace(array('{','}'), array('{ ', ' }'), $message);

$stringParts[] = "<span title='" . $message . "' style='color: ". $color . "; font-weight: bold'";
$stringParts[] = "<span title='" . $message . "' class='em-var {$class}'";
if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid)) {
// Modify this link to utilize a different framework
$editlink = Yii::app()->getController()->createUrl('admin/survey/sa/view/surveyid/' . $this->sid . '/gid/' . $gid . '/qid/' . $qid);
$stringParts[] = " onclick='window.open(\"" . $editlink . "\");'";
$stringParts[] = " data-link='{$editlink}'";
}
$stringParts[] = ">";
if ($this->sgqaNaming)
Expand All @@ -1613,7 +1615,7 @@ public function GetPrettyPrintString()
break;
case 'ASSIGN':
$messages[] = 'Assigning a new value to a variable';
$stringParts[] = "<span title='" . implode('; ',$messages) . "' style='color: red; font-weight: bold'>";
$stringParts[] = "<span title='" . implode('; ',$messages) . "' class='em-assign'>";
$stringParts[] = $token[0];
$stringParts[] = "</span>";
break;
Expand All @@ -1635,7 +1637,11 @@ public function GetPrettyPrintString()
++$errIndex;
}
}
return "<span style='background-color: #eee8aa;'>" . implode('', $stringParts) . "</span>";
App()->getClientScript()->registerCssFile(Yii::app()->getConfig('styleurl') . "expressions.css" );
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . "expression.js");
$sClass='em-expression';
$sClass.=($bHaveError)?" em-haveerror":"";
return "<span class='$sClass'>" . implode('', $stringParts) . "</span>";
}

/**
Expand Down
3 changes: 2 additions & 1 deletion scripts/admin/admin_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ function doToolTip()
});
}
});

/* Any other title take jquery ui tooltip */
$(document).tooltip();
}
// A function to encode any HTML for qtip
function htmlEncode(html){
Expand Down
8 changes: 8 additions & 0 deletions scripts/admin/expression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Manage javascript for expression administration
* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GNU/GPL License v2 or later
*/
$(document).ready(function(){
$('[data-link]').on('click',function(){
window.open($(this).data('link'));
});
});
11 changes: 11 additions & 0 deletions styles/expressions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.em-expression{background:#eee8aa /* palegoldenrod */ ;display:inline-block;font-weight: bold;border:1px dotted #ccc}
.em-haveerror{border-color: #ff4500}
.em-var-string{color: #808080 /* gray */}
.em-function{color: #0000ff /* blue */; }
.em-var-static{color:#a0522d /* sienna */}/* Static */
.em-var-before{color:#9370db /* mediumpurple*/ }/* Var used before set */
.em-var-after{color:#008000 /* green */}/* Var used after - no js except for survey */
.em-var-inpage{color:#4169e1 /* royalblue */} /* Javascript used in survey or group mode*/
.em-var-error{color: #ff4500}
.em-var-error{color: #ff0000 /* orangered */}
.em-error{border: 2px solid #ff0000; /* red */;}

0 comments on commit 45c4f4b

Please sign in to comment.