<!---- 
    Author 	: Wahyu / : 15-09-2014	
    Revisi 	: Ferry
-->
	
	<?php
				//---------Untuk privellege jika dia ada tombol save----------
				if($group_user->AddPrivillage == 1){
					$cek_autority_add 		= "";
				}
				else{
					$cek_autority_add 		= "disabled";
				}
				
				if($group_user->DeletePrivillage == 1){
					$cek_autority_delete 		= "";
				}
				else{
					$cek_autority_delete 		= "disabled";
				}
				
				if($group_user->EditPrivillage == 1){
					$cek_autority_edit 		= "";
				}
				else{
					$cek_autority_edit 		= "disabled";
				}
				
				if($group_user->SavePrivillage == 1){
					$cek_autority_save 		= "";
				}
				else{
					$cek_autority_save 		= "disabled";
				}
				//-------------end----------------------------
	?>	

<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_salesman" name="fm_salesman" method="post" action="">
        <!-- center view -->
        <div data-options="region:'center',border:false" style="background-color:#eee;height:30px; padding-left:2px; padding-top:2px">
            <div id="form-wrapper" class="easyui-panel" style="width:1179px;height:579px;" fit="true">	           
                <div class="easyui-tabs">
                    <!-- Job Title -->
                    <div id="tab_general" title="Jobtitle">
                        <div style="overflow:hidden;padding:0px;">
							<!-- gaya table baru di grid -->
							<table id="tt_jobtitle" class="easyui-datagrid"
                                title="" iconCls="icon-edit" 
                                singleSelect="true" rowNumbers="true" 
                                pageSize="150" mode="remote"
                                toolbar="#toolbar_jobtitle"
                                fitColumns="true" remoteSort="false" 
                                url="<?php echo base_url(); ?>custom/get_data/jobtitle"
                                style="width:auto;height:560px" 
                               
                            > 
							
                                <thead frozen="true">
                                    <tr>
                                        <th field="JobTitleCode" width="100" halign="center">Jobtitle Code</th>
                                        <th field="JobTitleName" width="200" halign="center">Jobtitle Name</th>
                                        <th field="JobTitleStatus" width="200" halign="center">Jobtitle Status</th>
                                        <th field="Description" width="825" halign="center">Description</th>
                                    </tr>
                                </thead>							
                            </table>
							
                            <!-- Toolbar -->
                            <div id="toolbar_jobtitle">
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="new_supporting('#dialog-template-jobtitle','#form_template_jobtitle','<?php echo base_url() ?>list/supporting/insert_jobtitle');" <?php echo $cek_autority_add;?>>New </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_supporting('#tt_jobtitle',$('#tt_jobtitle').datagrid('getSelected').JobTitleCode,'#dialog-template-jobtitle','#form_template_jobtitle','<?php echo base_url()?>list/supporting/update_jobtitle');" <?php echo $cek_autority_edit;?>>Edit </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delete_supporting('#tt_jobtitle',$('#tt_jobtitle').datagrid('getSelected').JobTitleCode,'<?php echo base_url()?>list/supporting/delete_jobtitle');" <?php echo $cek_autority_delete;?>>Delete </a>
                            </div>				
                        </div>		
                    </div>
                    <!-- End of Job Title -->
                    
                    <!-- City -->
                    <div id="tab_general" title="City">
                        <div style="overflow:hidden;padding:0px;">
                            <!-- gaya table baru di grid -->
							<table id="tt_city" class="easyui-datagrid"
                                title="" iconCls="icon-edit" 
                                singleSelect="true" rowNumbers="true" 
                                pageSize="150" mode="remote"
                                toolbar="#toolbar_city"
                                fitColumns="true" remoteSort="false" 
                                url="<?php echo base_url(); ?>custom/get_data/city"
                                style="width:auto;height:560px" 
                               
                            > 
							    <thead frozen="true">
                                    <tr>
                                        <th field="CityCode" width="100" halign="center">City Code</th>
                                        <th field="CityName" width="200" halign="center">City Name</th>
                                        <th field="StateName" width="200" halign="center">State Name</th>
                                        <th field="CityDesc" width="624" halign="center">Description</th>
                                    </tr>
                                </thead>							
                            </table>
							
                            <!-- Toolbar -->
                            <div id="toolbar_city">
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="new_supporting('#dialog-template-city','#form_template_city','<?php echo base_url() ?>list/supporting/insert_city');" <?php echo $cek_autority_add;?>>New </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_supporting('#tt_city',$('#tt_city').datagrid('getSelected').CityCode,'#dialog-template-city','#form_template_city','<?php echo base_url()?>list/supporting/update_city');" <?php echo $cek_autority_edit;?>>Edit </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delete_supporting('#tt_city',$('#tt_city').datagrid('getSelected').CityCode,'<?php echo base_url()?>list/supporting/delete_city');" <?php echo $cek_autority_delete;?>>Delete </a>
                            </div>				
                        </div>		
                    </div>
                    <!-- End of City -->
                    
                    <!-- State -->
                    <div id="tab_general" title="State">
                        <div style="overflow:hidden;padding:0px;">
							<!-- gaya table baru di grid -->
                            <table id="tt_state" class="easyui-datagrid"
                                title="" iconCls="icon-edit" 
                                singleSelect="true" rowNumbers="true" 
                                pageSize="150" mode="remote"
                                toolbar="#toolbar_state"
                                fitColumns="true" remoteSort="false" 
                                url="<?php echo base_url(); ?>custom/get_data/state"
                                style="width:auto;height:560px" 
                               
                            > 
                            
                                <thead>
                                <tr>
                                    <th field="StateCode" width="100" halign="center">State Code</th>
                                    <th field="StateName" width="200" halign="center">State Name</th>
                                    <th field="CountryName" width="200" halign="center">Country Name</th>
                                    <th field="StateDesc" width="624" halign="center">Description</th>
                                </tr>
                                </thead>
                            </table>
							
                            <!-- Toolbar -->
                            <div id="toolbar_state">
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="new_supporting('#dialog-template-state','#form_template_state','<?php echo base_url() ?>list/supporting/insert_state');" <?php echo $cek_autority_add;?>>New </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_supporting('#tt_state',$('#tt_state').datagrid('getSelected').StateCode,'#dialog-template-state','#form_template_state','<?php echo base_url()?>list/supporting/update_state');" <?php echo $cek_autority_edit;?>>Edit </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delete_supporting('#tt_state',$('#tt_state').datagrid('getSelected').StateCode,'<?php echo base_url()?>list/supporting/delete_state');" <?php echo $cek_autority_delete;?>>Delete </a>
                            </div>				
                        </div>		
                    </div>
                    <!-- End of State -->
                    
                    <!-- Country -->
                    <div id="tab_general" title="Country">
                        <div style="overflow:hidden;padding:0px;">
							<table id="tt_country" class="easyui-datagrid"
                                title="" iconCls="icon-edit" 
                                singleSelect="true" rowNumbers="true" 
                                pageSize="150" mode="remote"
                                 toolbar="#toolbar_country"
                                fitColumns="true" remoteSort="false" 
                                url="<?php echo base_url(); ?>custom/get_data/country"
                                style="width:auto;height:560px" 
                               
                            > 
							
                                <thead frozen="true">
                                    <tr>
                                        <th field="CountryCode" width="100" halign="center">Country Code</th>
                                        <th field="CountryName" width="200" halign="center">Country Name</th>
                                        <th field="CountryDesc" width="825" halign="center">Description</th>
                                    </tr>
                                </thead>							
                            </table>
							
                            <!-- Toolbar -->
                            <div id="toolbar_country">
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="new_supporting('#dialog-template-country','#form_template_state','<?php echo base_url() ?>list/supporting/insert_country');" <?php echo $cek_autority_add;?>>New </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_supporting('#tt_country',$('#tt_country').datagrid('getSelected').CountryCode,'#dialog-template-country','#form_template_country','<?php echo base_url()?>list/supporting/update_country');" <?php echo $cek_autority_edit;?>>Edit </a>
                                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delete_supporting('#tt_country',$('#tt_country').datagrid('getSelected').CountryCode,'<?php echo base_url()?>list/supporting/delete_country');" <?php echo $cek_autority_delete;?>>Delete </a>
                            </div>				
                        </div>		
                    </div>
                    <!-- End of Country -->
                </div>
            </div>
        </div>
    </form>
</div>

<!-- Dialog Template City -->
<div id="dialog-template-city" class="easyui-dialog" style="width:440px; height:255px; padding: 10px" closed="true" buttons="#dialog-buttons-city" data-options="modal:true">
    <form id="form_template_city" method="post" novalidate>
        <input type="hidden" name="id" class="id" />
        
        <table width="100%" border="0" cellspacing="1" cellpadding="1">   
            <tr height="20">
                <td width="120" align="left" valign="middle"><b>City Code</b></td>	
                <td width="10"><b>:</b></td>			
                <td> 
                    <input id="CityCode" name="CityCode" class="easyui-validatebox" style="text-transform:uppercase;width:300px; height:20px; border:1px solid #ccc" required="required" maxlength="3">
                </td>
            </tr>

            <tr height="20">
                <td><b>City Name</b></td>		
                <td><b>:</b></td>		
                <td> 
                    <input id="CityName" name="CityName"  class="easyui-validatebox" style="width:300px; height:20px; border:1px solid #ccc" required="required">
                </td>
            </tr>

            <tr height="20">
                <td><b>State Name</b></td>		
                <td><b>:</b></td>
                <td>
                    <select class="combo-grid" id="StateCode" name="StateCode" style="width:302px;height:25px" required editable="true"
                        data-options="
                            idField: 'StateCode',
                            textField: 'StateName',
                            url: '<?php echo base_url(); ?>custom/get_data/state',
                            method: 'post',
                            columns: [[
                                {field:'StateCode',title:'State Code', halign:'center', align:'left', width:110},
                                {field:'StateName',title:'State Name', halign:'center', align:'left', width:250},
                            ]],
                            fitColumns: true
                        ">
                    </select>
                </td>
            </tr>
            
            <tr height="20">
                <td valign="top" style="padding-top:4px;"><b>Description</b></td>		
                <td valign="top" style="padding-top:4px;"><b>:</b></td>		
                <td> 
                    <textarea class="easyui-validatebox" name="CityDesc" id="CityDesc" rows="4" style="width:296px;resize:none;white-space:normal;"></textarea>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-city" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_supporting('#form_template_city','#tt_city','#dialog-template-city');" <?php echo $cek_autority_save;?>>Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:jQuery('#dialog-template-city').dialog('close');">Close</a>
</div>

<!-- Dialog Template Jobtitle -->
<div id="dialog-template-jobtitle" class="easyui-dialog" style="width:480px; height:275px; padding: 10px" closed="true" buttons="#dialog-buttons-jobtitle" data-options="modal:true">
    <form id="form_template_jobtitle" method="post" novalidate>
	<input type="hidden" name="id" class="id" />
        
        <table width="100%" border="0" cellspacing="1" cellpadding="1">   
            <tr height="20">
                <td width="120" align="left" valign="middle"><b>Jobtitle Code</b></td>	
                <td width="10"><b>:</b></td>			

                <td> 
                    <input id="JobTitleCode" name="JobTitleCode" class="easyui-validatebox" style="text-transform:uppercase;width:300px; height:20px; border:1px solid #ccc" required="required" maxlength="3">
                </td>
            </tr>

            <tr height="20">
                <td><b>Jobtitle Name</b></td>		
                <td><b>:</b></td>		

                <td> 
                    <input id="JobTitleName" name="JobTitleName" class="easyui-validatebox" style="width:300px; height:20px; border:1px solid #ccc" required="required">
                </td>
            </tr>

            <tr height="20">
                <td valign="top" style="padding-top:4px;"><b>Description</b></td>
                <td valign="top" style="padding-top:4px;"><b>:</b></td>
    
                <td> 
                    <textarea class="easyui-validatebox" name="Description" id="Description" rows="4" style="width:296px;resize:none;white-space:normal;"></textarea>
                </td>
            </tr>

<!--                    <tr>
                    <td width="157" height="25" align="left" valign="middle"> Jobtitle Head</td>				

                    <td width="935" height="25" align="left" valign="middle" colspan="2"> 
                        <input id="JobTitleHead" name="JobTitleHead" class="easyui-validatebox" style="width:270px; height:20px; border:1px solid #ccc" >
                    </td>
                </tr>-->

            <tr height="20">
                <td width="120" align="left" valign="middle"><b>Index</b></td>	
                <td width="10"><b>:</b></td>			

                <td width="50" height="25" align="left" valign="middle"  colspan="2"> 
                    <select name="JobTitleLevel" id="JobTitleLevel" class="easyui-combobox" editable="false" style="width:302px;resize:none;white-space:normal;" >
                        <option value='1'>0</option>
                        <option value='2'>1</option>
                        <option value='3'>2</option>
                        <option value='4'>3</option>
                        <option value='5'>4</option>
                        <option value='6'>5</option>
                        <option value='7'>6</option>
                        <option value='8'>7</option>
                        <option value='9'>8</option>
                        <option value='10'>9</option>
                    </select>
                </td>
            </tr>
                
            <tr height="20">
                <td width="120" align="left" valign="middle"><b>Jobtitle Status</b></td>	
                <td width="10"><b>:</b></td>			

                <td width="50" height="25" align="left" valign="middle"  colspan="2"> 
                    <select name="JobTitleStatus" id="JobTitleStatus" class="easyui-combobox" editable="false" style="width:302px;resize:none;white-space:normal;" >
                        <option value='0'>Director</option>
                        <option value='1'>Managerial</option>
                        <option value='2'>Supervisor</option>
                        <option value='3'>Staff</option>
                        <option value='4'>Administrator</option>
                    </select>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-jobtitle" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_supporting('#form_template_jobtitle','#tt_jobtitle','#dialog-template-jobtitle');" <?php echo $cek_autority_save;?>>Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:jQuery('#dialog-template-jobtitle').dialog('close');">Close</a>
</div>

<!-- Dialog Template State -->
<div id="dialog-template-state" class="easyui-dialog" style="width:450px; height:250px; padding: 10px" closed="true" buttons="#dialog-buttons-state" data-options="modal:true">
    <form id="form_template_state" method="post" novalidate>
        <input type="hidden" name="id" class="id" />
		
        <table width="100%" border="0" cellspacing="1" cellpadding="1">   
            <tr height="20">
                <td width="110"><b>State Code</b></td>
                <td width="10"><b>:</b></td>
                <td> 
                    <input id="StateCode" name="StateCode" class="easyui-validatebox" style="text-transform:uppercase;width:300px; height:20px; border:1px solid #ccc" required="required">
                </td>
            </tr>

            <tr height="20">
                <td><b>State Name</b></td>
                <td><b>:</b></td>
                <td> 
                    <input id="StateName" name="StateName" class="easyui-validatebox" style="width:300px; height:20px; border:1px solid #ccc" required="required">
                </td>
            </tr>

            <tr height="20">
                <td ><b>Country Name</b></td>		
                <td><b>:</b></td>
                <td>
                    <select class="combo-grid" id="CountryCode" name="CountryCode" style="width:302px;height:25px" required editable="true"
                        data-options="
                            idField: 'CountryCode',
                            textField: 'CountryName',
                            url: '<?php echo base_url(); ?>custom/get_data/country',
                            method: 'post',
                            columns: [[
                                {field:'CountryCode',title:'Country Code',halign:'center',align:'left',width:110},
                                {field:'CountryName',title:'Country Name',halign:'center',align:'left',width:250}
                            ]],
                            fitColumns: true
                        ">
                    </select>
                </td>
            </tr>
            
            <tr height="20">
                <td valign="top" style="padding-top:4px;"><b>Description</b></td>
                <td valign="top" style="padding-top:4px;"><b>:</b></td>
                <td> 
                    <textarea class="easyui-validatebox" name="StateDesc" id="StateDesc" rows="4" style="width:296px;resize:none;white-space:normal;"></textarea>
                </td>
            </tr>	
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-state" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_supporting('#form_template_state','#tt_state','#dialog-template-state');" <?php echo $cek_autority_save;?>>Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:jQuery('#dialog-template-state').dialog('close');">Close</a>
</div>

<!-- Dialog Template Country -->
<div id="dialog-template-country" class="easyui-dialog" style="width:470px; height:218px; padding: 10px" closed="true" buttons="#dialog-buttons-country" data-options="modal:true">
    <form id="form_template_country" method="post" novalidate>
        <input type="hidden" name="id" class="id" />
		
        <table width="100%" border="0" cellspacing="1" cellpadding="1">   
            <tr height="20">
                <td width="150"><b>Country Code</b></td>
                <td width="10"><b>:</b></td>
                <td> 
                    <input id="CountryCode" name="CountryCode" class="easyui-validatebox" style="text-transform:uppercase;width:300px; height:20px; border:1px solid #ccc" required="required" maxlength="5">
                </td>
            </tr>

            <tr height="20">
                <td><b>Country Name</b></td>
                <td><b>:</b></td>
                <td> 
                    <input id="CountryName" name="CountryName" class="easyui-validatebox" style="text-transform:uppercase;width:300px; height:20px; border:1px solid #ccc" required="required">
                </td>
            </tr>

            <tr height="20">
                <td valign="top" style="padding-top:4px;"><b>Description</b></td>
                <td valign="top" style="padding-top:4px;"><b>:</b></td>
                <td> 
                    <textarea class="easyui-validatebox" name="CountryDesc" id="CountryDesc" rows="4" style="width:296px;resize:none;white-space:normal;"></textarea>
                </td>
            </tr>	
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-country" style="border:none;">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_supporting('#form_template_country','#tt_country','#dialog-template-country');" <?php echo $cek_autority_save;?>>Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:jQuery('#dialog-template-country').dialog('close');">Close</a>
</div>

<script type="text/javascript">
	
	var url;

    function new_supporting(pop_up, fm, insert_url){
        $(pop_up).dialog('open').dialog('setTitle','New');
        $(fm).form('clear');
        url = insert_url;
		
		var g = $('#tt_state').datagrid('getData');
		//alert (g + JSON.stringify(g));
	
		$('#StateCode').combogrid('loadData',g);
    }
	
    function edit_supporting(dtg, id, pop_up, fm, edit_url){
        var row = $(dtg).datagrid('getSelected');
        $('.id').val(id);
            
        if (row){
            $(pop_up).dialog('open').dialog('setTitle','Edit');
            $(fm).form('load',row);
            url = edit_url + '/' + id;
        }
    }
	
    function save_supporting(fm, dtg, dlg){
        $(fm).form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                
                if (result.status == false){
                    $.messager.alert('Failed',result.message,'error');
                }
                else {
                    $.messager.alert('Success',result.message,'info');

                    $(dlg).dialog('close');
                    $(dtg).datagrid('reload');
                } 
            }
        });
    }
	
	
	
    function delete_supporting(dtg, id, url){
        var row = $(dtg).datagrid('getSelected');
        
        if (row){
            $.messager.confirm('Confirm','Are you sure you want to remove this data?',function(r){
                if (r){						
                    $.post(url,{id:id},function(result){						
                        if (result.status){
                            $.messager.alert('Success',result.message,'info',function(){
                                $(dtg).datagrid('reload');
                            });				
                        } 
                        else {
                            $.messager.alert('Failed',result.message,'error');
                        }
                    },'json');
                }
            });
        }
    } 
</script>