1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\assets; |
4
|
|
|
|
5
|
|
|
use DomainException; |
6
|
|
|
use EE_Currency_Config; |
7
|
|
|
use EventEspresso\core\domain\DomainInterface; |
8
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
9
|
|
|
use EventEspresso\core\exceptions\InvalidEntityException; |
10
|
|
|
use EventEspresso\core\services\assets\AssetCollection; |
11
|
|
|
use EventEspresso\core\services\assets\AssetManager; |
12
|
|
|
use EventEspresso\core\services\assets\Registry; |
13
|
|
|
use EventEspresso\core\services\collections\DuplicateCollectionIdentifierException; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* LegacyEditorAssetManager |
18
|
|
|
* assets for the EE legacy event editor |
19
|
|
|
* |
20
|
|
|
* @package EventEspresso\core\domain\services\assets |
21
|
|
|
* @author Brent Christensen |
22
|
|
|
* @since $VID:$ |
23
|
|
|
*/ |
24
|
|
|
class LegacyEditorAssetManager extends AssetManager |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
const JS_HANDLE_UNDERSCORE = 'underscore'; |
28
|
|
|
const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
29
|
|
|
const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var EE_Currency_Config $currency_config |
34
|
|
|
*/ |
35
|
|
|
protected $currency_config; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* CoreAssetRegister constructor. |
39
|
|
|
* |
40
|
|
|
* @param AssetCollection $assets |
41
|
|
|
* @param DomainInterface $domain |
42
|
|
|
* @param Registry $registry |
43
|
|
|
* @param EE_Currency_Config $currency_config |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
AssetCollection $assets, |
47
|
|
|
DomainInterface $domain, |
48
|
|
|
Registry $registry, |
49
|
|
|
EE_Currency_Config $currency_config |
50
|
|
|
) { |
51
|
|
|
$this->currency_config = $currency_config; |
52
|
|
|
parent::__construct($domain, $assets, $registry); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @throws InvalidDataTypeException |
59
|
|
|
* @throws InvalidEntityException |
60
|
|
|
* @throws DuplicateCollectionIdentifierException |
61
|
|
|
* @throws DomainException |
62
|
|
|
*/ |
63
|
|
|
public function addAssets() |
64
|
|
|
{ |
65
|
|
|
$this->loadAccountingJs(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* accounting.js for performing client-side calculations |
71
|
|
|
* |
72
|
|
|
* @throws DomainException |
73
|
|
|
* @throws DuplicateCollectionIdentifierException |
74
|
|
|
* @throws InvalidDataTypeException |
75
|
|
|
* @throws InvalidEntityException |
76
|
|
|
* @since $VID:$ |
77
|
|
|
*/ |
78
|
|
|
private function loadAccountingJs() |
79
|
|
|
{ |
80
|
|
|
//accounting.js library |
81
|
|
|
// @link http://josscrowcroft.github.io/accounting.js/ |
82
|
|
|
$this->addJavascript( |
83
|
|
|
LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
84
|
|
|
EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
85
|
|
|
[LegacyEditorAssetManager::JS_HANDLE_UNDERSCORE], |
86
|
|
|
true, |
87
|
|
|
'0.3.2' |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$this->addJavascript( |
91
|
|
|
LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
92
|
|
|
EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
93
|
|
|
[LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
94
|
|
|
) |
95
|
|
|
->setInlineDataCallback( |
96
|
|
|
function () { |
97
|
|
|
wp_localize_script( |
98
|
|
|
LegacyEditorAssetManager::JS_HANDLE_ACCOUNTING, |
99
|
|
|
'EE_ACCOUNTING_CFG', |
100
|
|
|
$this->getAccountingSettings() |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns configuration data for the accounting-js library. |
109
|
|
|
* |
110
|
|
|
* @return array |
111
|
|
|
* @since $VID:$ |
112
|
|
|
*/ |
113
|
|
|
private function getAccountingSettings() |
114
|
|
|
{ |
115
|
|
|
return [ |
116
|
|
|
'currency' => [ |
117
|
|
|
'symbol' => $this->currency_config->sign, |
118
|
|
|
'format' => [ |
119
|
|
|
'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
120
|
|
|
'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
121
|
|
|
'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
122
|
|
|
], |
123
|
|
|
'decimal' => $this->currency_config->dec_mrk, |
124
|
|
|
'thousand' => $this->currency_config->thsnds, |
125
|
|
|
'precision' => $this->currency_config->dec_plc, |
126
|
|
|
], |
127
|
|
|
'number' => [ |
128
|
|
|
'precision' => $this->currency_config->dec_plc, |
129
|
|
|
'thousand' => $this->currency_config->thsnds, |
130
|
|
|
'decimal' => $this->currency_config->dec_mrk, |
131
|
|
|
], |
132
|
|
|
]; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|