Demo entry 3549098

printoutCode

   

Submitted by anonymous on Jan 21, 2016 at 17:03
Language: JavaScript+Ruby. Code size: 8.1 kB.

Angular broadcasts

View controller

	orderChanged function
	$rootScope.$broadcast('questionOrderChanged', questionIndex);
		to question Directive
			  $rootScope.$on('questionOrderChanged', function(e, questionIndex, deletedQuestionId) {
			    if (vm.question.number != questionIndex[vm.question.id]) {
			      vm.question.number = questionIndex[vm.question.id];
			    }
			    if (deletedQuestionId != vm.question.id) {
			      saveQuestion();
			    }
			  });
		======to response Directive======
			$rootScope.$on('questionOrderChanged', function(e, questionIndex){
		    vm.response.next_question_number = Survey.questionIndex[vm.response.next_question_id];
		    vm.questionNum = changeNextQuestion(vm.response.next_question_number, vm.response.next_question_id);
		  });

Seems to have nothing connected to it....
	$rootScope.$on('revalidateSurvey', function() {
	  validateSurvey();
	})

$scope.$watch( 'vm.survey.child_survey_count', function(){



$scope.$watch(function() {return initialSurveyValues(vm)}, function() {

$rootScope.$broadcast('saveAllQuestionsNow');
	===== to question directive ===== 
		 $rootScope.$on('saveAllQuestionsNow', function(e) {
	    saveQuestion();
	  });

$rootScope.$broadcast('changeQuestionsOpenState', vm.questionsOpenState);
	===== to question Directive =====
		$rootScope.$on('changeQuestionsOpenState', function(e, state) {
	    clickShowContentGlobal(state);
	  });

$rootScope.$broadcast('surveyUpdate', vm.survey.name, vm.survey.campaign_read_url, vm.survey.templates_for_survey);
	===== to app controller ======
	  $rootScope.$on('surveyUpdate', function(e, name, url, templates) {
	    vm.surveyName = name;
	    vm.surveyURL = url;
	    vm.surveyTemplates = templates;
	  });




Question Directive





Seems to not be connected to anything.....
  $scope.$on('notSaved', function() {
    vm.responsesNotSaved = true;
    setIsSaved();
  });


$scope.$broadcast('save!', vm.question.id);
	====== to resposne directive ======
		$scope.$on("save!", function(e, question_id){
	    var data = buildResponseData()
	    if (vm.response.number != '' && vm.response.canonical_number != '' && vm.response.response_text != '' && vm.response.coded_response != '') {
	      if (vm.response.id) {
	        updateResponse(question_id, vm.response.id, data)
	      } else {
	        createResponse(question_id, data);
	      }
	    }
	  });

$rootScope.$broadcast('questionUpdated');
	===== to view controller=====
		$rootScope.$on('questionUpdate', function() {
		  var questionIndex = createQuestionIndex(vm.survey);
		  Survey.questionIndex = questionIndex;
		  Survey.numOfQuestions = vm.survey.questions.length;
		  $rootScope.$broadcast('questionOrderChanged', questionIndex);
		  validateSurvey();
		});
			======to question Directive=======
			  $rootScope.$on('questionOrderChanged', function(e, questionIndex, deletedQuestionId) {
			    if (vm.question.number != questionIndex[vm.question.id]) {
			      vm.question.number = questionIndex[vm.question.id];
			    }
			    if (deletedQuestionId != vm.question.id) {
			      saveQuestion();
			    }
			  });
			======to response Directive=======
				$rootScope.$on('questionOrderChanged', function(e, questionIndex){
			    vm.response.next_question_number = Survey.questionIndex[vm.response.next_question_id];
			    vm.questionNum = changeNextQuestion(vm.response.next_question_number, vm.response.next_question_id);
			  });

$scope.$emit('saveStateChange', vm.question.id, vm.isSaved);
$scope.$emit('saveStateChange', vm.question.id, true);
	===== to view controller=====
		$scope.$on('saveStateChange', function(e, questionId, saveState) {
		  vm.saveStates[questionId] = saveState;
		});

$rootScope.$broadcast('questionCreated', vm.question);
	====to view controller
		$rootScope.$on('questionCreated', function(e, question) {
		  if (question.from_bank) {
		    addQuestionToCurrentSurvey(question)
		  } else {
		    vm.survey.questions.forEach(function(q, i) {
		      if (q.number === question.number && q.question_text === question.question_text) {
		        vm.survey.questions[i] = question;
		      }
		    });
		  }
		  var questionIndex = createQuestionIndex(vm.survey);
		  Survey.questionIndex = questionIndex;
		  Survey.numOfQuestions = vm.survey.questions.length;
		  $rootScope.$broadcast('questionOrderChanged', questionIndex);
		  validateSurvey();
		});
			=====to question Directive
			  $rootScope.$on('questionOrderChanged', function(e, questionIndex, deletedQuestionId) {
			    if (vm.question.number != questionIndex[vm.question.id]) {
			      vm.question.number = questionIndex[vm.question.id];
			    }
			    if (deletedQuestionId != vm.question.id) {
			      saveQuestion();
			    }
			  });
			=====to response Directive
				$rootScope.$on('questionOrderChanged', function(e, questionIndex){
			    vm.response.next_question_number = Survey.questionIndex[vm.response.next_question_id];
			    vm.questionNum = changeNextQuestion(vm.response.next_question_number, vm.response.next_question_id);
			  });



$rootScope.$broadcast('question-deleted', vm.question);
	==== to view controller =====
		$rootScope.$on('question-deleted', function(e, question) {
			  var index = vm.survey.questions.indexOf(question);
			  var deletedQuestionId = question.id;
			  if (index > -1) {
			    vm.survey.questions.splice(index, 1);
			    var questionIndex = createQuestionIndex(vm.survey);
			    Survey.questionIndex = questionIndex;
			    Survey.numOfQuestions = vm.survey.questions.length;
			    $rootScope.$broadcast('questionOrderChanged', questionIndex, deletedQuestionId);
			    validateSurvey();
			  }
			});
				====to question Directive======
				  $rootScope.$on('questionOrderChanged', function(e, questionIndex, deletedQuestionId) {
				    if (vm.question.number != questionIndex[vm.question.id]) {
				      vm.question.number = questionIndex[vm.question.id];
				    }
				    if (deletedQuestionId != vm.question.id) {
				      saveQuestion();
				    }
				  });
				====to response Directive=======
					$rootScope.$on('questionOrderChanged', function(e, questionIndex){
				    vm.response.next_question_number = Survey.questionIndex[vm.response.next_question_id];
				    vm.questionNum = changeNextQuestion(vm.response.next_question_number, vm.response.next_question_id);
				  });





Response Directive




$rootScope.$broadcast('responseCreated', vm.question.number, vm.response);
	===== to view controller ======
		$rootScope.$on('responseCreated', function(e, questionNumber, response){
		  vm.survey.questions.forEach(function(q) {
		    if (q.id === response.question_id) {
		      q.responses[response.number - 1] = response;
		    }
		  });
		  validateSurvey();
		});
Seems to not be connected to anything
	$rootScope.$broadcast('responseUpdated', vm.question.number, vm.response);


$rootScope.$broadcast('responseDeleted', vm.question.id, vm.response);
$rootScope.$broadcast('responseDeleted', vm.question, vm.response);
	===== to question directive =====
		$rootScope.$on('responseDeleted', function(e, questionId, response) {
	    $timeout(reorderResponses(), 500);
	  });



Response Table Directive




$rootScope.$broadcast('responseOrderFromModal', $scope.responseData)
	=====to response table Directive=======
			$rootScope.$on('responseOrderFromModal', function(e, response){
		    $scope.savedData= response;
		  });

$rootScope.$broadcast("responseOrderChanged", $scope.savedData)
	======To Response Directive=======
		$scope.$on('responseOrderChanged', function(e, responses) {
	    responses.forEach(function(response) {
	      if(response.parent_response_id === vm.response.id) {
	        Response.update(response.question_id, response.id, response)
	      }
	      if(response.id ===  vm.response.id) { 
	        updateResponse(response.question_id, response.id, response)
	      }
	    })
	  })

This snippet took 0.03 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).