Skip to content

Commit

Permalink
Dev: Add language wizard when a survey has more than one language (Ci…
Browse files Browse the repository at this point in the history
…ntLink)
  • Loading branch information
olleharstedt committed Aug 17, 2016
1 parent d8246e1 commit 80bc680
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
11 changes: 8 additions & 3 deletions application/core/plugins/CintLink/CintLink.php
Expand Up @@ -972,8 +972,7 @@ public function getSurvey(LSHttpRequest $request)
$link = Yii::app()->createAbsoluteUrl(
'survey/index',
array(
'sid' => $surveyId,
'lang' => $data['surveyls_language']
'sid' => $surveyId
)
);

Expand All @@ -982,7 +981,8 @@ public function getSurvey(LSHttpRequest $request)
'name' => $user->full_name,
'email' => $user->email,
'nrOfQuestions' => $this->getNrOfQuestions($survey),
'link' => $link
'link' => $link,
'language' => $survey->language
));
}

Expand All @@ -1005,6 +1005,11 @@ public function userTriedToPay(LSHttpRequest $request)
$this->set('cint_active_' . $surveyId, true);
}

/**
* Plugin specific code to run a function.
* Will echo function result.
* @return void
*/
public function newDirectRequest()
{
$event = $this->event;
Expand Down
14 changes: 14 additions & 0 deletions application/core/plugins/CintLink/css/cintlink.css
Expand Up @@ -45,3 +45,17 @@
.cint-price, .cint-age, .cint-buttons {
white-space: nowrap;
}

/* Radio buttons in language wizard is off */
#cint-lang-wizard .radio input {
margin-top: 4px;
}

#cint-lang-wizard .radio label {
padding-left: 6px;
font-weight: bold;
}

#cint-lang-wizard form {
padding-left: 20px;
}
37 changes: 23 additions & 14 deletions application/core/plugins/CintLink/js/cintlink.js
Expand Up @@ -123,10 +123,10 @@ $(document).ready(function() {
/**
* Show the CintLink widget
*
* @param {string|undefined} lang Language to put in the survey link
* @return
*/
function showWidget() {
console.log("showWidget");
function showWidget(lang) {

$.ajax({
method: 'POST',
Expand All @@ -138,11 +138,20 @@ $(document).ready(function() {
var survey = JSON.parse(response.result);
console.log('survey', survey);

var completeLink;
if (lang === undefined) {
completeLink = response.link + '&lang=' + response.language;
}
else {
completeLink = response.link + '&lang=' + lang;
}
console.log('completeLink', completeLink);

var options = {
locale: getWidgetLanguage(survey.surveyls_language),
introText: "LimeSurvey",
surveyLink: {
value: response.link,
value: completeLink,
readOnly: true
},
surveyTitle: {
Expand Down Expand Up @@ -282,17 +291,16 @@ $(document).ready(function() {
* @return
*/
function showLangWizard() {
showLoader();
$.ajax({
method: 'POST',
url: LS.plugin.cintlink.pluginBaseUrl + '&method=getLangWizard',
surveyId: LS.plugin.cintlink.surveyId
}).done(function(response) {
console.log('response', response);
hideLoader();
//$('#cintlink-container').html(response);
//doToolTip();
});
$('#cint-lang-wizard').modal();
}

/**
* Fired when user clicks OK in language wizard
* @return
*/
function langWizardOK() {
var lang = $('#cint-lang-wizard input[name="lang"]:checked').val();
showWidget(lang);
}

// Needs to be accessed from the outside (dashboard view)
Expand All @@ -302,6 +310,7 @@ $(document).ready(function() {
LS.plugin.cintlink.userTriedToPay = userTriedToPay;
LS.plugin.cintlink.showDashboard = showDashboard;
LS.plugin.cintlink.showLangWizard = showLangWizard;
LS.plugin.cintlink.langWizardOK = langWizardOK;

// Check if user is logged in on limesurvey.org
// If yes, show widget
Expand Down
34 changes: 33 additions & 1 deletion application/core/plugins/CintLink/views/dashboard.php
Expand Up @@ -23,7 +23,7 @@
<?php endif; ?>

<!-- Cint widget button (not visible from global dashboard) -->
<?php if (!empty($surveyId)): // Widget is not visible on global dashboard ?>
<?php if (!empty($surveyId)): ?>
<div class='row'>

<!-- Show Cint widget -->
Expand All @@ -37,6 +37,38 @@ class='btn btn-default'
<?php echo $plugin->gT('Choose participants'); ?>
</button>

<!-- Modal for Cint language wizard -->
<div id="cint-lang-wizard" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content"> <?php // JS add not.type as panel-type, e.g. panel-default, panel-danger ?>
<div class="modal-header panel-heading">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><?php echo $plugin->gT('Choose language'); ?></h4>
</div>
<div class="modal-body">
<p class='modal-body-text'><?php echo $plugin->gT('Pick a language that will be used as default for these participants. Make sure your order\'s country represents this language.'); ?></p>

<!-- Radio list with languages -->
<form class='form-horizontal'>
<div class='radio'>
<label><input type='radio' name='lang' checked='checked' value='<?php echo $survey->language; ?>' /><?php echo getLanguageNameFromCode($survey->language)[0]; ?></label>
</div>
<?php foreach ($survey->additionalLanguages as $lang): ?>
<div class='radio'>
<label><input type='radio' name='lang' value='<?php echo $lang; ?>' /><?php echo getLanguageNameFromCode($lang)[0]; ?></label>
</div>
<?php endforeach; ?>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">&nbsp;<?php eT("Cancel"); ?></button>
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick='LS.plugin.cintlink.langWizardOK();' >&nbsp;<?php eT("OK"); ?></button>
</div>
</div>
</div>
</div>

<!-- Refresh -->
<button class='btn btn-default pull-right' onclick='LS.plugin.cintlink.showDashboard();'><span class='fa fa-refresh'></span>&nbsp;<?php echo $plugin->gT('Refresh'); ?></button>

Expand Down

0 comments on commit 80bc680

Please sign in to comment.