{I" class:ETI"BundledAsset;FI"logical_path;TI"?social_networking/controllers/profile-answer-controller.js;FI" pathname;TI"{/Users/ems408/workspace/social_networking/app/assets/javascripts/social_networking/controllers/profile-answer-controller.js;FI"content_type;TI"application/javascript;TI" mtime;Tl+,¢kTI" length;Ti6 I" digest;TI"%5b2a6ce1bddf0b2745dcd72decd5c898;FI" source;TI"6 ;(function() { "use strict"; // Provide interaction with a participant's profile answers to profile questions. function ProfileAnswerCtrl(ProfileAnswers) { var self = this; self._answerResource = ProfileAnswers; self.answerModels = {}; self._answerStates = {}; } ProfileAnswerCtrl.prototype.storeAnswer = function(profileId, questionId, controller) { this._answerResource.getOne(profileId, questionId) .then(function(profileAnswer) { controller.answerModels[questionId] = profileAnswer; controller.setModel(profileAnswer, controller); controller._answerStates[questionId] = {}; controller._answerStates[questionId].editable = false; }) .catch(function(error) { controller.answerModels[questionId] = {}; var answerModel = {}; answerModel.profile_id = profileId; answerModel.profile_question_id = questionId; controller.answerModels[questionId] = answerModel; controller._answerStates[questionId] = {}; controller._answerStates[questionId].editable = true; }); }; ProfileAnswerCtrl.prototype.setModel = function(answer, controller) { var answerModel = {}; answerModel.id = answer.id; answerModel.profile_id = answer.profile_id; answerModel.profile_question_id = answer.profile_question_id; answerModel.answer_text = answer.answer_text; controller.answerModels[answer.profile_question_id] = answerModel; }; ProfileAnswerCtrl.prototype.getModel = function(question_id, controller) { return controller.answerModels[question_id]; }; // Initiate answer editor interface. ProfileAnswerCtrl.prototype.edit = function(question_id) { this._answerStates[question_id].editable = true; }; // Exit answer editor interface. ProfileAnswerCtrl.prototype.cancelEdit = function(question_id) { this._answerStates[question_id].editable = false; }; // Persist a profile from the form. ProfileAnswerCtrl.prototype.save = function(profileId, questionId, controller) { var answerModel = controller.getModel(questionId, controller); if (answerModel.id === undefined) { answerModel.profile_id = profileId; answerModel.profile_question_id = questionId; controller._answerResource.create(answerModel).then(function() { controller._answerStates[questionId].editable = false; }).catch(function(message) { controller.error = message.error; }); } else { answerModel.profile_id = profileId; answerModel.profile_question_id = questionId; controller._answerResource.update(answerModel).then(function() { controller._answerStates[questionId].editable = false; }).catch(function(message) { controller.error = message.error; }); } }; // Create a module and register the controllers. angular.module('socialNetworking.controllers') .controller('ProfileAnswerCtrl', ['ProfileAnswers', ProfileAnswerCtrl]); })(); ;TI"required_assets_digest;TI"%46f1fc94c4bfe5734416334276121a1d;FI" _version;TI"%b910479f035fc02c55a3e167aaa8a0b8;F