Skip to content

Commit

Permalink
Refactored the sub-directive choosing in SurveyElement directive
Browse files Browse the repository at this point in the history
  • Loading branch information
pbellon committed Feb 22, 2014
1 parent 2e685e7 commit f1c1a4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
14 changes: 14 additions & 0 deletions app/static/arte_ww/js/directives/surveyElement.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
TYPOLOGIES =
USER:
GENDER: 'user_gender'
AGE: 'user_age'
COUNTRY: 'user_country'
TYPED_NUMBER: 'typed_number'
RADIO_TYPES: ['boolean', 'text_radio', 'media_radio']
SELECTION_TYPES: ['text_selection', 'media_selection']




angular.module('arte-ww').directive 'surveyElement', [
()->
directive =
Expand All @@ -20,6 +32,8 @@ angular.module('arte-ww').directive 'surveyElement', [
]

link: (scope, elem, attrs)->
# let the template use choices typologies for sub-directive selection
scope.TYPOLOGIES = TYPOLOGIES
scope.$watch ->
scope.$eval(attrs.surveyElement)
, (element)->
Expand Down
1 change: 0 additions & 1 deletion app/templates/home.dj.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<script type="text/coffeescript" src="{% static 'arte_ww/js/controllers/SurveyCtrl.coffee' %}"></script>
<script type="text/coffeescript" src="{% static 'arte_ww/js/controllers/ThematicCtrl.coffee' %}"></script>
<script type="text/coffeescript" src="{% static 'arte_ww/js/controllers/ResultsCtrl.coffee' %}"></script>
<script type="text/coffeescript" src="{% static 'arte_ww/js/controllers/RadioQuestionCtrl.coffee' %}"></script>
<!-- services -->
<script type="text/coffeescript" src="{% static 'arte_ww/js/services/User.coffee' %}"></script>
<script type="text/coffeescript" src="{% static 'arte_ww/js/services/UserPosition.coffee' %}"></script>
Expand Down
18 changes: 9 additions & 9 deletions app/templates/partials/directives/survey-element.dj.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<div feedback-static ng-if="element.sub_type == 'static'"></div>
</div>

<div ng-switch-when='question' ng-switch='element.typology'>
<div ng-switch-when='question'>
<!-- user specific question -->
<div ng-switch-when="user_gender" question-user-gender></div>
<div ng-switch-when="user_country" question-user-country></div>
<div ng-switch-when="user_age" question-user-age></div>
<div question-user-gender ng-if="element.typology == TYPOLOGIES.USER.GENDER"></div>
<div question-user-country ng-if="element.typology == TYPOLOGIES.USER.COUNTRY"></div>
<div question-user-age ng-if="element.typology == TYPOLOGIES.USER.AGE"></div>

<!-- all `regular` question -->
<div ng-switch-when="typed_number" question-typed-number></div>
<!-- all radio questions -->
<div ng-if="['boolean', 'text_radio', 'media_radio'].indexOf(element.typology) != -1" question-radio></div>
<!-- all selection questions -->
<div ng-if="['text_selection', 'media_selection'].indexOf(element.typology) != -1" question-selection></div>
<div question-typed-number ng-if="element.typology == TYPOLOGIES.TYPED_NUMBER"></div>

<div question-radio ng-if="TYPOLOGIES.RADIO_TYPES.indexOf(element.typology) != -1"></div>
<div question-selection ng-if="TYPOLOGIES.SELECTION_TYPES.indexOf(element.typology) != -1"></div>
</div>
</div>

0 comments on commit f1c1a4b

Please sign in to comment.