// vim: ts=4:sw=4:nu:fdc=4:nospell
/*global Ext */
/**
 * @class Ext.ux.form.PopCombo
 * @extends Ext.form.ComboBox
 *
 * Pop(ulating)Combo's setValue method accepts object as argument and implements
 * special processing of the object. For example:
 * <pre>
 * var combo = new Ext.ux.form.PopCombo();
 * var o = {value:1,records:[[0,'Item 1'],[1,'Item 2']]};
 * combo.setValue(o);
 * </pre>
 * If records are found in the passed object the combo store is popupated with
 * these records before the value is actually set.
 *
 * @author Ing. Jozef Sakálo?
 * @copyright (c) 2009, by Ing. Jozef Sakálo?
 * @date 9. February 2009
 * @version 0.1
 * @revision $Id: Ext.ux.form.PopCombo.js 589 2009-02-21 23:30:18Z jozo $
 *
 * @license Ext.ux.form.PopCombo.js is licensed under the terms of the Open Source
 * LGPL 3.0 license. Commercial use is permitted to the extent that the
 * code/component(s) do NOT become part of another Open Source or Commercially
 * licensed development library or toolkit without explicit permission.
 *
 * <p>License details: <a href="http://www.gnu.org/licenses/lgpl.html"
 * target="_blank">http://www.gnu.org/licenses/lgpl.html</a></p>
 *
 * @forum 59406
 *
 * @donate
 * <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
 * <input type="hidden" name="cmd" value="_s-xclick">
 * <input type="hidden" name="hosted_button_id" value="3430419">
 * <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif"
 * border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
 * <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
 * </form>
 */

// create namespace
//Ext.ns('Ext.ux.form');
Ext.ns('Ext.form');

/**
 * Creates new Ext.ux.form.PopCombo
 * @constructor
 * @param {Object} config A config object
 */
Ext.form.PopCombo = Ext.extend(Ext.form.ComboBox, {

    // defaults
    /**
     * @cfg {Object} paramNames
     * Defines names that are used for "value" and "records" members
     * (defaults to {value:"value", records:"records"})
     */
    paramNames:{
        value:'value',
        records:'records'
    }

    ,
    setValue:function(value) {
        var val = value;
        if('object' === typeof value && '[object Object]' === Object.prototype.toString.call(value)) {
            if(undefined !== value[this.paramNames['records']]) {
                this.store.loadData(value[this.paramNames['records']]);
            }
            val = value[this.paramNames['value']];
        }
        Ext.form.PopCombo.superclass.setValue.call(this, val);
    } // eo function setValue

}); // eo extend

// register xtype
Ext.reg('popcombo', Ext.form.PopCombo);

// eof
