diff --git a/lib/app/extmodelapplication.py b/lib/app/extmodelapplication.py index a7a9ef41b83b2c7a31b5208d0dbec7e19723d6b6..64213b7d5b80267d40cfca8f771eef77284a87e3 100644 --- a/lib/app/extmodelapplication.py +++ b/lib/app/extmodelapplication.py @@ -32,6 +32,7 @@ from noc.main.models.tag import Tag from noc.core.stencil import stencil_registry from .extapplication import ExtApplication, view from .interfaces import DateParameter, DateTimeParameter +from noc.main.models.customfield import CustomField class ExtModelApplication(ExtApplication): @@ -48,6 +49,7 @@ class ExtModelApplication(ExtApplication): ignored_fields = set(["id", "bi_id"]) def __init__(self, *args, **kwargs): + CustomField.install_fields() super(ExtModelApplication, self).__init__(*args, **kwargs) self.db_table = self.model._meta.db_table self.pk_field_name = self.model._meta.pk.name @@ -120,7 +122,6 @@ class ExtModelApplication(ExtApplication): return int(item) def get_custom_fields(self): - from noc.main.models.customfield import CustomField return list(CustomField.table_fields(self.model._meta.db_table)) def get_launch_info(self, request): diff --git a/ui/web/ip/ipam/AddressPanel.js b/ui/web/ip/ipam/AddressPanel.js index f006cb12a42667029e14524a03468298c654a87a..456a357a458efa81d9beeddea8c6cd49ff2d4b1f 100644 --- a/ui/web/ip/ipam/AddressPanel.js +++ b/ui/web/ip/ipam/AddressPanel.js @@ -27,8 +27,7 @@ Ext.define("NOC.ip.ipam.AddressPanel", { initComponent: function () { var me = this; - Ext.apply(me, { - fields: [ + fieldsArr = [ { name: "vrf", xtype: "ip.vrf.LookupField", @@ -131,7 +130,75 @@ Ext.define("NOC.ip.ipam.AddressPanel", { fieldLabel: __("Source"), allowBlank: true } - ] + ]; + + // + // Load CustomFields to Form + // + customfields=[]; + Ext.Ajax.request({ + url: "/main/customfield/?table=ip_address&is_hidden=false&is_active=true", + method: "GET", + async: false, + success: function(response) { + var data = Ext.decode(response.responseText); + if (data){ + type_to_extjs_type = {'str':'textfield', + 'int':'numberfield', + 'bool':'checkboxfield', + 'date':'datefield', + 'datetime':'datetimefield' + }; + data.forEach(function(item, i, arr) { + if (item['max_length'] === 0) {max_length = 256} + else {max_length = item['max_length']} + + if (item['enum_group']) { + xtype = 'combobox'; + store={"store":[]}; + + Ext.Ajax.request({ + url: "/main/customfieldenumgroup/"+item['enum_group']+"/values/?is_active=true", + method: "GET", + async: false, + success: function(response) { + var custvalues = Ext.decode(response.responseText); + if (custvalues){ + custvalues.forEach(function(item, i, arr) { + store["store"].push([item['key'],item['value']]); + }); + } + }, + failure: function() { + NOC.error(__("Failed to load CustomValues data")) + } + }); + + } + else { + xtype = type_to_extjs_type[item['type']]; + store = {}; + } + + customfields.push($.extend({}, { + name: item["name"], + xtype: xtype, + fieldLabel: __(item["label"]), + allowBlank: true, + maxLength: max_length, + }, + store)); + }); + console.log('Address custom fields was loaded!') + } + }, + failure: function() { + NOC.error(__("Failed to load CustomFields data")) + } + }); + + Ext.apply(me, { + fields: fieldsArr.concat(customfields), }); me.callParent() }, diff --git a/ui/web/ip/ipam/PrefixPanel.js b/ui/web/ip/ipam/PrefixPanel.js index b6f62f0ccfe68ef352239458f9be2c4097539f40..e3483e6c6b59713ace9f4886a227cbb1f55e47fe 100644 --- a/ui/web/ip/ipam/PrefixPanel.js +++ b/ui/web/ip/ipam/PrefixPanel.js @@ -13,7 +13,9 @@ Ext.define("NOC.ip.ipam.PrefixPanel", { "NOC.ip.vrf.LookupField", "NOC.peer.as.LookupField", "NOC.vc.vc.LookupField", - "NOC.project.project.LookupField" + "NOC.project.project.LookupField", + "NOC.main.customfieldenumgroup.LookupField", + "NOC.core.ModelApplication" ], currentPrefixId: null, restUrl: "/ip/prefix/", @@ -27,20 +29,7 @@ Ext.define("NOC.ip.ipam.PrefixPanel", { initComponent: function () { var me = this; - me.rebaseButton = Ext.create("Ext.button.Button", { - text: __("Rebase"), - glyph: NOC.glyph.truck, - tooltip: __("Rebase prefix to a new location"), - scope: me, - handler: me.onRebase, - hasAccess: NOC.hasPermission("rebase"), - bind: { - disabled: "{isNew}" - } - }); - - Ext.apply(me, { - fields: [ + fieldsArr = [ { name: "vrf", xtype: "ip.vrf.LookupField", @@ -154,7 +143,86 @@ Ext.define("NOC.ip.ipam.PrefixPanel", { ], uiStyle: "medium" } - ], + ]; + // + // Load CustomFields to Form + // + customfields=[]; + Ext.Ajax.request({ + url: "/main/customfield/?table=ip_prefix&is_hidden=false&is_active=true", + method: "GET", + async: false, + success: function(response) { + var data = Ext.decode(response.responseText); + if (data){ + type_to_extjs_type = {'str':'textfield', + 'int':'numberfield', + 'bool':'checkboxfield', + 'date':'datefield', + 'datetime':'datetimefield' + }; + data.forEach(function(item, i, arr) { + if (item['max_length'] === 0) {max_length = 256} + else {max_length = item['max_length']} + + if (item['enum_group']) { + xtype = 'combobox'; + store={"store":[]}; + + Ext.Ajax.request({ + url: "/main/customfieldenumgroup/"+item['enum_group']+"/values/?is_active=true", + method: "GET", + async: false, + success: function(response) { + var custvalues = Ext.decode(response.responseText); + if (custvalues){ + custvalues.forEach(function(item, i, arr) { + store["store"].push([item['key'],item['value']]); + }); + } + }, + failure: function() { + NOC.error(__("Failed to load CustomValues data")) + } + }); + + } + else { + xtype = type_to_extjs_type[item['type']]; + store = {}; + } + + customfields.push($.extend({}, { + name: item["name"], + xtype: xtype, + fieldLabel: __(item["label"]), + allowBlank: true, + maxLength: max_length, + }, + store)); + }); + console.log('Prefix custom fields was loaded!') + } + }, + failure: function() { + NOC.error(__("Failed to load CustomFields data")) + } + }); + + me.rebaseButton = Ext.create("Ext.button.Button", { + text: __("Rebase"), + glyph: NOC.glyph.truck, + tooltip: __("Rebase prefix to a new location"), + scope: me, + handler: me.onRebase, + hasAccess: NOC.hasPermission("rebase"), + bind: { + disabled: "{isNew}" + } + }); + + Ext.apply(me, { + fields: fieldsArr.concat(customfields), formToolbar: [ me.rebaseButton ]