1 (function(angular
, $, _
) {
3 angular
.module('crmDashboard').component('crmDashboard', {
4 templateUrl
: '~/crmDashboard/Dashboard.html',
5 controller: function ($scope
, $element
, crmApi4
, crmUiHelp
, dialogService
, crmStatus
) {
6 var ts
= $scope
.ts
= CRM
.ts(),
8 this.columns
= [[], []];
10 this.contactDashlets
= {};
11 this.sortableOptions
= {
12 connectWith
: '.crm-dashboard-droppable',
13 handle
: '.crm-dashlet-header'
15 $scope
.hs
= crmUiHelp({file
: 'CRM/Contact/Page/Dashboard'});
17 this.$onInit = function() {
18 // Sort dashlets into columns
19 _
.each(CRM
.crmDashboard
.dashlets
, function(dashlet
) {
20 if (dashlet
['dashboard_contact.is_active']) {
21 ctrl
.columns
[dashlet
['dashboard_contact.column_no']].push(dashlet
);
23 ctrl
.inactive
.push(dashlet
);
27 $scope
.$watchCollection('$ctrl.columns[0]', onChange
);
28 $scope
.$watchCollection('$ctrl.columns[1]', onChange
);
31 var save
= _
.debounce(function() {
32 $scope
.$apply(function() {
34 _
.each(ctrl
.inactive
, function(dashlet
) {
35 if (dashlet
['dashboard_contact.id']) {
37 dashboard_id
: dashlet
.id
,
38 id
: dashlet
['dashboard_contact.id'],
43 _
.each(ctrl
.columns
, function(dashlets
, col
) {
44 _
.each(dashlets
, function(dashlet
, index
) {
46 dashboard_id
: dashlet
.id
,
51 if (dashlet
['dashboard_contact.id']) {
52 item
.id
= dashlet
['dashboard_contact.id'];
57 crmStatus({}, crmApi4('DashboardContact', 'save', {
59 defaults
: {contact_id
: 'user_contact_id'}
61 .then(function(results
) {
62 _
.each(ctrl
.columns
, function(dashlets
) {
63 _
.each(dashlets
, function(dashlet
) {
64 dashlet
['dashboard_contact.id'] = results
[dashlet
.id
].id
;
71 this.removeDashlet = function(column
, index
) {
72 ctrl
.inactive
.push(ctrl
.columns
[column
][index
]);
73 ctrl
.columns
[column
].splice(index
, 1);
76 this.deleteDashlet = function(index
) {
78 {start
: ts('Deleting'), success
: ts('Deleted')},
79 crmApi4('Dashboard', 'delete', {where
: [['id', '=', ctrl
.inactive
[index
].id
]]})
81 ctrl
.inactive
.splice(index
, 1);
84 this.showFullscreen = function(dashlet
) {
85 ctrl
.fullscreenDashlet
= true;
86 var options
= CRM
.utils
.adjustDialogDefaults({
92 dialogService
.open('fullscreenDashlet', '~/crmDashboard/FullscreenDialog.html', dashlet
, options
)
94 ctrl
.fullscreenDashlet
= null;
96 ctrl
.fullscreenDashlet
= null;
100 function onChange(newVal
, oldVal
) {
101 if (oldVal
!== newVal
) {
109 })(angular
, CRM
.$, CRM
._
);