Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
justinfreeman (Agileware)
Core
Commits
9b0a4617
Commit
9b0a4617
authored
11 years ago
by
colemanw
Browse files
Options
Downloads
Plain Diff
Merge pull request #1447 from colemanw/master
Add client-side money formatting
parents
2af30652
5ec182d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Resources.php
+3
-2
3 additions, 2 deletions
CRM/Core/Resources.php
js/Common.js
+29
-0
29 additions, 0 deletions
js/Common.js
with
32 additions
and
2 deletions
CRM/Core/Resources.php
+
3
−
2
View file @
9b0a4617
...
...
@@ -453,9 +453,10 @@ class CRM_Core_Resources {
}
}
// Initialize CRM.url
// Initialize CRM.url
and CRM.formatMoney
$url
=
CRM_Utils_System
::
url
(
'civicrm/example'
,
'placeholder'
,
FALSE
,
NULL
,
FALSE
);
$js
=
"CRM.url('init', '
$url
');"
;
$js
=
"CRM.url('init', '
$url
');
\n
"
;
$js
.
=
"CRM.formatMoney('init', '"
.
CRM_Utils_Money
::
format
(
1234.56
)
.
"');"
;
$this
->
addScript
(
$js
,
$jsWeight
++
,
$region
);
// Add global settings
...
...
This diff is collapsed.
Click to expand it.
js/Common.js
+
29
−
0
View file @
9b0a4617
...
...
@@ -879,4 +879,33 @@ CRM.validate = CRM.validate || {
$
(
this
).
toggleClass
(
'
collapsed
'
);
});
};
/**
* Clientside currency formatting
* @param value
* @param format
* @return string
*/
var
currencyTemplate
;
CRM
.
formatMoney
=
function
(
value
,
format
)
{
var
decimal
,
separator
,
sign
,
i
,
j
,
result
;
if
(
value
===
'
init
'
&&
format
)
{
currencyTemplate
=
format
;
return
;
}
format
=
format
||
currencyTemplate
;
result
=
/1
(
.
?)
234
(
.
?)
56/
.
exec
(
format
);
if
(
result
===
null
)
{
return
'
Invalid format passed to CRM.formatMoney
'
;
}
separator
=
result
[
1
];
decimal
=
result
[
2
];
sign
=
(
value
<
0
)
?
'
-
'
:
''
;
//extracting the absolute value of the integer part of the number and converting to string
i
=
parseInt
(
value
=
Math
.
abs
(
value
).
toFixed
(
2
))
+
''
;
j
=
((
j
=
i
.
length
)
>
3
)
?
j
%
3
:
0
;
result
=
sign
+
(
j
?
i
.
substr
(
0
,
j
)
+
separator
:
''
)
+
i
.
substr
(
j
).
replace
(
/
(\d{3})(?=\d)
/g
,
"
$1
"
+
separator
)
+
(
2
?
decimal
+
Math
.
abs
(
value
-
i
).
toFixed
(
2
).
slice
(
2
)
:
''
);
return
format
.
replace
(
/1.*234.*56/
,
result
);
};
})(
jQuery
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment