/**
 * Created by shadeeka on 12/18/15.
 */
angular.module('app.services')
// =========================================================================
// Modal views(popup views) service, create and initialize global popup views
// here
// =========================================================================
  .factory('ModalViews', ['$log','$ionicModal', function ($log, $ionicModal) {
    var _self = this, viewCache = {};
    var ModalViews = {
      init: function () {
        $log.debug("initializing cace views");
        //put all modal views here to cache
        this.lineSettings();
        this.configurations();
        this.operations();
        this.scoreboardConfig();
        this.addPlanAdvanceData();
      },

      getView: function (name) {
        var view;
        switch (name) {
          case "config":
          {
            view = viewCache["config"];
            break;
          }
          case "linesettings":
          {
            view = viewCache["linesettings"];
            break;
          }
          case "operations":
          {
            view = viewCache["operations"];
            break;
          }
          case "scoreboard_config":
          {
            view = viewCache["scoreboard_config"];
            break;
          }
          case "add_plan_advance_behind_master_data":
          {
            view = viewCache["add_plan_advance_behind_master_data"];
            break;
          }
        }
        return view;
      },

      configurations: function () {
        /*------Configuration View------*/
        $log.debug("configurations");
        $ionicModal.fromTemplateUrl('templates/configuration_popup.html', {
          animation: "pop"
        }).then(function (modal) {
          viewCache.config = modal;
        });
      },

      lineSettings: function () {
        $log.debug("lineSettings");
        $ionicModal.fromTemplateUrl('templates/line_settings.html', {
         animation: "pop"
        }).then(function (modal) {
          viewCache.linesettings = modal;
        });
      },
      operations: function () {
        $ionicModal.fromTemplateUrl('templates/operations.html', {
         animation: "pop"
        }).then(function (modal) {
          viewCache.operations = modal;
        });
      },
      scoreboardConfig: function () {
        $ionicModal.fromTemplateUrl('templates/scoreboard_config.html', {
          animation: "pop"
        }).then(function (modal) {
          viewCache.scoreboard_config = modal;
        });
      },
      addPlanAdvanceData: function () {
        $ionicModal.fromTemplateUrl('templates/add_plan_advance_behind_master_data.html', {
          animation: "pop"
        }).then(function (modal) {
          viewCache.add_plan_advance_behind_master_data = modal;
        });
      }
    }
    ModalViews.init();
    return ModalViews;
  }]);
