Ext.namespace( 'instore.extlib.ui.util' ); instore.extlib.ui.util.Util = { checkItems: function(config) { if(!config.items || config.items.length == 0) config.items = [{}]; }, applyRecursive: function(obj, config, defaults) { if(defaults) instore.extlib.ui.util.Util.applyRecursive(obj, defaults); if(obj && config && typeof config == "object") { for(var subobj in config) { if(typeof config[subobj] == "object" && typeof obj[subobj] != "undefined") instore.extlib.ui.util.Util.applyRecursive(obj[subobj], config[subobj]); else obj[subobj] = config[subobj]; } } return obj; }, applyRecursiveIf: function(obj, config) { if(obj && config) { for(var p in config) { if(typeof config[p] == "object" && typeof obj[p] != "undefined") instore.extlib.ui.util.Util.applyRecursiveIf(obj[p], config[p]); else { if(typeof obj[p] == "undefined") obj[p] = config[p]; } } } return obj; }, removeListeners: function(object, event) { var e = object.events[event]; if(e != null && e.listeners) Ext.each(e.listeners, function(listener) { e.listeners.remove(listener); }) }, setUniqueListener: function(object, event, func, scope) { instore.extlib.ui.util.Util.removeListeners(object, event); object.on(event, func, scope || object); }, dateRenderer: function(val) { return (val != null) ? val.dateFormat('d/m/Y') : val; }, beanToRecord: function(obj) { var fields = []; for(key in obj) fields.push({name: key}); return new Ext.data.Record.create(fields); }, assignSpecialKeys: function(field, fn, scope) { if(field && field.getXType()) { var xtype = field.getXType(); if(xtype == "combo") field.on("select", fn, scope); else if(xtype == "textfield" || xtype == "numberfield" || xtype == "datefield") { field.on("specialkey", function(f, e) { if(e.keyCode == Ext.EventObject.ENTER) fn.call(this); }.createDelegate(scope), scope); field.on("change", function() { fn.call(this); }.createDelegate(scope), scope); } } }, getFlatObject: function(obj, prefix) { var result = {}; if(obj && typeof obj == "object") { for(var prop in obj) { if(typeof obj[prop] == "object") { if(Ext.isArray(obj[prop])) { var arr = obj[prop]; for(var i = 0; i < arr.length; i++) Ext.apply(result, instore.extlib.ui.util.Util.getFlatObject(arr[i], prop + i)); } else Ext.apply(result, instore.extlib.ui.util.Util.getFlatObject(obj[prop], prop)); } else { var key = (prefix) ? prefix + "." + prop : prop; result[key] = obj[prop]; } } return result; } else return obj; } };