Skip to content

Commit

Permalink
deleted duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-petranussdorfer committed May 15, 2014
1 parent 1140876 commit 1ec4453
Showing 1 changed file with 0 additions and 168 deletions.
168 changes: 0 additions & 168 deletions js/adapt-contrib-openTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,176 +9,8 @@


define(function(require) {
var QuestionView = require('coreViews/questionView');
var Adapt = require('coreJS/adapt');
var countCharacter = 0;


var OpenTextInput = QuestionView.extend({
events: {
"click .opentextinput-widget .button.save": "onSaveClicked",
"click .opentextinput-widget .button.submit": "onSubmitClicked",
"click .opentextinput-widget .button.model": "onModelAnswerClicked",
"click .opentextinput-widget .button.user": "onUserAnswerClicked",
"keyup .opentextinput-item-textbox": "onKeyUpTextarea"
},


onKeyUpTextarea: function() {
this.countCharacter();
},
countCharacter: function() {
var charLengthOfTextarea = this.$(".opentextinput-item-textbox").val().length;
var allowedCharacters = this.model.get('allowedCharacters');
if (allowedCharacters != null) {
var charactersLeft = allowedCharacters - charLengthOfTextarea;
this.$(".countCharacters").html("Permitted number of characters left: " + charactersLeft);
} else {
this.$(".countCharacters").html("Number of Characters: " + charLengthOfTextarea);
}
},
postRender: function() {
// IMPORTANT!
// Both of the following methods need to be called inside your view.

// Use this to set the model status to ready.
// It should be used when telling Adapt that this view is completely loaded.
// This is sometimes used in conjunction with imageReady.
this.setReadyStatus();

// Use this to set the model status to complete.
// This can be used with inview or when the model is set to complete/the question has been answered.
this.setCompletionStatus();

// Read the last saved answer and paste it into the textarea
this.$(".opentextinput-item-textbox").val(this.getUserAnswer());

this.countCharacter();

QuestionView.prototype.postRender.apply(this);
},
preRender: function() {
this.setupDefaultSettings();
this.resetQuestion({
resetAttempts: true,
initialisingScreen: true
});
// we do not need feedbackarrays
this.listenTo(this.model, 'change:_isEnabled', this.onEnabledChanged);
},
setupDefaultSettings: function() {
// initialize saved status
this.model.set("_isSaved", false);

QuestionView.prototype.setupDefaultSettings.apply(this);
},
supports_html5_storage: function() {
// check for html5 local storage support
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
},
canSubmit: function() {
// function copied from textInput component
var canSubmit = true;
if ($(".opentextinput-item-textbox").val() == "") {
canSubmit = false;
}
return canSubmit;
},
forceFixedPositionFakeScroll: function() {
// function copied from textInput component
if (Modernizr.touch) {
_.defer(function() {
window.scrollTo(document.body.scrollLeft, document.body.scrollTop);
});
}
},
storeUserAnswer: function() {
// store user answer from textarea to localstorage
var userAnswer = this.$(".opentextinput-item-textbox").val();
// use unique identifier to avoid collisions with other components
var identifier = this.model.get('_id') + "-OpenTextInput-UserAnswer";

if (this.supports_html5_storage()) {
localStorage.setItem(identifier, userAnswer);
this.model.set("_isSaved", true);
} else {
console.warn("No local storage available");
}
},
onSaveClicked: function(event) {
console.log(this.model.get("_isSaved"));
event.preventDefault();
this.storeUserAnswer();
},
onSubmitClicked: function(event) {
event.preventDefault();

if (!this.canSubmit()) return;

Adapt.tabHistory = $(event.currentTarget).parent('.inner');

this.model.set({
_isEnabled: false,
_isSubmitted: true,
});
this.$(".component-widget").addClass("submitted user");

this.storeUserAnswer();
this.showFeedback();
// no marks for this question
},
onEnabledChanged: function() {
this.$('.opentextinput-item-textbox').prop('disabled', !this.model.get('_isEnabled'));
},
onModelAnswerShown: function() {
this.$(".opentextinput-item-textbox").val(this.model.get('modelAnswer'));
},
onUserAnswerShown: function() {
this.$(".opentextinput-item-textbox").val(this.getUserAnswer());
},
getUserAnswer: function() {
var identifier = this.model.get('_id') + "-OpenTextInput-UserAnswer";
var userAnswer = '';
if (this.supports_html5_storage()) {
userAnswer = localStorage.getItem(identifier);
} else {
console.warn("No local storage available");
}
return userAnswer;
},
onComplete: function(parameters) {
this.model.set({
_isComplete: true,
_isEnabled: false,
});
this.$(".component-widget").addClass("disabled");
// this.showMarking();
this.showUserAnswer();
Adapt.trigger('questionView:complete', this);
},
showFeedback: function() {

this.model.set('feedbackAudio', this.model.get("feedback").audio);

Adapt.mediator.defaultCallback('questionView:feedback', function(feedback) {
Adapt.trigger('questionView:showFeedback', feedback);
});

Adapt.trigger('questionView:feedback', {
title: this.model.get('title'),
message: this.model.get('feedback').submittedMessage,
audio: this.model.get('feedbackAudio')
});

},
markQuestion: function() {}
});

Adapt.register("opentextinput", OpenTextInput);
var QuestionView = require('coreViews/questionView');
var Adapt = require('coreJS/adapt');

Expand Down

0 comments on commit 1ec4453

Please sign in to comment.