Skip to content

Commit

Permalink
Add the ability to edit tokens inline, GCI Task #7245210
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@12067 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Shitiz Garg committed Jan 15, 2012
1 parent ac2f436 commit 3b2f713
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 48 deletions.
49 changes: 23 additions & 26 deletions application/controllers/admin/tokens.php
Expand Up @@ -336,15 +336,19 @@ function getTokens_json($iSurveyId)
$aData->records = count($tokens);
$aData->total = ceil($aData->records / $limit);

Yii::app()->loadHelper("surveytranslator");

$format = getDateFormatData(Yii::app()->session['dateformat']);

for ($i = 0, $j = ($page - 1) * $limit; $i < $limit && $j < $aData->records; $i++, $j++)
{
$token = $tokens[$j];
if ((int) $token['validfrom'])
$token['validfrom'] = date('m/d/Y', strtotime(trim($token['validfrom'])));
$token['validfrom'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validfrom'])));
else
$token['validfrom'] = '';
if ((int) $token['validuntil'])
$token['validuntil'] = date('m/d/Y', strtotime(trim($token['validuntil'])));
$token['validuntil'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validuntil'])));
else
$token['validuntil'] = '';

Expand All @@ -359,8 +363,7 @@ function getTokens_json($iSurveyId)
else
$action .= '<input type="image" src="' . Yii::app()->getConfig('imageurl') . '/token_remind.png" name="sendreminders" id="sendreminders" title="' . $clang->gT("Send reminder email to the selected entries (if they have already received the invitation email)") . '" onclick=\'window.open("' . Yii::app()->getController()->createUrl("admin/tokens/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid']) . '", "_blank")\' />';
}
$action .= '<input style="height: 16; width: 16px; font-size: 8; font-family: verdana" type="image" src="' . Yii::app()->getConfig('imageurl') . '/token_edit.png" title="' . $clang->gT("Edit token entry") . '" alt="' . $clang->gT("Edit token entry") . '" onclick=\'window.open("' . Yii::app()->getController()->createUrl("/admin/tokens/edit/surveyid/{$iSurveyId}/tokenid/{$token['tid']}") . '", "_top")\'>';

$action .= '<input style="height: 16; width: 16px; font-size: 8; font-family: verdana" type="image" src="' . Yii::app()->getConfig('imageurl') . '/token_edit.png" class="token_edit" title="' . $clang->gT("Edit token entry") . '" alt="' . $clang->gT("Edit token entry") . '">';
$aData->rows[$i]['cell'] = array($token['tid'], $action, $token['firstname'], $token['lastname'], $token['email'], $token['emailstatus'], $token['token'], $token['language'], $token['sent'], $token['remindersent'], $token['remindercount'], $token['completed'], $token['usesleft'], $token['validfrom'], $token['validuntil']);
$attributes = GetAttributeFieldNames($iSurveyId);
foreach ($attributes as $attribute)
Expand All @@ -372,28 +375,22 @@ function getTokens_json($iSurveyId)
echo ls_json_encode($aData);
}

function editToken($iSurveyId)
{
$sOperation = Yii::app()->request->getPost('oper');

if (trim($_POST['validfrom']) == '')
{
$from = null;
}
else
{
$from = date('Y-m-d H:i:s', strtotime(trim($_POST['validfrom'])));
}
if (trim($_POST['validuntil']) == '')
function editToken($iSurveyId)
{
$until = null;
}
else
{
$until = date('Y-m-d H:i:s', strtotime(trim($_POST['validuntil'])));
}
// if edit it will update the row
if ($sOperation == 'edit')
$sOperation = Yii::app()->request->getPost('oper');

if (trim($_POST['validfrom']) == '')
$from = null;
else
$from = date('Y-m-d H:i:s', strtotime(trim($_POST['validfrom'])));

if (trim($_POST['validuntil']) == '')
$until = null;
else
$until = date('Y-m-d H:i:s', strtotime(trim($_POST['validuntil'])));

// if edit it will update the row
if ($sOperation == 'edit')
{
// if (Yii::app()->request->getPost('language') == '')
// {
Expand Down Expand Up @@ -425,7 +422,7 @@ function editToken($iSurveyId)
{
$value = Yii::app()->request->getPost($attr_name);
if ($desc['mandatory'] == 'Y' && trim($value) == '')
$this->getController()->error(sprintf($clang->gT('%s cannot be empty'), $desc['description']));
$this->getController()->error(sprintf($this->controller->lang->gT('%s cannot be empty'), $desc['description']));
$aData[$attr_name] = Yii::app()->request->getPost($attr_name);
}
$token = Tokens_dynamic::model()->find('tid=' . CHttpRequest::getPost('id'));
Expand Down
25 changes: 14 additions & 11 deletions application/views/admin/token/browse.php
Expand Up @@ -40,6 +40,7 @@
/* Build the javasript variables to pass to the jqGrid */
?>
<script type="text/javascript">
var imageurl = "<?php echo Yii::app()->getRequest()->getBaseUrl() ?>/images";
var mapButton = "<?php $clang->eT("Next") ?>";
var error = "<?php $clang->eT("Error") ?>";
var removecondition = "<?php $clang->eT("Remove condition") ?>";
Expand All @@ -66,21 +67,23 @@
var inviteurl = "<?php echo Yii::app()->getController()->createUrl("admin/tokens/email/surveyid/{$surveyid}/tids/|"); ?>";
var searchtypes = ["<?php $clang->eT("Equals") ?>","<?php $clang->eT("Contains") ?>","<?php $clang->eT("Not equal") ?>","<?php $clang->eT("Not contains") ?>","<?php $clang->eT("Greater than") ?>","<?php $clang->eT("Less than") ?>"]
var colNames = ["ID","<?php $clang->eT("Action") ?>","<?php $clang->eT("First name") ?>","<?php $clang->eT("Last name") ?>","<?php $clang->eT("Email address") ?>","<?php $clang->eT("Email status") ?>","<?php $clang->eT("Token") ?>","<?php $clang->eT("Language") ?>","<?php $clang->eT("Invitation sent?") ?>","<?php $clang->eT("Reminder sent?") ?>","<?php $clang->eT("Reminder count") ?>","<?php $clang->eT("Completed?") ?>","<?php $clang->eT("Uses left") ?>","<?php $clang->eT("Valid from") ?>","<?php $clang->eT("Valid until") ?>",<?php echo $columnNames; ?>];
var colModels = [{ "name":"tid", "index":"tid", "width":20, "align":"center", "sorttype":"int", "sortable": true, "editable":false, "hidden":false},
{ "name":"action", "index":"action", "sorttype":"string", "sortable": false, "width":70, "align":"center", "editable":false},
var colModels = [
{ "name":"tid", "index":"tid", "width":30, "align":"center", "sorttype":"int", "sortable": true, "editable":false, "hidden":false},
{ "name":"action", "index":"action", "sorttype":"string", "sortable": false, "width":90, "align":"center", "editable":false},
{ "name":"firstname", "index":"firstname", "sorttype":"string", "sortable": true, "width":100, "align":"center", "editable":true},
{ "name":"lastname", "index":"lastname", "sorttype":"string", "sortable": true,"width":100, "align":"center", "editable":true},
{ "name":"email", "index":"email","align":"center","width":100, "sorttype":"string", "sortable": true, "editable":true},
{ "name":"emailstatus", "index":"emailstatus","align":"center","width":80,"sorttype":"string", "sortable": true, "editable":true, "edittype":"checkbox", "editoptions":{ "value":"OK:N"}},
{ "name":"token", "index":"token","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true},
{ "name":"language", "index":"language","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true, "edittype":"select", "editoptions":{"value":"<?php echo $langnames; ?>"}},
{ "name":"sent", "index":"sent","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true, "edittype":"checkbox", "editoptions":{ "value":"Y:N"}},
{ "name":"remindersent", "index":"remindersent","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true, "edittype":"checkbox", "editoptions":{ "value":"Y:N"}},
{ "name":"email", "index":"email","align":"center","width":170, "sorttype":"string", "sortable": true, "editable":true},
{ "name":"emailstatus", "index":"emailstatus","align":"center","width":80,"sorttype":"string", "sortable": true, "editable":true},
{ "name":"token", "index":"token","align":"center", "sorttype":"int", "sortable": true,"width":150,"editable":true},
{ "name":"language", "index":"language","align":"center", "sorttype":"int", "sortable": true,"width":100,"editable":true, "edittype":"select", "editoptions":{"value":"<?php echo $langnames; ?>"}},
{ "name":"sent", "index":"sent","align":"center", "sorttype":"int", "sortable": true,"width":130,"editable":true},
{ "name":"remindersent", "index":"remindersent","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true},
{ "name":"remindercount", "index":"remindercount","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true},
{ "name":"completed", "index":"completed","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true, "edittype":"checkbox", "editoptions":{ "value":"Y:N"}},
{ "name":"completed", "index":"completed","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true},
{ "name":"usesleft", "index":"usesleft","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true},
{ "name":"validfrom", "index":"validfrom","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true, "editoptions":{ dataInit:function (elem) {$(elem).datepicker();}}},
{ "name":"validuntil", "index":"validuntil","align":"center", "sorttype":"int", "sortable": true,"width":80,"editable":true, "editoptions":{ dataInit:function (elem) {$(elem).datepicker();}}},<?php echo implode(",\n", $uidNames); ?>];
{ "name":"validfrom", "index":"validfrom","align":"center", "sorttype":"int", "sortable": true,"width":160,"editable":true},
{ "name":"validuntil", "index":"validuntil","align":"center", "sorttype":"int", "sortable": true,"width":160,"editable":true},
<?php echo implode(",\n", $uidNames); ?>];
<!--
for(i=0; i<document.forms.length; i++)
{
Expand Down
56 changes: 47 additions & 9 deletions scripts/admin/tokens.js
Expand Up @@ -122,27 +122,65 @@ jQuery("#displaytokens").jqGrid({
colModel: colModels,
toppager: true,
height: "100%",
width: "100%",
rowNum: 25,
editable:true,
scrollOffset:0,
autowidth: true,
sortable : true,
sortname: 'id',
sortorder: 'asc',
viewrecords : true,
rowList: [25,50,100,250,500,1000,5000,10000],
multiselect: true,
loadonce : false,
/*ondblClickRow: function(id)
loadComplete: function()
{
window.editing = false;
jQuery(".token_edit").unbind('click').bind('click', function(e)
{
if(id && id!==lastSel)
{
jQuery('#displaytokens').saveRow(lastSel);
lastSel=id;
if (window.editing)
return true;
var row = jQuery(this).closest('.jqgrow');
var func = function()
{
jQuery('#displaytokens').restoreRow(row.attr('id'));
row.find('input').show();
row.find('.drop_editing').remove();
row.find('.save').remove();
window.editing = false;
}
jQuery('#displaytokens').editRow(id,true);
},*/

jQuery('#displaytokens').editRow(row.attr('id'), true, null, null, null, null, func);
jQuery(this).parent().find('input').hide();
window.editing = true;

var validfrom = row.find('[aria-describedby="displaytokens_validfrom"]');
validfrom.find('input').css('width', '119px').datetimepicker({
showOn: 'button',
dateFormat: userdateformat,
});
var validuntil = row.find('[aria-describedby="displaytokens_validuntil"]');
validuntil.find('input').css('width', '119px').datetimepicker({
showOn: 'button',
dateFormat: userdateformat,
});

jQuery('<input type="image" class="drop_editing" src="' + jQuery(this).parent().find('input:eq(1)').attr('src') + '" />')
.appendTo(jQuery(this).parent())
.click(func);
jQuery('<input type="image" class="save" src="' + imageurl + '/success_notice.png" width="16" />')
.appendTo(jQuery(this).parent())
.click(function()
{
jQuery('#displaytokens').saveRow(row.attr('id'));
func();
});
});
},
ondblClickRow: function(id)
{
var row = jQuery('#' + id);
row.find('.token_edit').click();
},
pager: "#pager",
caption: "Tokens",
});
Expand Down
10 changes: 9 additions & 1 deletion scripts/jquery/css/start/jquery-ui.css
Expand Up @@ -1563,4 +1563,12 @@

.ui-tabs .ui-tabs-hide {
display: none !important;
}
}

/* css for timepicker */
.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
.ui-timepicker-div dl { text-align: left; }
.ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
.ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }

0 comments on commit 3b2f713

Please sign in to comment.