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