Skip to content

Commit d5ed401

Browse files
committed
Добавлена кнопка для просмотра уведомлений в верхнее меню
1 parent fd7f427 commit d5ed401

File tree

13 files changed

+279
-86
lines changed

13 files changed

+279
-86
lines changed

public/cms/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/cms/js/backend.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/cms/js/page-wysiwyg.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/js/cms/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var CMS = {
1212
* Вычисление высоты контейнера с контентом
1313
*/
1414
content_height: null,
15-
calculateContentHeight: function() {
16-
if(this.content_height != null)
15+
calculateContentHeight: function () {
16+
if (this.content_height != null)
1717
return this.content_height;
1818

1919
var contentCont = $('#content-wrapper'),
@@ -28,4 +28,4 @@ var CMS = {
2828

2929
return this.content_height;
3030
}
31-
};
31+
};

resources/assets/js/cms/components/ui.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,48 @@ CMS.ui = {
44
// 1: callback
55
// 2: priority
66

7-
_elements:[],
8-
add:function (module, callback, priority) {
9-
if (typeof(callback) != 'function')
7+
_elements: [],
8+
add: function (module, callback, priority) {
9+
if (!_.isFunction(callback))
1010
return this;
1111

1212
CMS.ui._elements.push([module, callback, priority || 0]);
1313
return this;
1414
},
15-
call: function(module) {
15+
call: function (module) {
1616
for (var i = 0; i < CMS.ui._elements.length; i++) {
1717
var elm = CMS.ui._elements[i];
18-
if(_.isArray(module) && _.indexOf(module, elm[0]) != -1 )
18+
if (_.isArray(module) && _.indexOf(module, elm[0]) != -1)
1919
elm[1]();
2020
else if (module == elm[0])
2121
elm[1]();
2222
}
2323
},
24-
init:function (module) {
25-
$('body').trigger('ui.init.before', [this]);
24+
init: function (module, container) {
25+
if (_.isUndefined(container)) {
26+
var container = $('body')
27+
} else if (!(container instanceof jQuery)) {
28+
if (_.isString(container))
29+
container = $(container);
30+
else
31+
throw new TypeError('Container must be string or jQuery object');
32+
}
2633

2734
CMS.ui._elements = _.sortBy(CMS.ui._elements, 2);
2835

2936
for (var i = 0; i < CMS.ui._elements.length; i++) {
3037
var elm = CMS.ui._elements[i];
3138

3239
try {
33-
if(!module)
34-
elm[1]();
35-
else if(_.isArray(module) && _.indexOf(module, elm[0]) != -1 )
36-
elm[1]();
37-
else if (module == elm[0])
38-
elm[1]();
39-
} catch (e) {console.log(elm[0], e);}
40+
if (_.isUndefined(module))
41+
elm[1](container);
42+
else if (_.isArray(module) && _.indexOf(module, elm[0]) != -1)
43+
elm[1](container);
44+
else if (_.isString(module) && module == elm[0])
45+
elm[1](container);
46+
} catch (e) {
47+
console.log(elm[0], e);
48+
}
4049
}
41-
$('body').trigger('ui.init.after', [this]);
4250
}
43-
};
51+
};

resources/assets/js/cms/run.js

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,113 @@
1-
$(function() {
1+
$(function () {
22
$.ajaxSetup({
33
headers: {
44
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
55
}
66
});
77

8-
CMS.Translate.init(function() {
8+
CMS.Translate.init(function () {
99
CMS.ui.init();
1010
KodiCMS.start(null, CMS.settings);
1111

1212
CMS.controllers.call();
1313
CMS.messages.init();
1414
CMS.Notifications.init();
1515
});
16+
17+
window.App = new Vue({
18+
el: 'body',
19+
data: function () {
20+
return {
21+
loadingNotifications: false,
22+
notifications: []
23+
}
24+
},
25+
created: function () {
26+
var self = this;
27+
$('#notifications')
28+
.on('hidden.bs.dropdown', function () {
29+
$('.notifications-list').slimScroll({ destroy: true });
30+
self.markNotificationsAsRead();
31+
})
32+
.on('shown.bs.dropdown', function () {
33+
self.showNotifications();
34+
});
35+
36+
this.loadDataForAuthenticatedUser();
37+
},
38+
methods: {
39+
showNotifications: function () {
40+
this.loadDataForAuthenticatedUser();
41+
},
42+
43+
loadDataForAuthenticatedUser: function () {
44+
this.getNotifications();
45+
},
46+
47+
/**
48+
* Get the application notifications.
49+
*/
50+
getNotifications: function () {
51+
this.loadingNotifications = true;
52+
53+
var self = this;
54+
55+
this.$http.get('/api.notifications.recent').then(function (response) {
56+
this.notifications = response.data.content;
57+
this.loadingNotifications = false;
58+
$('.notifications-list').slimScroll({ height: 250 });
59+
}, function (response) {
60+
// error callback
61+
});
62+
},
63+
64+
markNotificationAsRead: function (notification) {
65+
if (notification.read) {
66+
return;
67+
}
68+
69+
this.$http.put('/api.notifications.read', {ids: [notification.id]});
70+
notification.read = true;
71+
},
72+
73+
/**
74+
*
75+
* Mark the current notifications as read.
76+
*/
77+
markNotificationsAsRead: function () {
78+
if (!this.hasUnreadNotifications) {
79+
return;
80+
}
81+
82+
this.$http.put('/api.notifications.read', {ids: _.pluck(this.notifications, 'id')});
83+
84+
_.each(this.notifications, function (notification) {
85+
notification.read = true;
86+
});
87+
}
88+
},
89+
computed: {
90+
unreadNotifications: function () {
91+
if (this.notifications) {
92+
return _.filter(this.notifications, function (notification) {
93+
return !notification.read;
94+
}).length;
95+
}
96+
97+
return 0;
98+
},
99+
100+
hasNotifications: function () {
101+
return this.notifications.length;
102+
},
103+
104+
/**
105+
* Determine if the user has any unread notifications.
106+
*/
107+
hasUnreadNotifications: function () {
108+
return this.unreadNotifications > 0;
109+
}
110+
}
111+
});
112+
16113
});

0 commit comments

Comments
 (0)