Skip to content

Commit

Permalink
Dev: Refactorisation of admin javascript part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jul 20, 2018
1 parent fe97c13 commit 0169d43
Show file tree
Hide file tree
Showing 57 changed files with 35,132 additions and 122 deletions.
2 changes: 1 addition & 1 deletion application/config/packages.php
Expand Up @@ -184,7 +184,7 @@
'js' => array(
'js/confirmdeletemodal.js',
'js/bootstrap-remote-modals.js',
'js/admin_core.js',
'build/adminbasics.js',
'js/notifications.js',
),
'depends' => array(
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/ExpressionValidate.php
Expand Up @@ -84,7 +84,7 @@ public function quota($iSurveyId, $quota, $lang = null)
$this->getController()->layout = $this->layout;
$this->getController()->pageTitle = gT("Validate quota");

$this->getController()->render("/admin/expressions/validationList", $aData);
$this->getController()->renderPartial("/admin/expressions/validationList", $aData);
}
/**
* Check the Expression in email
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/dataentry.php
Expand Up @@ -634,7 +634,7 @@ public function editdata($subaction, $id, $surveyid)
array(
'class' => 'popupdate',
'size' => '12',
'onkeypress' => 'return goodchars(event,\''.$goodchars.'\')'
'onkeypress' => 'return window.LS.goodchars(event,\''.$goodchars.'\')'
)
);
/*
Expand Down Expand Up @@ -666,7 +666,7 @@ public function editdata($subaction, $id, $surveyid)
$aDataentryoutput .= CHtml::hiddenField('dateformat'.$fname['fieldname'], $dateformatdetails['jsdate'],
array('id' => "dateformat{$fname['fieldname']}")
);
// $aDataentryoutput .= "\t<input type='text' class='popupdate' size='12' name='{$fname['fieldname']}' value='{$thisdate}' onkeypress=\"return goodchars(event,'".$goodchars."')\"/>\n";
// $aDataentryoutput .= "\t<input type='text' class='popupdate' size='12' name='{$fname['fieldname']}' value='{$thisdate}' onkeypress=\"return window.LS.goodchars(event,'".$goodchars."')\"/>\n";
// $aDataentryoutput .= "\t<input type='hidden' name='dateformat{$fname['fieldname']}' id='dateformat{$fname['fieldname']}' value='{$dateformatdetails['jsdate']}' />\n";
} else {
$aDataentryoutput .= CHtml::textField($fname['fieldname'], $thisdate);
Expand Down Expand Up @@ -963,7 +963,7 @@ public function editdata($subaction, $id, $surveyid)
break;
case "N": //NUMERICAL TEXT
$aDataentryoutput .= "\t<input type='text' name='{$fname['fieldname']}' value='{$idrow[$fname['fieldname']]}' "
."onkeypress=\"return goodchars(event,'0123456789.,')\" />\n";
."onkeypress=\"return window.LS.goodchars(event,'0123456789.,')\" />\n";
break;
case "S": //SHORT FREE TEXT
$aDataentryoutput .= "\t<input type='text' name='{$fname['fieldname']}' value='"
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -1773,7 +1773,7 @@ private function _tabResourceManagement($oSurvey)
global $sCKEditorURL;

// TAB Uploaded Resources Management
$ZIPimportAction = " onclick='if (validatefilename(this.form,\"".gT('Please select a file to import!', 'js')."\")) { this.form.submit();}'";
$ZIPimportAction = " onclick='if (window.LS.validatefilename(this.form,\"".gT('Please select a file to import!', 'js')."\")) { this.form.submit();}'";
if (!function_exists("zip_open")) {
$ZIPimportAction = " onclick='alert(\"".gT("The ZIP library is not activated in your PHP configuration thus importing ZIP files is currently disabled.", "js")."\");'";
}
Expand Down
Expand Up @@ -147,7 +147,7 @@
'htmlOptions'=>array('style'=>'cursor: pointer;', 'class'=>'hoverAction grid-view'),
//'selectionChanged'=>"function(id){window.location='" . Yii::app()->urlManager->createUrl('admin/survey/sa/view/surveyid' ) . '/' . "' + $.fn.yiiGridView.getSelection(id.split(',', 1));}",
'ajaxUpdate' => true,
'afterAjaxUpdate' => 'doToolTip',
'afterAjaxUpdate' => 'window.LS.doToolTip',
'template' => $this->template,
));
?>
Expand Down
16 changes: 6 additions & 10 deletions application/helpers/common_helper.php
Expand Up @@ -323,21 +323,17 @@ function convertGETtoPOST($url)
$calledscript = array_shift($stack);
$query = array_shift($stack);
$aqueryitems = explode('&', $query);
$arrayParam = Array();
$arrayVal = Array();
$postArray = [];

foreach ($aqueryitems as $queryitem) {
$stack = explode('=', $queryitem);
$paramname = array_shift($stack);
$value = array_shift($stack);
$arrayParam[] = "'".$paramname."'";
$arrayVal[] = substr($value, 0, 9) != "document." ? "'".$value."'" : $value;
}
// $Paramlist = "[" . implode(",",$arrayParam) . "]";
// $Valuelist = "[" . implode(",",$arrayVal) . "]";
$Paramlist = "[".implode(",", $arrayParam)."]";
$Valuelist = "[".implode(",", $arrayVal)."]";
$callscript = "sendPost('$calledscript','',$Paramlist,$Valuelist);";
$postArray[$paramname] = substr($value, 0, 9) != "document." ? "'".$value."'" : $value;
}

$callscript = "window.LS.sendPost('".$calledscript."','".json_encode($postArray)."');";

return $callscript;
}

Expand Down
2 changes: 1 addition & 1 deletion application/helpers/qanda_helper.php
Expand Up @@ -1125,7 +1125,7 @@ function do_date($ia)
'dateformatdetails' => $dateformatdetails['dateformat'],
'dateformatdetailsjs' => $dateformatdetails['jsdate'],
'dateformatdetailsphp' => $dateformatdetails['phpdate'],
'goodchars' => "", // "return goodchars(event,'".$goodchars."')", // This won't work with non-latin keyboards
'goodchars' => "", // "return window.LS.goodchars(event,'".$goodchars."')", // This won't work with non-latin keyboards
'checkconditionFunction' => $checkconditionFunction.'(this.value, this.name, this.type)',
'language' => App()->language,
'hidetip' => trim($aQuestionAttributes['hide_tip']) == 0,
Expand Down
2 changes: 1 addition & 1 deletion application/models/TokenDynamic.php
Expand Up @@ -864,7 +864,7 @@ public function getbuttons()
&& $this->participant_id != ""
&& Permission::model()->hasGlobalPermission('participantpanel', 'read')) {

$onClick = "sendPost('".App()->createUrl('admin/participants/sa/displayParticipants')."','',['searchcondition'],['participant_id||equal||{$this->participant_id}']);";
$onClick = "window.LS.sendPost('".App()->createUrl('admin/participants/sa/displayParticipants')."',false,{'searchcondition': 'participant_id||equal||{$this->participant_id}'});";
$button .= '<a class="btn btn-default btn-xs" href="#" role="button" data-toggle="tooltip" title="'.gT('View this person in the central participants database').'" onclick="'.$onClick.'"><span class="icon-cpdb" ></span></a>';
} else {
$button .= '<span class="btn btn-default btn-xs disabled blank_button" href="#"><span class="fa-fw fa" ><!-- Display participant in CPDB--></span></span>';
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/conditions/includes/copyform.php
Expand Up @@ -44,7 +44,7 @@ function prepareCopyconditions() {
$('input:checked[name^=\"aConditionFromScenario\"]').each(function(i,val) {
var thecid = val.value;
var theform = document.getElementById('copyconditions');
addHiddenElement(theform,'copyconditionsfrom[]',thecid);
window.LS.addHiddenElement(theform,'copyconditionsfrom[]',thecid);
return true;
});
}
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/dataentry/content_view.php
Expand Up @@ -507,7 +507,7 @@ function updateJSON<?php echo $fieldname; ?>() {
}
$title = gT('Only numbers may be entered in this field.');

echo $prefix; ?><input type='text' name='<?php echo $fieldname; ?>' size='<?php echo $tiwidth; ?>' title='<?php echo $title; ?>' <?php echo $maxlength; ?> onkeypress="return goodchars(event,'-0123456789<?php echo $acomma; ?>')" /><?php echo $suffix;
echo $prefix; ?><input type='text' name='<?php echo $fieldname; ?>' size='<?php echo $tiwidth; ?>' title='<?php echo $title; ?>' <?php echo $maxlength; ?> onkeypress="return window.LS.goodchars(event,'-0123456789<?php echo $acomma; ?>')" /><?php echo $suffix;
echo '</div>';
break;

Expand Down Expand Up @@ -544,7 +544,7 @@ function updateJSON<?php echo $fieldname; ?>() {
{
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
$numbersonly = 'onkeypress="return goodchars(event,\'-0123456789'.$sSeparator.'\')"';
$numbersonly = 'onkeypress="return window.LS.goodchars(event,\'-0123456789'.$sSeparator.'\')"';
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions application/views/admin/export/statistics_subviews/_question.php
Expand Up @@ -85,10 +85,10 @@
."</div>\n";?>

<span class='smalltext'><?php eT("Number greater than");?>:</span><br />
<?php echo CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array('onkeypress'=>"return goodchars(event,'0123456789.,')"));?>
<?php echo CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array('onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')"));?>
<br>
<span class='smalltext'><?php eT("Number less than");?>:</span><br>
<?php echo CHtml::textField($myfield3,isset($_POST[$myfield3])?$_POST[$myfield3]:'',array('onkeypress'=>"return goodchars(event,'0123456789.,')"));?>
<?php echo CHtml::textField($myfield3,isset($_POST[$myfield3])?$_POST[$myfield3]:'',array('onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')"));?>
<br>
<?php
}
Expand Down Expand Up @@ -194,10 +194,10 @@
$myfield2="{$myfield}G";
$myfield3="{$myfield}L";
echo "\t<span class='smalltext'>".gT("Number greater than").":</span><br />\n"
.CHtml::textField('N'.$myfield2,isset($_POST[$myfield2])?'N'.$_POST[$myfield2]:'',array( 'onkeypress'=>"return goodchars(event,'0123456789.,')" ))
.CHtml::textField('N'.$myfield2,isset($_POST[$myfield2])?'N'.$_POST[$myfield2]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
."\t<br />\n"
."\t<span class='smalltext'>".gT("Number less than").":</span><br />\n"
.CHtml::textField('N'.$myfield3,isset($_POST[$myfield3])?'N'.$_POST[$myfield3]:'',array( 'onkeypress'=>"return goodchars(event,'0123456789.,')" ))
.CHtml::textField('N'.$myfield3,isset($_POST[$myfield3])?'N'.$_POST[$myfield3]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
."\t<br />\n";

//put field names into array
Expand All @@ -211,10 +211,10 @@
$myfield2 = "{$myfield}G";
$myfield3 = "{$myfield}L";
echo "\t<span class='smalltext'>".gT("Number of files greater than").":</span><br />\n"
.CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array( 'onkeypress'=>"return goodchars(event,'0123456789.,')" ))
.CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
."<br />\n"
."\t<span class='smalltext'>".gT("Number of files less than").":</span><br />\n"
.CHtml::textField($myfield3,isset($_POST[$myfield3])?$_POST[$myfield3]:'',array( 'onkeypress'=>"return goodchars(event,'0123456789.,')" ))
.CHtml::textField($myfield3,isset($_POST[$myfield3])?$_POST[$myfield3]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
."<br />\n";
break;

Expand Down
Expand Up @@ -7,15 +7,15 @@
<div class='form-group'>
<label class="col-sm-4 control-label" for='idG'><?php eT("Greater than:"); ?></label>
<div class='col-sm-8'>
<input class="form-control" type='number' id='idG' name='idG' size='10' value='<?php if (isset($_POST['idG'])){ echo sanitize_int($_POST['idG']);} ?>' onkeypress="return goodchars(event,'0123456789')" />
<input class="form-control" type='number' id='idG' name='idG' size='10' value='<?php if (isset($_POST['idG'])){ echo sanitize_int($_POST['idG']);} ?>' onkeypress="returnwindow.LS.goodchars(event,'0123456789')" />
</div>
</div>
</div>
<div class="row ls-space margin top-5">
<div class='form-group'>
<label class="col-sm-4 control-label" for='idL'><?php eT("Less than:"); ?></label>
<div class='col-sm-8'>
<input class="form-control" type='number' id='idL' name='idL' size='10' value='<?php if (isset($_POST['idL'])) { echo sanitize_int($_POST['idL']);} ?>' onkeypress="return goodchars(event,'0123456789')" />
<input class="form-control" type='number' id='idL' name='idL' size='10' value='<?php if (isset($_POST['idL'])) { echo sanitize_int($_POST['idL']);} ?>' onkeypress="returnwindow.LS.goodchars(event,'0123456789')" />
</div>
</div>
</div>
Expand Down
Expand Up @@ -54,7 +54,7 @@
'class'=>'form30',
'name'=>'importlabelresources',
'enctype'=>'multipart/form-data',
'onsubmit'=>'return validatefilename(this, "'.gT('Please select a file to import!', 'js').'");'
'onsubmit'=>'return window.LS.validatefilename(this, "'.gT('Please select a file to import!', 'js').'");'
)
);
?>
Expand All @@ -74,7 +74,7 @@
<input class="btn btn-default" type='button' value='<?php eT("Import resources ZIP archive") ?>' <?php
echo !function_exists("zip_open")
? "onclick='alert(\"" . gT("The ZIP library is not activated in your PHP configuration thus importing ZIP files is currently disabled.", "js") . "\");'"
: "onclick='if (validatefilename(this.form,\"" . gT('Please select a file to import!', 'js') . "\")) { this.form.submit();}'"
: "onclick='if (window.LS.validatefilename(this.form,\"" . gT('Please select a file to import!', 'js') . "\")) { this.form.submit();}'"
?>/>
</div>
</li>
Expand Down
Expand Up @@ -214,7 +214,7 @@
if(result.success){
formGroup.fadeOut(400, function(){formGroup.remove()});
} else {
notifyFader(result.errorMessage, 'well-lg bg-danger text-center');
window.LS.notifyFader(result.errorMessage, 'well-lg bg-danger text-center');
}
}
})
Expand Down
42 changes: 26 additions & 16 deletions application/views/admin/quotas/viewquotas_quota_actions.php
Expand Up @@ -18,19 +18,29 @@
<span class='fa fa-trash text-danger'></span>
</a>
<?php } ?>
<?php if (Permission::model()->hasSurveyPermission($oSurvey->getPrimaryKey(), 'quotas','update')) {
echo CHtml::link(CHtml::tag('span', array(
'class' => 'fa fa-tasks',
), ''
), array(
'admin/validate',
'sa'=>'quota',
'sid'=>$oSurvey->getPrimaryKey(),
'quota'=>$oQuota->getPrimaryKey(),
), array(
'class'=>'btn btn-default',
'title'=>sprintf(gT("Validation of quota %s"),$oQuota->name),
'target'=>'dialog',
'data-tooltip' => 'true'
));
}
<?php if (Permission::model()->hasSurveyPermission($oSurvey->getPrimaryKey(), 'quotas','update')) { ?>
<a
href='#'
data-remote-link="<?=App()->createUrl('admin/validate/', ["sa" => 'quota', 'sid'=>$oSurvey->getPrimaryKey(), 'quota'=>$oQuota->getPrimaryKey()])?>"
class="btn btn-default selector__quota_open_validation"
data-tooltip="true"
title="<?=sprintf(gT("Validation of quota %s"),$oQuota->name)?>"
data-toggel="modal"
data-target="quotaValidation"
>
<i class='fa fa-tasks'></i>
</a>
<?php } ?>

<?php
Yii::app()->getClientScript()->registerScript('quotas_load_validationmodal', "
$('.selector__quota_open_validation').remoteModal({
saveButton: false,
}, {
closeIcon : '<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><span aria-hidden=\"true\">&times;</span></button>',
closeButton : '<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">".gT("Close")."</button>',
saveButton : '<button type=\"button\" class=\"btn btn-primary\">".gT("Close")."</button>'
})
", LSYii_ClientScript::POS_POSTSCRIPT);

?>
2 changes: 1 addition & 1 deletion application/views/admin/responses/browsetimerow_view.php
Expand Up @@ -40,7 +40,7 @@
'htmlOptions' => array('class' => 'time-statistics-table'),

'ajaxUpdate' => true,
'afterAjaxUpdate' => 'doToolTip',
'afterAjaxUpdate' => 'window.LS.doToolTip',

// Number of row per page selection
'summaryText'=>gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'),
Expand Down
Expand Up @@ -9,7 +9,7 @@
<h3><?php eT("Import a question"); ?></h3>
<div class="row">
<div class="col-lg-12">
<?php echo CHtml::form(array("admin/questions/sa/import"), 'post', array('id'=>'importquestion', 'class'=>'', 'name'=>'importquestion', 'enctype'=>'multipart/form-data','onsubmit'=>"return validatefilename(this, '".gT("Please select a file to import!",'js')."');")); ?>
<?php echo CHtml::form(array("admin/questions/sa/import"), 'post', array('id'=>'importquestion', 'class'=>'', 'name'=>'importquestion', 'enctype'=>'multipart/form-data','onsubmit'=>"return window.LS.validatefilename(this, '".gT("Please select a file to import!",'js')."');")); ?>
<div class="form-group">
<label class=" control-label" for='the_file'><?php eT("Select question file (*.lsq):");
echo '<br>'.sprintf(gT("(Maximum file size: %01.2f MB)"),getMaximumFileUploadSize()/1024/1024);?>
Expand Down
Expand Up @@ -81,7 +81,7 @@
value="{{ assessment_value }}"
maxlength='5'
size='5'
onkeypress="return goodchars(event,'-1234567890')"
onkeypress="returnwindow.LS.goodchars(event,'-1234567890')"
/>
</td>
{% elseif first %}
Expand All @@ -92,7 +92,7 @@
id='assessment_{{ position }}_{{ scale_id }}'
name='assessment_{{ position }}_{{ scale_id }}'
value="{{ assessment_value }}" maxlength='5' size='5'
onkeypress="return goodchars(event,'-1234567890')"
onkeypress="returnwindow.LS.goodchars(event,'-1234567890')"
/>
</td>
{% elseif assessmentvisible %}
Expand Down
Expand Up @@ -13,7 +13,7 @@
<div class="row">
<div class="col-lg-12">
<!-- form -->
<?php echo CHtml::form(array("admin/questiongroups/sa/import"), 'post', array('id'=>'importgroup', 'name'=>'importgroup', 'class'=>'form30 ', 'enctype'=>'multipart/form-data', 'onsubmit'=>'return validatefilename(this,"'.gT('Please select a file to import!','js').'");')); ?>
<?php echo CHtml::form(array("admin/questiongroups/sa/import"), 'post', array('id'=>'importgroup', 'name'=>'importgroup', 'class'=>'form30 ', 'enctype'=>'multipart/form-data', 'onsubmit'=>'return window.LS.validatefilename(this,"'.gT('Please select a file to import!','js').'");')); ?>

<!-- Select question group file -->
<div class="form-group">
Expand Down

0 comments on commit 0169d43

Please sign in to comment.