Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Get all surveys info

  • dsvntt
  • dsvntt's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 7 months ago - 1 year 7 months ago #232255 by dsvntt
Get all surveys info was created by dsvntt
Hi!

I have a custom theme. 

I need to make changes for surveys in custom.js.

If the survey settings says alloweditaftercompletion = Y, then I need to make changes.

I think the best solution is to take aSurveyInfo from layout_survey_list.twig and pass that object to custom.js. In custom.js, check the alloweditaftercompletion value and make the change if needed. It's been tested and this way works. The only problem is that aSurveyInfo only returns data from the last survey. That is, if the last survey has value "Y", then it will be the same for all the others. Is it possible to get the data of all active surveys?

Thank you!

 
Last edit: 1 year 7 months ago by dsvntt.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 7 months ago #232271 by tpartner
Replied by tpartner on topic Get all surveys info
What changes are you making. Do you want those changes on the survey list page or when viewing surveys?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • dsvntt
  • dsvntt's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 7 months ago #232281 by dsvntt
Replied by dsvntt on topic Get all surveys info
Hi!

I make changes for the main page (where all the active surveys are shown), namely the button that is responsible for the transition to the survey. It is custom in my theme. Now the problem is in the aSurveyInfo transfer to custom.js /checking "alloweditaftercompletion" of all surveys.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232297 by tpartner
Replied by tpartner on topic Get all surveys info
In layout_survey_list.twig, the aSurveyInfo.publicSurveys object contains settings for all publicly listed active surveys.

So, you could apply attributes and/or classes to the survey list items, something like this:

Code:
<ul class='{{ aSurveyInfo.class.surveylistrowdivbdivul }} list-unstyled ' {{ aSurveyInfo.attr.surveylistrowdivbdivul }}>
 
  {% for key, oSurvey in aSurveyInfo.publicSurveys %}
    <li  class="{{ aSurveyInfo.class.surveylistrowdivbdivulli }} btn-group col-sm-6 col-xs-12" {{ aSurveyInfo.attr.surveylistrowdivbdivulli }}>
      <a
      href="{{ oSurvey.sSurveyUrl }}"
      title="{{ gT("Start survey") }}"
      lang="{{ oSurvey.language }}"
      class="{{ aSurveyInfo.class.surveylistrowdivbdivullia }} btn btn-primary col-xs-12 allow-edit-{{oSurvey['alloweditaftercompletion']}}"
      data-allow-edit="{{oSurvey['alloweditaftercompletion']}}"  >
        {{ oSurvey.localizedTitle }}
      </a>
    </li>
  {% endfor %}
</ul>

This would result in HTML something like this which you could manage in your custom.js file.

Code:
<ul class=" surveys-list  list-unstyled ">
  <li class="   btn-group col-sm-6 col-xs-12">
    <a href="/limeSurvey5x/index.php/444444?lang=en" title="Start survey" class=" surveytitle   btn btn-primary col-xs-12 allow-edit-N" data-allow-edit="N" lang="en">
      Test 1
    </a>
  </li>
  <li class="   btn-group col-sm-6 col-xs-12">
    <a href="/limeSurvey5x/index.php/573255?lang=de" title="Start survey" class=" surveytitle   btn btn-primary col-xs-12 allow-edit-Y" data-allow-edit="Y" lang="de">
      Test 2
    </a>
  </li>
</ul>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • dsvntt
  • dsvntt's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 6 months ago - 1 year 6 months ago #232302 by dsvntt
Replied by dsvntt on topic Get all surveys info
Hi!

Thank you so much for your help!

I apologize for not adding my code last time. This is what the code looks like in custom.js:

function createCardFooter(survey, locale) {
//footer container
const container = document.createElement('div')
container.setAttribute("class", "card-footer")

// answer button
const a = document.createElement('a')
a.href = survey.href
a.lang = survey.lang
// surveytitle class is something lime has used -> keeps button centered in smaller media queries
a.setAttribute("class", "surveytitle btn btn-primary col-xs-12 ansButton")

if (alloweditaftercompletion = Y) {

a.innerHTML = locale["ansButton"]

} else {

// answer button text and button behavior depends on survey's answer status
if (survey.ansStatus.status.startsWith('full') || (!config.show_repeatable_surveys && survey.ansStatus.status === 'repeat')) {
// if answer date is wanted to be part of button text then use the below one:
//a.innerHTML = locale["ansButtonFull"] + " " + survey.ansStatus.status.split(" ")[1]
a.innerHTML = locale["ansButtonFull"]
a.style.pointerEvents = "none";
a.setAttribute("class", "btn btn-primary col-xs-12 ansButton card-btn-disabled")
const tickMark = document.createElement('div')
tickMark.setAttribute('class', 'tick-mark')
a.appendChild(tickMark)
}
if (survey.ansStatus.status === 'repeat' && config.show_repeatable_surveys) {
a.innerHTML = locale["ansButtonPartial"]
}
if (survey.ansStatus.status === 'open') {
a.innerHTML = locale["ansButton"]
}
}
container.appendChild(a)
return container
}

(sorry I don't know how to properly insert the code here)

The idea is: if "alloweditaftercompletion = Y", then the button will always be "a.innerHTML = locale["ansButton"]", but if "alloweditaftercompletion = N", then the code will determine the copy by ansStatus (code already written).
Last edit: 1 year 6 months ago by dsvntt.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232318 by tpartner
Replied by tpartner on topic Get all surveys info
Sorry, I can't follow what you are trying to achieve or where you are getting some of the variables.

Perhaps explaining the objectives in words and providing screenshot mock-ups might help.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • dsvntt
  • dsvntt's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 6 months ago #232319 by dsvntt
Replied by dsvntt on topic Get all surveys info
Okay, I'll try to explain again.

In custom.js I have to check the alloweditaftercompletion value. You got me right and your example does everything correctly. The only thing in custom.js I have to check it with javaScript. As an example:

if (alloweditaftercompletion = Y){
do something
}else{
don't do anything
}

So you understood my question correctly, but in your answer it's done with html, can the same be done with JavaScript?

Thank you!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232378 by tpartner
Replied by tpartner on topic Get all surveys info
You can access the element attributes and/or class names with JavaScript to find the alloweditaftercompletion value.

So, assuming you are looping through the survey links with your JS, you can do something like this:

Code:
if($(this).attr('data-allow-edit') == 'Y') {
  // Do something...
}
else {
  // Don't do anything.
}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232379 by tpartner
Replied by tpartner on topic Get all surveys info
This seems a little rough to me, but if you need to push the alloweditaftercompletion values directly to JavaScript, you could do something like this which will create a JS object with survey IDs as keys and alloweditaftercompletion as values.

Code:
<script type="text/javascript" data-author="Tony Partner">  
  var oAllowedEdits = {};
</script>
 
{% for key, oSurvey in aSurveyInfo.publicSurveys %}
  <script type="text/javascript" data-author="Tony Partner">  
    var thisSID = '{{ oSurvey["sid"] }}';  
    var thisAllowedEdit = '{{ oSurvey["alloweditaftercompletion"] }}';
    oAllowedEdits[thisSID] = thisAllowedEdit;
  </script>  
{% endfor %}
 
<script type="text/javascript" data-author="Tony Partner">  
  console.log(oAllowedEdits);
</script>

The result is a JS object like this:

 

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • dsvntt
  • dsvntt's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 6 months ago #232417 by dsvntt
Replied by dsvntt on topic Get all surveys info
Hi!

Thank you very much for your help!

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose