Advertisement
Guest User

Untitled

a guest
Mar 20th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.57 KB | None | 0 0
  1. //---------------------------------------------------------------------
  2. // vc.vc application
  3. //---------------------------------------------------------------------
  4. // Copyright (C) 2007-2012 The NOC Project
  5. // See LICENSE for details
  6. //---------------------------------------------------------------------
  7. console.debug("Defining NOC.vc.vc.Application");
  8.  
  9. Ext.define("NOC.vc.vc.Application", {
  10. extend: "NOC.core.ModelApplication",
  11. requires: [
  12. "NOC.vc.vc.Model",
  13. "NOC.core.TagsField",
  14. "NOC.vc.vcdomain.LookupField"
  15. ],
  16. model: "NOC.vc.vc.Model",
  17. search: true,
  18.  
  19. columns: [
  20. {
  21. text: "VC Domain",
  22. dataIndex: "vc_domain__label",
  23. width: 70
  24. },
  25. {
  26. text: "Name",
  27. dataIndex: "name"
  28. },
  29. {
  30. text: "Label",
  31. dataIndex: "label",
  32. width: 50
  33. },
  34. {
  35. text: "Prefixes",
  36. dataIndex: "prefixes",
  37. width: 200
  38. },
  39. {
  40. text: "Description",
  41. dataIndex: "description",
  42. flex: 1
  43. },
  44. {
  45. text: "Tags",
  46. dataIndex: "tags",
  47. renderer: noc_renderTags
  48. },
  49. {
  50. text: "Int.",
  51. dataIndex: "interfaces_count",
  52. width: 35
  53. },
  54. {
  55. xtype: "actioncolumn",
  56. width: 30,
  57. items: [
  58. {
  59. icon: "/static/img/fam/silk/information.png",
  60. tooltip: "Show Interfaces",
  61. handler: function(grid, rowIndex, colIndex) {
  62. var me = grid.up("panel").up("panel"),
  63. vc = grid.getStore().getAt(rowIndex);
  64. me.showInterfaces(vc.data);
  65. }
  66. }
  67. ]
  68. }
  69. ],
  70. fields: [
  71. {
  72. name: "vc_domain",
  73. xtype: "vc.vcdomain.LookupField",
  74. fieldLabel: "VC Domain",
  75. allowBlank: false
  76. },
  77. {
  78. name: "name",
  79. xtype: "textfield",
  80. fieldLabel: "Name",
  81. allowBlank: false,
  82. regex: /^[a-zA-Z0-9_\-]+$/
  83. },
  84. {
  85. name: "l1",
  86. xtype: "numberfield",
  87. fieldLabel: "L1",
  88. allowBlank: false
  89. },
  90. { // @todo: Auto-hide when VC domain does not support l2
  91. name: "l2",
  92. xtype: "numberfield",
  93. fieldLabel: "L2",
  94. allowBlank: true
  95. },
  96. {
  97. name: "description",
  98. xtype: "textfield",
  99. fieldLabel: "Description",
  100. allowBlank: true
  101. },
  102. {
  103. name: "tags",
  104. xtype: "tagsfield",
  105. fieldLabel: "Tags",
  106. allowBlank: true
  107. }
  108. ],
  109. filters: [
  110. {
  111. title: "By VC Domain",
  112. name: "vc_domain",
  113. ftype: "lookup",
  114. lookup: "vc.vcdomain"
  115. },
  116. {
  117. title: "By VC Filter",
  118. name: "l1",
  119. ftype: "vcfilter"
  120. },
  121. {
  122. title: "By Tags",
  123. name: "tags",
  124. ftype: "tag"
  125. }
  126. ],
  127. toolbar: [
  128. {
  129. itemId: "create_first",
  130. text: "Add First Free",
  131. iconCls: "icon_application_form_add",
  132. tooltip: "Add first free VC",
  133. handler: function() {
  134. var app = this.up("panel").up("panel");
  135. app.first_new_record();
  136. }
  137. },
  138. {
  139. itemId: "import",
  140. text: "Import",
  141. iconCls: "icon_door_in",
  142. tooltip: "Import VCs",
  143. menu: {
  144. xtype: "menu",
  145. plain: true,
  146. items: [
  147. {
  148. text: "VLANs From Switch",
  149. itemId: "vlans_from_switch",
  150. iconCls: "icon_arrow_right"
  151. }
  152. ]
  153. }
  154. }
  155. ],
  156. //
  157. afterRender: function() {
  158. var me = this;
  159. me.callParent();
  160. // Set up import menu
  161. var importMenu = me.grid_toolbar.getComponent("import").menu,
  162. VLANSFromSwitchItem = importMenu.getComponent("vlans_from_switch");
  163.  
  164. VLANSFromSwitchItem.mon(VLANSFromSwitchItem, "click",
  165. me.onImportVLANSFromSwitch, me);
  166. },
  167. //
  168. first_new_record: function() {
  169. var me = this;
  170. Ext.create("NOC.vc.vc.AddFirstFreeForm", {
  171. callback: Ext.bind(me.on_first_new_record, me),
  172. renderTo: me.el
  173. });
  174. },
  175. //
  176. on_first_new_record: function(vc_domain, vc) {
  177. var me = this;
  178. console.log(vc_domain, vc);
  179. me.new_record({vc_domain: vc_domain, l1: vc});
  180. },
  181. //
  182. onImportVLANSFromSwitch: function() {
  183. Ext.create("NOC.vc.vc.MOSelectForm", {app: this});
  184. },
  185. //
  186. runImportFromSwitch: function(vc_domain, managed_object, vc_filter) {
  187. var me = this;
  188.  
  189. me.vc_domain = vc_domain;
  190. me.vc_filter = vc_filter;
  191. // Get VC filter expression
  192. Ext.Ajax.request({
  193. url: "/vc/vcfilter/" + me.vc_filter + "/",
  194. method: "GET",
  195. scope: me,
  196. success: function(response) {
  197. // Run MRT
  198. var me = this,
  199. r = Ext.decode(response.responseText);
  200. me.vc_filter_expression = r.expression;
  201. NOC.mrt({
  202. url: "/vc/vc/mrt/get_vlans/",
  203. selector: managed_object,
  204. scope: me,
  205. success: me.processImportFromSwitch,
  206. failure: function() {
  207. NOC.error("Failed to import VLANs")
  208. }
  209. });
  210. },
  211. failure: function() {
  212. NOC.error("Failed to get VC Filter");
  213. }
  214. });
  215. },
  216. //
  217. processImportFromSwitch: function(result) {
  218. var me = this,
  219. r = result[0];
  220. if(r.status) {
  221. // VLANS Fetched
  222. // r.code
  223. var w = Ext.create("NOC.vc.vc.VCImportForm", {
  224. app: me,
  225. vc_domain: me.vc_domain,
  226. vc_filter: me.vc_filter,
  227. vc_filter_expression: me.vc_filter_expression
  228. });
  229. w.loadVLANsFromSwitch(r.result);
  230. } else {
  231. // Failed to fetch
  232. NOC.error("Failed to import VLANs from {0}:<br>{1}",
  233. r.object_name, r.result.text);
  234. }
  235. },
  236. // Called when import complete
  237. onImportSuccess: function(result) {
  238. var me = this;
  239. me.refresh_store();
  240. },
  241. // Show interfaces window
  242. showInterfaces: function(vc) {
  243. var me = this;
  244. Ext.Ajax.request({
  245. url: "/vc/vc/" + vc.id + "/interfaces/",
  246. method: "GET",
  247. scope: me,
  248. success: function(response) {
  249. var r = Ext.decode(response.responseText);
  250. Ext.create("NOC.vc.vc.VCInterfaces", {
  251. app: me,
  252. vc: vc,
  253. interfaces: r
  254. });
  255. },
  256. failure: function() {
  257. NOC.error("Failed to get interfaces");
  258. }
  259. });
  260. }
  261. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement