| 1 |
<?php |
| 2 |
namespace WeDevs\ERP; |
| 3 |
|
| 4 |
use WeDevs\ERP\Framework\Traits\Hooker; |
| 5 |
|
| 6 |
/** |
| 7 |
* Scripts and styles |
| 8 |
*/ |
| 9 |
class Scripts { |
| 10 |
|
| 11 |
use Hooker; |
| 12 |
|
| 13 |
/** |
| 14 |
* Script and style suffix |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $suffix; |
| 19 |
|
| 20 |
/** |
| 21 |
* Script version number |
| 22 |
* |
| 23 |
* @var integer |
| 24 |
*/ |
| 25 |
protected $version; |
| 26 |
|
| 27 |
/** |
| 28 |
* Initialize the class |
| 29 |
*/ |
| 30 |
public function __construct() { |
| 31 |
$this->suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 32 |
$this->version = '20150314'; |
| 33 |
|
| 34 |
$this->action( 'admin_enqueue_scripts', 'scripts_handler' ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Register and enqueue scripts and styles |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
public function scripts_handler() { |
| 43 |
$this->register_scripts(); |
| 44 |
$this->register_styles(); |
| 45 |
|
| 46 |
$this->enqueue_scripts(); |
| 47 |
$this->enqueue_styles(); |
| 48 |
} |
| 49 |
|
| 50 |
public function register_scripts() { |
| 51 |
|
| 52 |
// wp_register_script( $handle, $src, $deps, $ver, $in_footer ); |
| 53 |
$vendor = WPERP_ASSETS . '/vendor'; |
| 54 |
$js = WPERP_ASSETS . '/js'; |
| 55 |
|
| 56 |
// register vendors first |
| 57 |
wp_register_script( 'erp-select2', $vendor . '/select2/select2.full.min.js', array( 'jquery' ), $this->version, true ); |
| 58 |
wp_register_script( 'erp-tiptip', $vendor . '/tiptip/jquery.tipTip.min.js', array( 'jquery' ), $this->version, true ); |
| 59 |
wp_register_script( 'erp-momentjs', $vendor . '/moment/moment.min.js', false, $this->version, true ); |
| 60 |
wp_register_script( 'erp-fullcalendar', $vendor . '/fullcalendar/fullcalendar' . $this->suffix . '.js', array( 'jquery', 'erp-momentjs' ), $this->version, true ); |
| 61 |
wp_register_script( 'erp-timepicker', $vendor . '/timepicker/jquery.timepicker.min.js', array( 'jquery', 'erp-momentjs' ), $this->version, true ); |
| 62 |
wp_register_script( 'erp-vuejs', $vendor . '/vue/vue' . $this->suffix . '.js', array( 'jquery' ), $this->version, true ); |
| 63 |
wp_register_script( 'erp-trix-editor', $vendor . '/trix/trix.js', array( 'jquery' ), $this->version, true ); |
| 64 |
wp_register_script( 'erp-nprogress', $vendor . '/nprogress/nprogress.js', array( 'jquery' ), $this->version, true ); |
| 65 |
wp_register_script( 'erp-jvectormap', $vendor . '/jvectormap/jvectormap.min.js', array( 'jquery' ), $this->version, true ); |
| 66 |
wp_register_script( 'erp-jvectormap-world-mill', $vendor . '/jvectormap/jvectormap-world-mill.js', array( 'jquery' ), $this->version, true ); |
| 67 |
|
| 68 |
// sweet alert |
| 69 |
wp_register_script( 'erp-sweetalert', $vendor . '/sweetalert/sweetalert.min.js', array( 'jquery' ), $this->version, true ); |
| 70 |
|
| 71 |
// flot chart |
| 72 |
wp_register_script( 'erp-flotchart', $vendor . '/flot/jquery.flot.min.js', array( 'jquery' ), $this->version, true ); |
| 73 |
wp_register_script( 'erp-flotchart-time', $vendor . '/flot/jquery.flot.time.min.js', array( 'jquery' ), $this->version, true ); |
| 74 |
wp_register_script( 'erp-flotchart-orerbars', $vendor . '/flot/jquery.flot.orderBars.js', array( 'jquery' ), $this->version, true ); |
| 75 |
wp_register_script( 'erp-flotchart-pie', $vendor . '/flot/jquery.flot.pie.min.js', array( 'jquery' ), $this->version, true ); |
| 76 |
wp_register_script( 'erp-flotchart-axislables', $vendor . '/flot/jquery.flot.axislabels.js', array( 'jquery' ), $this->version, true ); |
| 77 |
wp_register_script( 'erp-flotchart-categories', $vendor . '/flot/jquery.flot.categories.js', array( 'jquery' ), $this->version, true ); |
| 78 |
wp_register_script( 'erp-flotchart-tooltip', $vendor . '/flot/jquery.flot.tooltip.min.js', array( 'jquery' ), $this->version, true ); |
| 79 |
wp_register_script( 'erp-flotchart-resize', $vendor . '/flot/jquery.flot.resize.min.js', array( 'jquery' ), $this->version, true ); |
| 80 |
wp_register_script( 'erp-flotchart-valuelabel', $vendor . '/flot/jquery.flot.valuelabels.js', array( 'jquery' ), $this->version, true ); |
| 81 |
wp_register_script( 'erp-flotchart-navigate', $vendor . '/flot/jquery.flot.navigate.js', array( 'jquery' ), $this->version, true ); |
| 82 |
wp_register_script( 'erp-flotchart-selection', $vendor . '/flot/jquery.flot.selection.js', array( 'jquery' ), $this->version, true ); |
| 83 |
wp_register_script( 'erp-flotchart-stack', $vendor . '/flot/jquery.flot.stack.js', array( 'jquery' ), $this->version, true ); |
| 84 |
|
| 85 |
// core js files |
| 86 |
wp_register_script( 'erp-popup', $js . '/jquery-popup' . $this->suffix . '.js', array( 'jquery' ), $this->version, true ); |
| 87 |
wp_register_script( 'erp-script', $js . '/erp' . $this->suffix . '.js', array( 'jquery', 'backbone', 'underscore', 'wp-util', 'jquery-ui-datepicker' ), $this->version, true ); |
| 88 |
wp_register_script( 'erp-file-upload', $js . '/upload' . $this->suffix . '.js', array( 'jquery', 'plupload-handlers' ), $this->version, true ); |
| 89 |
wp_register_script( 'erp-admin-settings', $js . '/settings' . $this->suffix . '.js', array( 'jquery' ), $this->version, true ); |
| 90 |
wp_register_script( 'erp-system-status', $js . '/system-status' . $this->suffix . '.js', array( 'jquery' ), $this->version, true ); |
| 91 |
|
| 92 |
// tether.js |
| 93 |
wp_register_script( 'erp-tether-main', $vendor . '/tether/tether.min.js', array( 'jquery' ), $this->version, true ); |
| 94 |
wp_register_script( 'erp-tether-drop', $vendor . '/tether/drop.min.js', array( 'jquery' ), $this->version, true ); |
| 95 |
|
| 96 |
// clipboard.js |
| 97 |
wp_register_script( 'erp-clipboard', $vendor . '/clipboard/clipboard.min.js', array( 'jquery' ), $this->version, true ); |
| 98 |
|
| 99 |
// toastr.js |
| 100 |
wp_register_script( 'erp-toastr', $vendor . '/toastr/toastr.min.js', array(), $this->version, true ); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Register all the styles |
| 105 |
* |
| 106 |
* @return void |
| 107 |
*/ |
| 108 |
public function register_styles() { |
| 109 |
$vendor = WPERP_ASSETS . '/vendor'; |
| 110 |
$css = WPERP_ASSETS . '/css'; |
| 111 |
|
| 112 |
wp_register_style( 'erp-fontawesome', $vendor . '/fontawesome/font-awesome.min.css', false, $this->version ); |
| 113 |
wp_register_style( 'erp-select2', $vendor . '/select2/select2.min.css', false, $this->version ); |
| 114 |
wp_register_style( 'erp-tiptip', $vendor . '/tiptip/tipTip.css', false, $this->version ); |
| 115 |
wp_register_style( 'erp-fullcalendar', $vendor . '/fullcalendar/fullcalendar' . $this->suffix . '.css', false, $this->version ); |
| 116 |
wp_register_style( 'erp-timepicker', $vendor . '/timepicker/jquery.timepicker.css', false, $this->version ); |
| 117 |
wp_register_style( 'erp-trix-editor', $vendor . '/trix/trix.css', false, $this->version ); |
| 118 |
wp_register_style( 'erp-flotchart-valuelabel-css', $vendor . '/flot/plot.css', false, $this->version ); |
| 119 |
wp_register_style( 'erp-nprogress', $vendor . '/nprogress/nprogress.css', false, $this->version ); |
| 120 |
wp_register_style( 'erp-jvectormap', $vendor . '/jvectormap/jvectormap.css', false, $this->version ); |
| 121 |
|
| 122 |
// jquery UI |
| 123 |
wp_register_style( 'jquery-ui', $vendor . '/jquery-ui/jquery-ui-1.9.1.custom.css' ); |
| 124 |
|
| 125 |
// sweet alert |
| 126 |
wp_register_style( 'erp-sweetalert', $vendor . '/sweetalert/sweetalert.css', false, $this->version ); |
| 127 |
|
| 128 |
// tether drop theme |
| 129 |
wp_register_style( 'erp-tether-drop-theme', $vendor . '/tether/drop-theme.min.css', false, $this->version ); |
| 130 |
|
| 131 |
// toastr.js |
| 132 |
wp_register_style( 'erp-toastr', $vendor . '/toastr/toastr.min.css', false, $this->version ); |
| 133 |
|
| 134 |
// core css files |
| 135 |
wp_register_style( 'erp-styles', $css . '/admin.css', false, $this->version ); |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Enqueue the scripts |
| 141 |
* |
| 142 |
* @return void |
| 143 |
*/ |
| 144 |
public function enqueue_scripts() { |
| 145 |
$screen = get_current_screen(); |
| 146 |
$screen_base = isset( $screen->base ) ? $screen->base : false; |
| 147 |
$hook = str_replace( sanitize_title( __( 'HR Management', 'erp' ) ) , 'hr-management', $screen_base ); |
| 148 |
|
| 149 |
wp_enqueue_script( 'erp-select2' ); |
| 150 |
wp_enqueue_script( 'erp-popup' ); |
| 151 |
wp_enqueue_script( 'erp-script' ); |
| 152 |
|
| 153 |
wp_localize_script( 'erp-script', 'wpErp', array( |
| 154 |
'nonce' => wp_create_nonce( 'erp-nonce' ), |
| 155 |
'set_logo' => __( 'Set company logo', 'erp' ), |
| 156 |
'upload_logo' => __( 'Upload company logo', 'erp' ), |
| 157 |
'remove_logo' => __( 'Remove company logo', 'erp' ), |
| 158 |
'update_location' => __( 'Update Location', 'erp' ), |
| 159 |
'create' => __( 'Create', 'erp' ), |
| 160 |
'update' => __( 'Update', 'erp' ), |
| 161 |
'confirmMsg' => __( 'Are you sure?', 'wpuf' ), |
| 162 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 163 |
'plupload' => array( |
| 164 |
'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'erp_featured_img' ), |
| 165 |
'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), |
| 166 |
'filters' => array(array('title' => __( 'Allowed Files' ), 'extensions' => '*')), |
| 167 |
'multipart' => true, |
| 168 |
'urlstream_upload' => true, |
| 169 |
) |
| 170 |
) ); |
| 171 |
|
| 172 |
wp_enqueue_script( 'erp-menu', WPERP_ASSETS . "/js/erp-menu.js", array(), date( 'Ymd' ), true ); |
| 173 |
|
| 174 |
// load country/state JSON on new company page |
| 175 |
if ( 'wp-erp_page_erp-company' == $hook || isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'new', 'edit' ) ) ) { |
| 176 |
wp_enqueue_script( 'post' ); |
| 177 |
wp_enqueue_media(); |
| 178 |
|
| 179 |
$country = \WeDevs\ERP\Countries::instance(); |
| 180 |
wp_localize_script( 'erp-script', 'wpErpCountries', $country->load_country_states() ); |
| 181 |
} |
| 182 |
|
| 183 |
if ( 'hr-management_page_erp-hr-employee' == $hook ) { |
| 184 |
$country = \WeDevs\ERP\Countries::instance(); |
| 185 |
wp_localize_script( 'erp-script', 'wpErpCountries', $country->load_country_states() ); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Enqueue the stylesheet |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
public function enqueue_styles() { |
| 197 |
wp_enqueue_style( 'erp-fontawesome' ); |
| 198 |
wp_enqueue_style( 'erp-select2' ); |
| 199 |
wp_enqueue_style( 'jquery-ui' ); |
| 200 |
|
| 201 |
wp_enqueue_style( 'erp-styles' ); |
| 202 |
} |
| 203 |
} |
| 204 |
|