menu.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. init: function () {
  24. this._super();
  25. this.renderOnRoute();
  26. },
  27. didInsertElement: function () {
  28. App.router.location.addObserver('lastSetURL', this, 'renderOnRoute');
  29. this.renderOnRoute();
  30. },
  31. /**
  32. * Syncs navigation menu with requested URL
  33. */
  34. renderOnRoute: function () {
  35. var last_url = App.router.location.lastSetURL || location.href.replace(/^[^#]*#/, '');
  36. if (last_url.substr(1, 4) !== 'main' || !this._childViews) {
  37. return;
  38. }
  39. var reg = /^\/main\/services\/(\d+)/g;
  40. var sub_url = reg.exec(last_url);
  41. var service_id = (null != sub_url) ? sub_url[1] : 1;
  42. $.each(this._childViews, function () {
  43. this.set('active', this.get('content.id') == service_id ? "active" : "");
  44. });
  45. },
  46. tagName: 'ul',
  47. classNames: ["nav", "nav-list", "nav-services"],
  48. activateView: function () {
  49. var service = App.router.get('mainServiceItemController.content');
  50. $.each(this._childViews, function () {
  51. this.set('active', (this.get('content.serviceName') == service.get('serviceName') ? "active" : ""));
  52. });
  53. }.observes("App.router.mainServiceItemController.content"),
  54. itemViewClass: Em.View.extend({
  55. classNameBindings: ["active"],
  56. active: "",
  57. serviceOperationsCount: function () {
  58. var operations = App.router.get('backgroundOperationsController').getOperationsFor(this.get('content.serviceName'));
  59. return operations.length;
  60. }.property('App.router.backgroundOperationsController.serviceOperationsChangeTime'),
  61. templateName: require('templates/main/service/menu_item')
  62. })
  63. });