Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. let Person = function(name, sexe) {
  4.   this.name = name;
  5.   this.sexe = sexe;
  6. }
  7.  
  8. let Patient = function(name, sexe, age, symptom) {
  9.   Person.call(this, name, sexe);
  10.   this.age = age;
  11.   this.symptom = symptom;
  12. };
  13.  
  14. Patient.prototype = Object.create(Person.prototype);
  15. Patient.prototype.constructor = Patient;
  16.  
  17. let Doctor = function(name, sexe, specialty) {
  18.   Person.call(this, name, sexe);
  19.   this.specialty = specialty;
  20. };
  21.  
  22. Doctor.prototype = Object.create(Person.prototype);
  23. Doctor.prototype.constructor = Doctor;
  24.  
  25. let hospitalGUI = (function() {
  26.  
  27.   let that = this;
  28.  
  29.   function findConditionObject(symptomOrSpeciality){
  30.     return conditionKeys.find(i => i.name == symptomOrSpeciality);
  31.   }
  32.  
  33.   function generateAppeal(sexe){
  34.     return ( sexe == "male" ) ? "Mr. " : "Ms. ";
  35.   }
  36.  
  37.   function generateDoctorAppeal(sexe){
  38.     return ( sexe === "male" ) ? "Dr. " : "Drs. ";
  39.   }
  40.  
  41.   function getAgeCategory(age){
  42.     return (age < 3) ? "baby" :
  43.  
  44.       (age >= 3 && age < 16) ? "child" :
  45.       (age >= 16 && age < 75) ? "adult" :
  46.       (age >= 75) ? "elderly" : false;
  47.   }
  48.  
  49.   function getDoctorIcon(sexe, conditionObject){
  50.  
  51.         return (sexe == "male") ? personIconMap.create(conditionObject.maleIcon)[0].outerHTML :
  52.         personIconMap.create(conditionObject.femaleIcon)[0].outerHTML;
  53.   }
  54.  
  55.   function getPatientIcon(sexe, age){
  56.     return personIconMap.create(patientIconKeys[sexe][age])[0].outerHTML;
  57.   }
  58.  
  59.   function getOrganIcon(conditionObject){
  60.     return organIconMap.create(conditionObject.icon)[0].outerHTML;
  61.  
  62.   }
  63.  
  64.  
  65.   function renderArticle(personobject) {
  66.  
  67.     let symptomOrSpeciality = (personobject instanceof Doctor) ? personobject.specialty : personobject.symptom;
  68.  
  69.     let ageCategory = getAgeCategory(personobject.age);
  70.  
  71.     let conditionObject = findConditionObject(symptomOrSpeciality);
  72.  
  73.     let doctorOrPatient = (personobject instanceof Doctor) ? "doctor" : "patient";
  74.  
  75.     let data = '<article draggable="true" id="' +
  76.       personobject.name.split(" ").join("-") +
  77.       '" data-type="' +
  78.       doctorOrPatient + '">';
  79.  
  80.     data += "<h3>";
  81.     data += (personobject instanceof Patient) ? generateAppeal(personobject.sexe) :
  82.       generateDoctorAppeal(personobject.sexe);
  83.  
  84.     data += personobject.name;
  85.     data += "</h3><figure>";
  86.  
  87.     //find the organ icon that belongs to the symptom/specialty of the patient/doctor
  88.     data += getOrganIcon(conditionObject);
  89.  
  90.     //find the person icon that belongs the person which depends on the age of the patient or the specialty of the doctor
  91.     //if the person is a doctor, check if it is a male or female.
  92.     data += (personobject instanceof Doctor) ?  getDoctorIcon(personobject.sexe, conditionObject) :
  93.       getPatientIcon(personobject.sexe, ageCategory);
  94.  
  95.     data += "<figcaption>";
  96.     //a doctor has a doctordisplayname and to a patient belongs a displayname
  97.     data += (personobject instanceof Doctor) ? conditionObject.doctorDisplayName : conditionObject.displayName;
  98.     data += "</figcaption></article>";
  99.  
  100.     let object = {
  101.       isDoctor: (personobject instanceof Doctor),
  102.       obj: data
  103.     };
  104.  
  105.     return object;
  106.   }
  107.  
  108.   let displayPeople = function() {
  109.     let myData = [];
  110.  
  111.     let myPeople = personData.map(a => (a["symptom"] != undefined) ? new Patient(a.name, (a.male) ? "male" : "female", a.age, a.symptom) : new Doctor(a.name, (a.male) ? "male" : "female", a.specialty));
  112.  
  113.     myPeople.forEach((person) => {
  114.       myData.push(renderArticle(person));
  115.     });
  116.  
  117.     console.log(myData);
  118.  
  119.     myData.forEach((data) => {
  120.       (data.isDoctor) ? $('footer').append(data.obj):
  121.         $('header').append(data.obj);
  122.     })
  123.   }
  124.  
  125.   let init = function() {
  126.     displayPeople();
  127.   }
  128.  
  129.   // Code voor drag and drop event handling
  130.   let listen = function(e) {
  131.     e.dataTransfer = e.originalEvent.dataTransfer;
  132.     e.dataTransfer.setData("person", e.target.id); // Geef gegevens door op deze manier wanneer je de drag released
  133.  
  134.     // Neat little trick to preserve dragged element's style in Chrome even when it is a link
  135.     if (e.dataTransfer.setDragImage)
  136.       e.dataTransfer.setDragImage(e.target, 0, 0);
  137.   };
  138.  
  139.   let releaseDrag = function(e) {
  140.     console.log('releaseDrag');
  141.     //alert('released');
  142.   };
  143.  
  144.   let showFeedback = function() {
  145.     console.log('showFeedback');
  146.   };
  147.  
  148.   let allowDrop = function(e) {
  149.     e.preventDefault();
  150.   };
  151.  
  152.   // Eigenlijke verwerking van gedropte element
  153.   let checkDropzone = function(e) {
  154.     e.dataTransfer = e.originalEvent.dataTransfer;
  155.  
  156.     var draggedPersonId = e.dataTransfer.getData('person'); // gegevens ophalen
  157.     // Hier verdere logica implementeren
  158.     console.log(draggedPersonId);
  159.     //alert(draggedPersonId);
  160.  
  161.     return false; // Niet verwijderen!
  162.   };
  163.  
  164.   let initDragAndDrop = function() {
  165.     init();
  166.     $('header,footer') // all articles in either header or footer are draggable ...
  167.       .on('dragstart', 'article', listen)
  168.       .on('dragend', 'article', releaseDrag);
  169.  
  170.     $('main figure') // the image (of the hospital) in main allows for persons to be dropped ...
  171.       .on('dragenter', 'img', showFeedback)
  172.       .on('dragleave', 'img', showFeedback)
  173.       .on('dragover', 'img', allowDrop)
  174.       .on('drop', 'img', checkDropzone);
  175.  
  176.     //$('main figure img').on('drop', checkDropzone); // the image (of the hospital) in main allows for persons to be dropped ... -> kan hier ook , want img binnen main figure is statisch end wordt niet dynamisch geladen
  177.  
  178.   }
  179.  
  180.   return {
  181.     init: initDragAndDrop
  182.   }
  183.  
  184. })()
  185.  
  186. //shorthand for document.ready
  187. $(() => {
  188.   hospitalGUI.init();
  189. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement