'use strict';

module.exports =

/*@ngInject*/
function GrammarActivitiesCreateCmsCtrl (
  $scope, _, GrammarActivity
) {
  $scope.grammarActivity = {};
  $scope.grammarActivity.question_set = [{}];

  function buildConcepts(set) {
    return _.chain(set)
      .map(function (s) {
        return [s.concept_level_0.$id, {
          quantity: s.number_of_questions,
          ruleNumber: s.concept_level_0.ruleNumber
        }];
      })
      .object()
      .value();
  }

  $scope.processGrammarActivityForm = function () {
    console.log('Processing ', $scope.grammarActivity);
    var ga = $scope.grammarActivity;
    var newGrammarActivity = {
      title: ga.title,
      description: ga.description,
      concepts: buildConcepts(ga.question_set)
    };

    console.log(newGrammarActivity);

    GrammarActivity.addToFB(newGrammarActivity).then(function () {
      console.log('Added', newGrammarActivity);
    });
  };
};

'use strict';

module.exports =

/*@ngInject*/
function GrammarActivitiesCreateCmsCtrl (
  $scope, _, GrammarActivity, $state
) {
  $scope.grammarActivity = {};
  $scope.grammarActivity.question_set = [{}];

  function buildConcepts(set) {
    return _.chain(set)
      .map(function (s) {
        return [s.concept_level_0.$id, {
          quantity: s.number_of_questions,
          ruleNumber: s.concept_level_0.ruleNumber
        }];
      })
      .object()
      .value();
  }

  $scope.processGrammarActivityForm = function () {
    var ga = $scope.grammarActivity;
    var newGrammarActivity = {
      title: ga.title,
      description: ga.description,
      concepts: buildConcepts(ga.question_set),
      standard: ga.standard,
      standard_level: ga.standard_level,
      theme: ga.theme
    };


    GrammarActivity.addToFB(newGrammarActivity).then(function () {
      $state.go('cms-grammar-activities');
    });
  };
};

Add standard, standard_level, theme to ga's
Add standard, standard_level, theme to ga's

Go back to the list state after successful creation

See #81
