Ejemplo n.º 1
0
 /**
 * Create the competence with the input data and store it to the API.
 */
 createCompetence(){
   var competence = new Competence();
   var user = new User();
   var learningTemplate = new LearningTemplate();
   var superCompetences = this.props.superCompetence ? [this.props.superCompetence] : [];
   //console.log(this.state.title);
   var _this = this;
   let verb2 = '';
   let verb = this.state.verb.split(' ... ');
   if(verb[1]) {
     verb2 = verb[1];
   }
   verb = verb[0];
   let r = {'Tätigkeit': verb, 'Lernziel':this.state.title, 'Tags':this.state.catchwords.length > 0, 'Kategorie':this.state.group};
   let empty = Object.keys(r).filter((k) => !r[k]);
   if(empty.length) {
     Alert.alert('Fehlende Infos.', 'Folgende Felder müssen noch ausgefüllt werden: ' + empty.join(', '), [
       {text: 'Ok, mach ich.'},
     ]);
     return;
   }
   this.setState({loading:true});
   let competenceTitle = ('Ich '+verb+' '+this.state.title+' '+verb2).trim();
   user.isLoggedIn().done((u) => {
     learningTemplate.save({
       userName: u.username,
       groupId: learningTemplate.courseContext,
       selectedTemplate: this.state.group
     })
     .then(() => competence.save({
       forCompetence: competenceTitle,
       operator: this.state.verb,
       catchwords: this.state.catchwords,
       isGoal: this.props.type === 'goals',
       subCompetences: [],
       superCompetences: superCompetences,
       learningProjectName: this.state.group
     }))
     .done(() => {
       this.saveQuestions(competenceTitle);
       let competence = new Competence();
       competence.setItem('reloadGoals', true).then(() => {
         this.props.navigator.pop();
       })
       /*if(this.props.afterCompetenceCreate) {
         this.props.afterCompetenceCreate();
       }*/
     }, (error) => {
       //Errorhandler
       Alert.alert('Erstellen fehlgeschlagen', 'Das Lernziel konnte nicht gespeichert werden.', [
         {text: 'Ok, schade'},
       ]);
       _this.setState({loading:false});
     });
   });
 }
Ejemplo n.º 2
0
 /**
 * Save the default reflection questions to the competence
 * @param competenceId {string}
 */
 saveQuestions(competenceId){
   let u = new User();
   let questions = lib.constants.generalCompetenceQuestions;
   for(var i in questions){
     let q = {
       question: questions[i].text,
       competenceId: competenceId
     };
     u.post('competences/questions', q).then((d) => {
       console.log(d);
     });
   }
 }
Ejemplo n.º 3
0
 .done((d) => {
   if(!d){
     _this.setState({loggingIn:false, loggedIn:d});
     Alert.alert( 'Login fehlgeschlagen', 'Nutzer oder Passwort sind fehlerhaft.', [
       {text: 'Ok', onPress: () => {this.refs.username.focus()}}, ]);
     return false;
   }
   user.login(username, password).done(() => {
     _this.setState({loggingIn:false, loggedIn:d});
     this.props.onLogin();
   });
 });
Ejemplo n.º 4
0
 /**
 * Try to login the user with the given credentials from the input.
 */
 tryLogin(){
   var user = new User(false);
   var _this = this;
   let username = this.state.username,
   password = this.state.password;
   console.log('TRY');
   this.setState({loggingIn:true});
   user.tryLogin(username, password)
     .done((d) => {
       if(!d){
         _this.setState({loggingIn:false, loggedIn:d});
         Alert.alert( 'Login fehlgeschlagen', 'Nutzer oder Passwort sind fehlerhaft.', [
           {text: 'Ok', onPress: () => {this.refs.username.focus()}}, ]);
         return false;
       }
       user.login(username, password).done(() => {
         _this.setState({loggingIn:false, loggedIn:d});
         this.props.onLogin();
       });
     });
 }
Ejemplo n.º 5
0
 constructor(){
   super();
   this.state = {
     selectedTab: 'goals',
     notifCount: 0,
     presses: 0,
     iconsLoaded: 0,
     loggedIn: false,
     checkedLoggedIn: false
   };
   this.systemName = Router.systemName;
   this.user = new User();
   var _this = this;
   this.user.isLoggedIn().done((isIn) => {
     _this.setState({loggedIn: isIn, checkedLoggedIn:true});
   });
   this.afterCompetenceCreate = this.afterCompetenceCreate.bind(this);
   this.updateBadge = this.updateBadge.bind(this);
   //this.test();
 }
Ejemplo n.º 6
0
 onLogin(){
   this.user.isLoggedIn().done((isIn) => {
     this.setState({loggedIn: isIn});
   });
 }