<?php
include("lib/config.php");
?>
<script src="vendor/ckeditor/ckeditor.js"></script>
<div class="box-content">
  <form method="post" name="frmDepartments" id="frmDepartments">
    <input type="hidden" name="action" value="save">
   
    <div class="form-group">
      <label for="title">Name</label>
      <input type="text" class="form-control" name="name" id="name" value="" placeholder="" style="width:350px;" required>
    </div>
    <div class="form-group">
      <!--<label for="">Description</label>-->
        <table class="table table-striped table-bordered dataTable no-footer">
			  <thead>
				<tr>
				  <th width="100%" colspan="3">Detail</th>
				</tr>
			  </thead>
			<tbody>		
			<tr>
				<td colspan="3"><textarea name="description" id="editor1"></textarea>
				</td>
			</tr>
			</tbody>
			</table>
    </div>
    <!--<div class="form-group">
      <label for="title">Display Order</label>
      <input type="text" class="form-control" name="display_order" id="display_order" value="" placeholder="" style="width:350px;">
    </div>-->
    <div class="control-group">
    <label class="control-label" for="selectError">Status</label>
        <div class="controls">
            <select name="status" id="status" data-rel="chosen">                       
                <option value="1">Active</option>
                <option value="0">In Active</option>                                
            </select>
        </div>
    </div>
    
    <div style="margin-top:30px; text-align:right;">
      <!--<input type="button" class="btn btn-primary" value="<?=(isset($_GET['pid']))?'Update':'Save'?>">-->
      
      <button data-loading-text="Saving..." type="submit" class="btn btn-success"> <i class="fa fa-floppy-o"></i> Save</button>
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            
    </div>
  </form>
</div>

<script>
$(document).ready(function(e){
    $("#frmDepartments").on('submit', function(e){
	
        e.preventDefault();
		
		for (instance in CKEDITOR.instances) {
			CKEDITOR.instances[instance].updateElement();
		}
	
        $.ajax({
            type: 'POST',
            url: 'departments-config.php',
            data: new FormData(this),
            //data: userData,
            contentType: false,
            cache: false,
            processData:false,
			dataType: 'JSON',
            beforeSend: function(){
                //$('.submitBtn').attr("disabled","disabled");
                //$('#fupForm').css("opacity",".5");
            },
            success: function(msg){				
                //$('.statusMsg').html('');
				
                if(msg[0].message == 'ok'){
				
                    $('#frmDepartments')[0].reset();
					
					//$('.statusMMsg').html('<span style="font-size:18px;color:#34A853">Product(s) added successfully.</span>');
					$('#myModal').modal('hide');
					
					getDepartments(); 
					
					Lobibox.notify('success', {
						title: 'Success',
						msg: 'Record added successfully.'
					});
					
                }
				else
				{   
					//$('.statusMMsg').html('<span style="font-size:18px;color:#EA4335">Some problem occurred, please try again.</span>');
					$('#myModal').modal('hide');
					
					Lobibox.notify('error', {
						title: 'Error',
						msg: 'Some problem occurred, please try again.'
					});
                }
            }
        });
    });
	
});
</script>

<script>
	CKEDITOR.replace( 'editor1', {
		fullPage: true,
		allowedContent: true,
		extraPlugins: 'wysiwygarea'
	});
</script>
