define('modules/smart-assistant/views/dashlets/smart-assistant', ['view'], function (View) { return View.extend({ name: 'SmartAssistant', getTitle: function () { return this.translate('Smart Assistant', 'labels', 'SmartAssistant') || 'Smart Assistant'; }, templateContent: '' + '
' + '
' + '
' + '
', events: { 'click .sa-card': function (e) { var type = $(e.currentTarget).data('type'); this.showDetail(type); }, }, afterRender: function () { this._alerts = []; this._summary = {}; this._activeType = null; this.loadSummary(); }, loadSummary: function () { var self = this; Espo.Ajax.getRequest('SmartAssistant/action/summary').then(function (response) { self._summary = response.summary || {}; self._alerts = response.alerts || []; self.renderCards(self._summary); self.showDetail(self._activeType); }).catch(function () {}); }, renderCards: function (summary) { var cards = [ {type: 'open', label: 'תיקים פתוחים', value: summary.totalOpenCases || 0, color: '#1565c0', bg: '#e3f2fd', icon: 'fa-folder-open'}, {type: 'overdue', label: 'משימות באיחור', value: summary.totalOverdueTasks || 0, color: '#c62828', bg: '#ffcdd2', icon: 'fa-exclamation-circle'}, {type: 'hearings', label: 'דיונים השבוע', value: summary.upcomingHearings7d || 0, color: '#e65100', bg: '#fff3e0', icon: 'fa-gavel'}, {type: 'attention', label: 'דורשים תשומת לב', value: summary.casesNeedingAttention || 0, color: '#f9a825', bg: '#fff9c4', icon: 'fa-bell'}, ]; var self = this; var html = ''; cards.forEach(function (c) { var active = self._activeType === c.type; var border = active ? '2px solid ' + c.color : '2px solid transparent'; var cursor = c.value > 0 ? 'pointer' : 'default'; html += '
' + '
' + c.value + '
' + '
' + c.label + '
' + '
'; }); this.$el.find('.sa-dashlet-cards').html(html); }, showDetail: function (type) { var $detail = this.$el.find('.sa-dashlet-detail'); if (!type || type === this._activeType && $detail.html()) { this._activeType = null; $detail.html(''); this.renderCards(this._summary); return; } this._activeType = type; this.renderCards(this._summary); var alerts = this._alerts; var items = []; if (type === 'overdue') { items = alerts.filter(function (a) { return a.type === 'overdue_task'; }); } else if (type === 'hearings') { items = alerts.filter(function (a) { return a.type === 'hearing_no_prep'; }); } else if (type === 'attention') { items = alerts.filter(function (a) { return a.severity === 'critical' || a.severity === 'warning'; }); } else if (type === 'open') { items = alerts.filter(function (a) { return a.type === 'inactive_case' || a.type === 'unassigned_case'; }); } if (items.length === 0) { $detail.html('
אין פריטים להצגה
'); return; } var severityColors = {critical: '#c62828', warning: '#e65100', info: '#1565c0'}; var severityIcons = {critical: 'fa-exclamation-circle', warning: 'fa-exclamation-triangle', info: 'fa-info-circle'}; var html = ''; items.forEach(function (a) { var color = severityColors[a.severity] || '#333'; var icon = severityIcons[a.severity] || 'fa-circle'; var link = a.caseId ? '' : ''; var linkEnd = a.caseId ? '' : ''; html += '
' + '' + link + Espo.Utils.escapeString(a.message) + linkEnd + '
'; }); $detail.html(html); }, actionRefresh: function () { this.loadSummary(); }, getActionItemDataList: function () { return [ { name: 'refresh', iconHtml: '', }, ]; }, getColor: function () { return '#5c6bc0'; }, }); });