Advertisement
Guest User

polymerajax

a guest
Apr 26th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 5.09 KB | None | 0 0
  1. <link rel="import" href="../../../bower_components/polymer/polymer.html">
  2. <link rel="import" href="../../../bower_components/iron-form/iron-form.html">
  3. <link rel="import" href="../../../bower_components/iron-fit-behavior/iron-fit-behavior.html">
  4. <link rel="import" href="../../../bower_components/paper-input/paper-input.html">
  5. <link rel="import" href="../../../bower_components/iron-label/iron-label.html">
  6. <link rel="import" href="../../../bower_components/paper-button/paper-button.html">
  7. <link rel="import" href="../../../bower_components/marked-element/marked-element.html">
  8. <link rel="import" href="../../../bower_components/paper-toast/paper-toast.html">
  9. <link rel="import" href="../../../bower_components/paper-radio-group/paper-radio-group.html">
  10. <link rel="import" href="../../../bower_components/paper-radio-button/paper-radio-button.html">
  11. <link rel="import" href="../../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
  12.  
  13. <!-- you are missing this import -->
  14. <link rel="import" href="../../../bower_components/iron-ajax/iron-ajax.html" />
  15.  
  16. <dom-module id="generic-question">
  17.     <style is="custom-style" include="iron-flex iron-flex-alignment">
  18.     .outer {
  19.         display: inline-flex;
  20.         flex-wrap: wrap;
  21.         flex-direction: row;
  22.     }
  23.    
  24.     .correct {
  25.         color: green;
  26.     }
  27.    
  28.     .wrong {
  29.         color: red;
  30.     }
  31.    
  32.     .inner {
  33.         display: inline-flex;
  34.         flex-wrap: wrap;
  35.         flex-direction: column;
  36.     }
  37.    
  38.     .mcq-body {
  39.         padding: 10px;
  40.     }
  41.     </style>
  42.  
  43.     <template>
  44.     <p>Path: [[path]] or ComputedUrl: [[url]]</p>
  45.         <iron-ajax auto url="[[url]]" handle-as="json" last-response="{{questions}}"></iron-ajax>
  46.         <template is="dom-repeat" items="{{questions}}">
  47.         <div class="outer">
  48.             <div class="inner">
  49.                 <div id="mcqbody" class="mcq-body">
  50.                     <div class="question" name="question">{{item.question}}</div>
  51.                     <paper-radio-group id="mcq" class="layout vertical wrap" selected="{{selection}}">
  52.                         <paper-radio-button name="resp1">{{item.reponseB}}</paper-radio-button>
  53.                         <paper-radio-button name="resp2">{{item.reponseF}}</paper-radio-button>
  54.                         <paper-radio-button name="resp3">{{item.reponseM}}</paper-radio-button>
  55.                     </paper-radio-group>
  56.                     <iron-collapse id="correct" opened="{{open1}}">
  57.                         <paper-input class="correct" text="">
  58.                             <iron-icon icon="check-circle" prefix></iron-icon>
  59.                             <div prefix> Correct</div>
  60.                         </paper-input>
  61.                     </iron-collapse>
  62.                     <iron-collapse id="wrong" opened="{{open2}}">
  63.                         <paper-input class="wrong" text="">
  64.                             <iron-icon icon="cancel" prefix></iron-icon>
  65.                             <div prefix> Faux</div>
  66.                         </paper-input>
  67.                     </iron-collapse>
  68.                     <iron-collapse id="wrong" opened="{{open3}}">
  69.                         <paper-input class="wrong" text="">
  70.                             <iron-icon icon="cancel" prefix></iron-icon>
  71.                             <div prefix> Veuillez répondre à la question </div>
  72.                         </paper-input>
  73.                     </iron-collapse>
  74.                     <div style="margin-top:40px" class="card-actions">
  75.                         <paper-button raised on-tap="validate">Validate</paper-button>
  76.                         <paper-button raised on-tap="next">Next</paper-button>
  77.                     </div>
  78.                 </div>
  79.             </div>
  80.         </div>
  81.         </template>
  82.  
  83.     </template>
  84.     <script>
  85.     (function() {
  86.         'use strict';
  87.         Polymer({
  88.             is: 'generic-question',
  89.             validate: function() {
  90.                 if (this.selection == "resp1" ) {
  91.                     this.open1 = true;
  92.                     this.open2 = false;
  93.                     this.open3 = false;
  94.                    
  95.                 } else {
  96.                     this.open2 = true;
  97.                     this.open1 = false;
  98.                     this.open3 = false;
  99.                 }        
  100.             },
  101.  
  102.             next: function() {
  103.                 if (this.open1 == true) {
  104.                     this.fire('nextQuestion', true);
  105.                 } else {
  106.                     this.open3 = true;
  107.                     this.open2 = false;
  108.                 }
  109.                
  110.             },
  111.  
  112.             properties: {
  113.                 "path": {
  114.                     type: String,
  115.                     value: function() {
  116.                         return 'listQuestions1';
  117.                     }
  118.                 },
  119.                 "url: {
  120.                     type: String,
  121.                     computed: 'computeUrl(path)'
  122.                 },
  123.                 "questions": {
  124.                     type: Object
  125.                 }
  126.             },
  127.             computeUrl: function(path) {
  128.                 return 'questions/' + path + '.json';
  129.             }
  130.         });
  131.     })();
  132.     </script>
  133. </dom-module>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement