msgtplui - Always put normal MsgTpl above its translations
[civicrm-core.git] / ext / msgtplui / ang / msgtplui / Edit.js
CommitLineData
2abfa17f
TO
1(function(angular, $, _) {
2
3 angular.module('msgtplui').config(function($routeProvider) {
4 $routeProvider.when('/edit', {
5 controller: 'MsgtpluiEdit',
6 controllerAs: '$ctrl',
7 templateUrl: '~/msgtplui/Edit.html',
8
9 // If you need to look up data when opening the page, list it out
10 // under "resolve".
11 resolve: {
12 myContact: function(crmApi) {
13 return crmApi('Contact', 'getsingle', {
14 id: 'user_contact_id',
15 return: ['first_name', 'last_name']
16 });
17 }
18 }
19 });
20 }
21 );
22
23 // The controller uses *injection*. This default injects a few things:
24 // $scope -- This is the set of variables shared between JS and HTML.
25 // crmApi, crmStatus, crmUiHelp -- These are services provided by civicrm-core.
26 // myContact -- The current contact, defined above in config().
27 angular.module('msgtplui').controller('MsgtpluiEdit', function($scope, crmApi, crmStatus, crmUiHelp, myContact) {
28 // The ts() and hs() functions help load strings for this module.
29 var ts = $scope.ts = CRM.ts('msgtplui');
30 var hs = $scope.hs = crmUiHelp({file: 'CRM/msgtplui/Edit'}); // See: templates/CRM/msgtplui/Edit.hlp
31 // Local variable for this controller (needed when inside a callback fn where `this` is not available).
32 var ctrl = this;
33
34 // We have myContact available in JS. We also want to reference it in HTML.
35 this.myContact = myContact;
36
37 this.save = function() {
38 return crmStatus(
39 // Status messages. For defaults, just use "{}"
40 {start: ts('Saving...'), success: ts('Saved')},
41 // The save action. Note that crmApi() returns a promise.
42 crmApi('Contact', 'create', {
43 id: ctrl.myContact.id,
44 first_name: ctrl.myContact.first_name,
45 last_name: ctrl.myContact.last_name
46 })
47 );
48 };
49 });
50
51})(angular, CRM.$, CRM._);