/*
 * sagurume.ui.js - UI library for Sagurume Web Service
 */

// everything wrapped in jQuery -
// same effect as jQuery.noConflict() for use with prototype.js
(function($){

if( typeof( Sagurume ) != 'function' ) {
    Sagurume = function (){};
}
if( typeof( Sagurume.UI ) != 'function' ) {
    Sagurume.UI = function (){};
}

/*
 * Sagurume.UI.Places.Pulldown - エリア選択 プルダウン
 * VERSION 1.01
 * CHANGES
 *   2008-03-26 v1.01 Recruit.UI.Base.Hierarchy 利用に変更
 *   2008-01-21 v1.00 released
 */
if( typeof( Sagurume.UI.Places ) != 'function' ) {
    Sagurume.UI.Places = function (){};
}

/*
 * Sagurume.UI.Places.Pulldown
 */
Sagurume.UI.Places.Pulldown =
Class.create( Recruit.UI.Base.Hierarchy, {
    _get_definition : function (){
        var ret = [
            { cls:  Sagurume.UI.Places.Zone.Pulldown },
            { cls:  Sagurume.UI.Places.Pref.Pulldown },
            { cls:  Sagurume.UI.Places.Area.Pulldown }
        ];
        return ret;
    }
});

/*
 * Sagurume.UI.Places.LargeServiceArea.Pulldown
 */
if( typeof( Sagurume.UI.Places.Zone ) != 'function' ) {
    Sagurume.UI.Places.Zone = function (){};
}
Sagurume.UI.Places.Zone.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id         : 'sgrm-zone-sel',
            name       : 'zone',
            label      : 'ゾーン',
            has_parent : false
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : '/sagurume/zone/v1'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.zone;
    }
});

/*
 * Sagurume.UI.Places.ServiceArea.Pulldown
 */
if( typeof( Sagurume.UI.Places.Pref ) != 'function' ) {
    Sagurume.UI.Places.Pref = function (){};
}
Sagurume.UI.Places.Pref.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id         : 'sgrm-pref-sel',
            name       : 'pref',
            label      : '都道府県',
            has_parent : true,
            parent     : 'zone',
            zone : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : '/sagurume/pref/v1'
        });
    },
    _get_selections_material: function (){
        var _self = this;
	var arr = [];

        $.each( this.driver.results.pref, function (){
            if( this.zone.code == _self.zone ){
                arr.push( this );
            }
        });
        return arr;
    }
});

/*
 * Sagurume.UI.Places.Area.Pulldown
 */
if( typeof( Sagurume.UI.Places.Area ) != 'function' ) {
    Sagurume.UI.Places.Area = function (){};
}
Sagurume.UI.Places.Area.Pulldown =
Class.create( Recruit.UI.Base.Pulldown.JSONP, {
    _get_def_props: function (){
        return {
            id         : 'sgrm-area-sel',
            name       : 'area',
            label      : 'エリア',
            has_parent : true,
            parent     : 'pref',
            pref : ''
        };
    },
    _get_driver: function (){
        return new Recruit.UI.Driver.JSONP({
            url : '/sagurume/area/v1'
        });
    },
    _get_selections_material: function (){
        return this.driver.results.area;
    }
});


// end of jQuery no-conflict wrapper
})(jQuery);

