Skip to content

Commit

Permalink
Fixed issue #9933: Incomplete token menu -- partial fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Oct 2, 2015
1 parent f8fe438 commit a26350e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 44 deletions.
12 changes: 6 additions & 6 deletions protected/controllers/TokensController.php
Expand Up @@ -51,7 +51,7 @@ public function actionCreate($surveyId)

$token = \ls\models\Token::create($survey->sid);
if (App()->request->isPostRequest) {
$token->setAttributes(App()->request->getPost(get_class($token)));
$token->setAttributes(App()->request->getPost(\CHtml::modelName($token)));

// Validate & safe.
if ($token->save()) {
Expand Down Expand Up @@ -92,17 +92,17 @@ public function actionUpdate($surveyId, $id)

$token = $this->loadModel($id, $surveyId);

if (App()->request->isPostRequest) {
$token->setAttributes(App()->request->getPost(get_class($token)));
if (App()->request->isPutRequest) {
$token->setAttributes(App()->request->getPost(\CHtml::modelName($token)));

// Validate & safe.
if ($token->save()) {
// On success.
App()->user->setFlash('success', 'ls\models\Token updated');
$this->redirect(['tokens/index', 'surveyId' => $survey->sid]);
App()->user->setFlash('success', gT('Token updated'));
// $this->redirect(['tokens/index', 'surveyId' => $survey->sid]);
}
}
$this->render('create', ['token' => $token, 'survey' => $survey]);
$this->render('update', ['token' => $token, 'survey' => $survey]);
}

public function actionIndex($surveyId)
Expand Down
11 changes: 6 additions & 5 deletions protected/models/Dynamic.php
Expand Up @@ -75,16 +75,17 @@ public static function create($id, $scenario = 'insert')
public static function valid($id, $refresh = false)
{
$result = false;
if (is_numeric($id) && (!isset(self::$valid[$id]) || $refresh)) {
$tableName = static::constructTableName($id);
if (is_numeric($id) && (!isset(self::$valid[$tableName]) || $refresh)) {
try {
App()->db->createCommand("SELECT 1 FROM " . static::constructTableName($id))->execute();
self::$valid[$id] = true;
App()->db->createCommand("SELECT 1 FROM `$tableName`")->execute();
self::$valid[$tableName] = true;
} catch (\CDbException $e) {
self::$valid[$id] = false;
self::$valid[$tableName] = false;
}
}

return self::$valid[$id];
return self::$valid[$tableName];
}


Expand Down
12 changes: 5 additions & 7 deletions protected/models/Token.php
Expand Up @@ -46,13 +46,13 @@ abstract class Token extends Dynamic
public function attributeLabels()
{
$labels = [
'tid' => gT('ls\models\Token ID'),
'partcipant' => gt('ls\models\Participant ID'),
'tid' => gT('Token ID'),
'partcipant' => gt('Participant ID'),
'firstname' => gT('First name'),
'lastname' => gT('Last name'),
'email' => gT('Email address'),
'emailstatus' => gT('Email status'),
'token' => gT('ls\models\Token'),
'token' => gT('Token'),
'language' => gT('Language code'),
'blacklisted' => gT('Blacklisted'),
'sent' => gT('Invitation sent date'),
Expand Down Expand Up @@ -265,11 +265,9 @@ public function rules()
{
$aRules = [
['token', 'unique', 'allowEmpty' => true],
['firstname', 'required'],
['lastname', 'required'],
[implode(',', $this->tableSchema->columnNames), 'safe'],
['firstname', 'length', 'max' => 40],
['lastname', 'length', 'max' => 40],
['remindercount', 'numerical', 'integerOnly' => true, 'allowEmpty' => true],
['email', 'filter', 'filter' => 'trim'],
[
'email',
\CEmailValidator::class,
Expand Down
1 change: 1 addition & 0 deletions protected/themes/default/assets/css/style.css
Expand Up @@ -73,5 +73,6 @@ table.upgrade tr.disabled {
}

body {
position: relative;
margin-top: 70px;
}
32 changes: 6 additions & 26 deletions protected/views/tokens/create.php
Expand Up @@ -6,7 +6,9 @@
'layout' => TbHtml::FORM_LAYOUT_HORIZONTAL,
'enableClientValidation' => true,
'enableAjaxValidation' => false,

'clientOptions' => [
'validateOnSubmit' => true
]

]);
$inputOptions = [
Expand All @@ -15,40 +17,18 @@
echo $form->textFieldControlGroup($token, 'firstname', $inputOptions);
echo $form->textFieldControlGroup($token, 'lastname', $inputOptions);
echo $form->textFieldControlGroup($token, 'email', $inputOptions);
echo $form->textFieldControlGroup($token, 'emailstatus', $inputOptions);
echo $form->textFieldControlGroup($token, 'token', $inputOptions);
echo $form->dropDownListControlGroup($token, 'language', $survey->allLanguages, $inputOptions);
echo $form->textFieldControlGroup($token, 'sent', $inputOptions);
echo $form->textFieldControlGroup($token, 'remindersent', $inputOptions);
echo $form->textFieldControlGroup($token, 'completed', $inputOptions);
echo $form->numberFieldControlGroup($token, 'usesleft', $inputOptions);
echo $form->customControlGroup($this->widget(WhDateTimePicker::class, [
'model' => $token,
'attribute' => 'validfrom',
'pluginOptions' => [
// 'language' => App()->language,
'pick12HourFormat' => false,
'pickSeconds' => false,
'format' => 'YYYY-MM-DD HH:mm:ss',
]
], true), $token, 'validfrom', $inputOptions);
echo $form->customControlGroup($this->widget(WhDateTimePicker::class, [
'model' => $token,
'attribute' => 'validfrom',
'pluginOptions' => [
// 'language' => App()->language,
'pick12HourFormat' => false,
'pickSeconds' => false,
'format' => 'YYYY-MM-DD HH:mm:ss',
]
], true), $token, 'validuntil', $inputOptions);

echo $form->dateFieldControlGroup($token, 'validfrom');
echo $form->dateFieldControlGroup($token, 'validuntil');
foreach ($token->attributeNames() as $attribute) {
if (substr_compare('attribute_', $attribute, 0, 10) === 0) {
echo $form->textFieldControlGroup($token, $attribute, $inputOptions);
}
}


echo TbHtml::openTag('div', ['class' => 'pull-right btn-group']);
echo TbHtml::submitButton(gT('Save token'), ['color' => 'primary']);
echo TbHtml::closeTag('div');
Expand Down
40 changes: 40 additions & 0 deletions protected/views/tokens/update.php
@@ -0,0 +1,40 @@
<div class="row"><div class="col-md-6 col-md-offset-3">
<?php
/** @var \ls\models\Token $token */
/** @var TbActiveForm $form */
$form = $this->beginWidget(TbActiveForm::class, [
'layout' => TbHtml::FORM_LAYOUT_HORIZONTAL,
'enableClientValidation' => true,
'enableAjaxValidation' => false,
'clientOptions' => [
'validateOnSubmit' => true
],
'method' => 'put'

]);
$inputOptions = [
'formLayout' => TbHtml::FORM_LAYOUT_HORIZONTAL,
];
echo $form->textFieldControlGroup($token, 'firstname', $inputOptions);
echo $form->textFieldControlGroup($token, 'lastname', $inputOptions);
echo $form->textFieldControlGroup($token, 'email', $inputOptions);
echo $form->textFieldControlGroup($token, 'token', $inputOptions);
echo $form->dropDownListControlGroup($token, 'language', $survey->allLanguages, $inputOptions);
echo $form->textFieldControlGroup($token, 'sent', $inputOptions);
echo $form->textFieldControlGroup($token, 'remindersent', $inputOptions);
echo $form->textFieldControlGroup($token, 'completed', $inputOptions);
echo $form->numberFieldControlGroup($token, 'usesleft', $inputOptions);
echo $form->dateFieldControlGroup($token, 'validfrom');
echo $form->dateFieldControlGroup($token, 'validuntil');
foreach ($token->attributeNames() as $attribute) {
if (substr_compare('attribute_', $attribute, 0, 10) === 0) {
echo $form->textFieldControlGroup($token, $attribute, $inputOptions);
}
}


echo TbHtml::openTag('div', ['class' => 'pull-right btn-group']);
echo TbHtml::submitButton(gT('Save token'), ['color' => 'primary']);
echo TbHtml::closeTag('div');
$this->endWidget();
?></div></div>

0 comments on commit a26350e

Please sign in to comment.