Ext.apply(Ext.util.Format, {
    usSalary: function(value){
        return value > 0 ? this.usMoney(value) : 'Not Listed.';
    },
    scesc: function(value) {
		return value ? "Applications for the position are only accepted through the South Carolina Employment Security Commission (Job Service) located at 1558 W. Evans Street in Florence" : "";
    },
    date: function(value) {
		return value ? value.dateFormat('Y-m-d') : '';
    },
	jobStatus: function(value){
		var color, weight = 'none';
		switch(value){
			case 'Filled':
				color = '#900B09';
				break;
			case 'Remove':
				color = "#FF0000";
				break;
			default:
				color = '#000000';
		}
		return String.format("<span style=\"color:{0};font-weight:{1}\">{2}</span>", color, weight, value);
	},
	fillDate: function(value){
		return (value == "0000-00-00") ? "Not Filled" : value;
	},
	jobDepot: function(value) {
		return Ext.util.Format.ellipsis(value, 20);
	}
});

/**
  * Floco.grid.JobGridPanel Extension Class
  *
  * @author Joshua Suggs
  * @version 1.0
  *
  * @class Floco.grid.JobGridPanel
  * @extends Floco.ext.ExpanderGridPanel
  * Class for creating an editable, groupable, expandable grid.
  
  * @constructor
  */ 
Floco.grid.JobGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
    // disable editing on init (toggled by quickedit)
    editEnabled: false,
    
    // single row selection model
    sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
    
	viewConfig : {
		forceFit: true
	},
    
    // Grouping Data Store for job grid, ungrouped at init
    store: new Ext.data.Store({
        reader: new Ext.data.JsonReader({
            root: 'bindings',
            totalProperty: 'results'
            }, [
                {name:'id', type:'int'},
                {name:'job_code', type:'string'},
                {name:'department', type:'string'},
                {name:'title', type:'string'},
                {name:'description', type:'string'},
                {name:'salary', type:'string'},
                {name:'scope', type:'string'},
                {name:'status', type:'string'},
                {name:'vacated_by', type:'string'},
                {name:'date', type:'date', dateFormat: 'Y-m-d'},
                {name:'scesc', type:'boolean'},
                {name:'attachments'}
            ]
        ),
        url: 'jobs/ajax.php?ajax&grid',
        sortInfo: {field: 'job_code', direction: 'ASC'},
        autoLoad: false
    }),
    
    initComponent : function(){
		this.details = new Floco.ext.RowViewDetails({
			tpl : new Ext.Template(
		        '<p><b>Description:</b> {description}<br>',
		        '<p><b>Salary:</b> {salary}<br>',
		        '<p><b>Attachments:</b> {attachments}',
		        '<p><b>{scesc:scesc}</b>'
		    )
		});
		this.plugins = this.details;
        
        Floco.grid.JobGridPanel.superclass.initComponent.call(this);
        
        this.colModel = new Ext.grid.ColumnModel([
			this.details,
            {header: "Department", width: 20, sortable: true, dataIndex: 'department', renderer: Ext.util.Format.jobDepot},
            {header: "Title", width: 30, sortable: true, dataIndex: 'title', renderer: Ext.util.Format.ucWords},
            {header: "Status", width: 10, sortable: true, dataIndex: 'status', renderer: Ext.util.Format.jobStatus},
            {header: "Deadline", width: 10, sortable: true, dataIndex: 'date', renderer: Ext.util.Format.date}
        ]);
        
        this.store.load();
    },
    
    onRender : function(ct, positions) {
        Floco.grid.JobGridPanel.superclass.onRender.apply(this, arguments);
    },
    
    // Add Event Handlers
    initEvents : function(){
        Floco.grid.JobGridPanel.superclass.initEvents.call(this);
    }
});
Ext.reg('jobgrid', Floco.grid.JobGridPanel);








