<?php

/*
  Copyright (C) <{$year}>  {$author}  <{$email}>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  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 General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * Main Model
 * 
 * @package WordPress
 * @subpackage {$plugin_label}
 * @author {$author} <{$email}>
 */
class {$prefix}view_View {
    
	/**
     * Control Node
     * 
     * @var {$prefix}_control_Control 
     * @access protected
     */
    protected $control_node;
    
    /**
     * Model Node
     * 
     * @var {$prefix}_model_Model 
     * @access protected
     */
    protected $model_node;

    /**
     * Constructor
     * 
     * @access public
     * @param {$prefix}_control_Control  $control
     */
    function __construct($control) {

        $this->control_node = $control;
		
        if (is_admin()){
                add_action('admin_print_scripts', array($this, 'admin_print_scripts'));
                add_action('admin_print_styles', array($this, 'admin_print_styles'));
        }else{
            $this->printFrontScripts();
            $this->printFrontStyles();
        }
    }
    
    /**
     * Set Model Node
     * 
     * @access public
     * @param {$prefix}_model_Model $model_node
     */
    public function setModelNode($model_node) {
        
        $this->model_node = $model_node;
    }

    /**
     * Register fron JS libraries
     * 
     * @access public
     */
    public function printFrontScripts() {
		
        if ($this->loadJSCSS('front')) {
        }
    }

    /**
     * Print front styles
     * 
     * @access public
     */
    public function printFrontStyles() {
		
        if ($this->loadJSCSS('front')) {
        }
    }

    /**
     * Render proper js scripts
     * 
     * @access public
     */
    public function admin_print_scripts() {

        if ($this->loadJSCSS('admin')) {
            wp_enqueue_script({$plugin_name_upper}_PREFIX . 'admin-general', {$plugin_name_upper}_JS_DIR . 'admin-general.js');
            wp_localize_script({$plugin_name_upper}_PREFIX . 'admin-general', {$plugin_name_upper}_PREFIX . '{$plugin_name}_local', array(
                    'nonce' => $this->model_node->getNonce(),
            ));
        }
    }

    /**
     * Render proper CSS stylesheets
     * 
     * @access public
     */
    public function admin_print_styles() {
		
        if ($this->loadJSCSS('admin')) {
            wp_enqueue_style({$plugin_name_upper}_PREFIX . 'admin-general', {$plugin_name_upper}_CSS_DIR . 'admin-general.css');
        }
    }

    /**
     * Check if is necessary to load Additional JS script and CSS
     * 
     * @param string Mode - Admin or Front
     * @return boolrsn TRUE if can be loaded
     */
    protected function loadJSCSS($mode = 'admin') {

        $result = FALSE;
        switch ($mode) {
            case 'admin':
                if (is_admin()) {
                    $result = TRUE;
                }
                break;

            case 'front':
                $result = TRUE;
                break;

            default:
                break;
        }

        return $result;
    }

}

?>