menu.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.MainServiceMenuView = Em.CollectionView.extend({
  20. content: function () {
  21. return App.router.get('mainServiceController.content');
  22. }.property('App.router.mainServiceController.content'),
  23. didInsertElement: function () {
  24. App.router.location.addObserver('lastSetURL', this, 'renderOnRoute');
  25. this.renderOnRoute();
  26. },
  27. activeServiceId : null,
  28. /**
  29. * Syncs navigation menu with requested URL
  30. */
  31. renderOnRoute: function () {
  32. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  33. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  34. return;
  35. }
  36. var reg = /^\/main\/services\/(\S+)\//g;
  37. var sub_url = reg.exec(last_url);
  38. var service_id = (null != sub_url) ? sub_url[1] : 1;
  39. this.set('activeServiceId', service_id);
  40. },
  41. tagName: 'ul',
  42. classNames: ["nav", "nav-list", "nav-services"],
  43. itemViewClass: Em.View.extend({
  44. classNameBindings: ["active"],
  45. active: function(){
  46. return this.get('content.id') == this.get('parentView.activeServiceId') ? 'active' : '';
  47. }.property('parentView.activeServiceId'),
  48. alertsCount: function () {
  49. var allAlerts = App.router.get('clusterController.alerts');
  50. var serviceId = this.get('content.serviceName');
  51. if (serviceId) {
  52. return allAlerts.filterProperty('serviceType', serviceId).length;
  53. }
  54. return 0;
  55. }.property('App.router.clusterController.alerts'),
  56. templateName: require('templates/main/service/menu_item')
  57. })
  58. });