Skip to content

Commit

Permalink
widgets for questionssets
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Apr 7, 2016
1 parent 2a45b80 commit fc14aa9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
8 changes: 7 additions & 1 deletion apps/projects/static/projects/js/project_questions_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ app.factory('FormService', ['$http', '$timeout', function($http, $timeout) {

service.saveAndRedirect = function(url) {
service.save();
service.redirect(url);
//service.redirect(url);
};

service.fetchValues = function() {
Expand Down Expand Up @@ -225,6 +225,7 @@ app.factory('FormService', ['$http', '$timeout', function($http, $timeout) {
};

service.storeValueSetValues = function(valueset) {

// loop over all arrays of values in the valueset
angular.forEach(valueset.values, function(values, attribute_id) {
// loop over all values in the array
Expand All @@ -238,6 +239,11 @@ app.factory('FormService', ['$http', '$timeout', function($http, $timeout) {
// store the current index in the list
value.index = index;

// add the valueset id to the value if it was not set before (new valueset)
if (angular.isUndefined(value.valueset)) {
value.valueset = valueset.id;
}

if (angular.isDefined(value.id)) {
// update an existing value
$http.put(values_url + value.id, value).success(function(response) {
Expand Down
2 changes: 2 additions & 0 deletions apps/projects/templates/projects/project_questions_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ <h4>
<button type="button" class="btn btn-default" ng-click="service.save()">
{% trans 'Save' %}
</button>
<!--
<button type="button" class="btn btn-primary" ng-show="service.options.has_next"
ng-click="service.saveAndRedirect('{% url 'project_questions_next' project.pk question_entity.pk %}')">
{% trans 'Save and continue' %}
Expand All @@ -136,6 +137,7 @@ <h4>
ng-click="service.saveAndRedirect('{% url 'project' project.pk %}')">
{% trans 'Save and return to overview' %}
</button>
-->
</div>

</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

{% if attribute.is_collection %}

<div class="input-group input-collection"
<div class="textarea-collection"
ng-repeat="value in service.valueset.values[{{ attribute.id }}] track by $index" ng-hide="value.removed">

<input class="form-control" type="text" ng-model="service.valueset.values[{{ attribute.id }}][$index].text"/>
<textarea class="form-control" rows="6"
ng-model="service.valueset.values[{{ attribute.id }}][$index].text">
</textarea>

<div class="input-group-btn">
<button type="button" class="btn btn-danger" tabindex="-1"
ng-click="service.removeValueSetValue({{ attribute.id }}, $index)">
{% trans 'Remove' %}
</button>
</div>
<button type="button" class="btn btn-danger" tabindex="-1"
ng-click="service.removeValueSetValue({{ attribute.id }}, $index)">
{% trans 'Remove' %}
</button>
</div>

{% else %}

<input class="form-control" type="text" ng-model="service.valueset.values[{{ attribute.id }}][0].text"/>
<textarea class="form-control" rows="6"
ng-model="service.valueset.values[{{ attribute.id }}][0].text">
</textarea>

{% endif %}

Expand Down
38 changes: 32 additions & 6 deletions apps/projects/templates/projects/project_questions_form_yesno.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,48 @@

{% if attribute.is_collection %}

<div class="input-group input-collection"
ng-repeat="value in service.valueset.values[{{ attribute.id }}] track by $index" ng-hide="value.removed">
<div class="radio-collection"
ng-repeat="value in service.valueset.values[{{ attribute.id }}] track by $index"
ng-hide="value.removed">

<input class="form-control" type="text" ng-model="service.valueset.values[{{ attribute.id }}][$index].text"/>

<div class="input-group-btn">
<div class="pull-right">
<button type="button" class="btn btn-danger" tabindex="-1"
ng-click="service.removeValueSetValue({{ attribute.id }}, $index)">
{% trans 'Remove' %}
</button>
</div>
<div class="radio pull-left">
<label>
<input type="radio"
ng-model="service.valueset.values[{{ attribute.id }}][$index].text"
data-ng-value="1" />
<span>{% trans 'Yes' %}</span>
</label>
<label class=>
<input type="radio"
ng-model="service.valueset.values[{{ attribute.id }}][$index].text"
data-ng-value="0" />
<span class="">{% trans 'No' %}</span>
</label>
</div>
</div>

{% else %}

<input class="form-control" type="text" ng-model="service.valueset.values[{{ attribute.id }}][0].text"/>
<div>
<label>
<input type="radio"
data-ng-model="service.valueset.values[{{ attribute.id }}][0].text"
data-ng-value="1" />
<span>{% trans 'Yes' %}</span>
</label>
<label>
<input type="radio"
data-ng-model="service.valueset.values[{{ attribute.id }}][0].text"
data-ng-value="0" />
<span>{% trans 'No' %}</span>
</label>
</div>

{% endif %}

Expand Down

0 comments on commit fc14aa9

Please sign in to comment.