Menu.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2011
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. dojo.provide("com.ibm.cognos.admin.utils.Menu");
  11. dojo.declare("com.ibm.cognos.admin.utils.Menu", null, {
  12. constructor: function (menuModel, fragId){
  13. // menuModel {
  14. // id: xxx,
  15. // items: [
  16. // id: xxx,
  17. // title: xxxx
  18. // ],
  19. // captionId: xxx,
  20. // fieldId: xxx,
  21. // inputValue: xxx,
  22. // defaultValue: xxx
  23. // }
  24. this.fragId = fragId;
  25. this.menuModel = menuModel;
  26. this.menu = new ui_menu({id: this.menuModel.id, items:this._getItems()});
  27. this.menu.selectMenuItem(this.menuModel.inputValue || this.menuModel.defaultValue);
  28. },
  29. _getItems: function(){
  30. var items=[];
  31. var self=this;
  32. dojo.forEach(this.menuModel.items, function(item){
  33. items.push({
  34. id: item.id,
  35. title: item.title,
  36. action: function(evt){
  37. self.menu.selectMenuItem(item.id);
  38. self._setMenuItem(item.id, item.title);
  39. }
  40. });
  41. });
  42. return items;
  43. },
  44. _setMenuItem: function(selectedValue, caption) {
  45. var captionId = this.menuModel.captionId || this.menuModel.id + "_caption";
  46. var menuCaption = dojo.byId(this.fragId + captionId);
  47. if (menuCaption) {
  48. menuCaption.innerHTML = caption;
  49. dojo.byId(this.fragId + this.menuModel.fieldId).value = selectedValue;
  50. }
  51. },
  52. getMenu: function(){
  53. return this.menu;
  54. }
  55. });