// Copyright (C) 2013 Anders Sundman <anders@4zm.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

'use strict';

angular.module('spira.catalog.plant-editor')
  .controller(
    'PlantEditorCtrl',
    ['$scope', '$http', '$log', '$routeParams',
     function($scope, $http, $log, $routeParams) {

       $scope.species = {};
       $scope.kinds = {};

       $log.info("PlantEditorCtrl");

       $log.info("route params: " + $routeParams);
       $log.info("route id: " + $routeParams.id);


       $scope.saveSpecies = function() {
         $log.info("save species");
       };

       $scope.deleteSpecies = function() {
         $log.info("delete species");
       };


       $scope.addKind = function() {
         $log.info("add kind");
       };

       $scope.deleteKind = function(k) {
         $log.info("delete kind");
       };

       $scope.saveKind = function(k) {
         $log.info("save kind");
       };

       $http.get("/api/species/" + $routeParams.id).
         success(function(response) {
           $scope.species = response;

           $log.info("will now request kinds");
           $http.get("/api/species/" + $routeParams.id + '/kinds').
             success(function(response) {
               $log.info("kind request completed");
               $scope.kinds = response;
             }).
             error(function(response) {
               throw new Error("Error requesting species kinds: " +
                               response.status);
             });
         }).
         error(function(response) {
           throw new Error("Error requesting species: " +
                           response.status);
         });
     }]);


@@ -1290,17 +1290,16 @@
     %7D;%0A%0A
-%0A
        $
@@ -1351,32 +1351,64 @@
 fo(%22add kind%22);%0A
+         $scope.kinds.push(%7B%7D);%0A
        %7D;%0A%0A     
@@ -1435,32 +1435,32 @@
 = function(k) %7B%0A
-
          $log.in
@@ -1470,32 +1470,146 @@
 %22delete kind%22);%0A
+         var i = $scope.kinds.indexOf(k);%0A         if(i != -1) %7B%0A           $scope.kinds.splice(i, 1);%0A         %7D%0A
        %7D;%0A%0A     
@@ -2066,16 +2066,56 @@
 sponse;%0A
+               $log.info($scope.kinds);%0A
         

Support for removing kinds from view model