<? global $vis_language;?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
    <div class="col-sm-6">
        <h3 class="m-b-xs text-black"><? echo $vis_language['TXTASSETS']; ?></h3>
        <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
            <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
            <li class="active"><a class="link" href="#/cmdb/assets/<?php echo $vis_language['TXTASSETS'];?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTASSETS'];?>',{'vis_module':'<?=$operation['vis_module'];?>','vis_operation':'assets'});"><? echo $vis_language['TXTASSETS'];?></a></li>
            <li class="active"><? echo $vis_language['TXTADDCI'];?></li>
        </ul>
    </div>
</section>
<section class="padder">
    <section class="panel panel-default">
        <header class="panel-heading sub_header"><? echo $vis_language['TXTADDCI']; ?></header>
        <div class="panel-body">
            <form class="form-horizontal" role="form" id="vis_add_assets_form" name="vis_add_assets_form" method="post">
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTNAME']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_name" id="vis_name">
					</div>
				</div>
                <div class="form-group">
					<label class="col-sm-2 control-label"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
					<div class="col-sm-10">
						<select name="vis_department" id="vis_department" class="form-control input-sm selectpicker"<? if(count($departments)>10) echo ' data-live-search="true"';?>>
						<option value="0"> <? echo $vis_language['TXTSELECT']; ?> </option>
						<? if($departments!=-1) for($d=0;$d<count($departments); $d++)
							echo '<option value="'.$departments[$d]['domain_id'].':'.$departments[$d]['department_id'].'">'.$departments[$d]['domain_name'].' :: '.$departments[$d]['department_name'].'</option>'
						?>
						</select>
					</div>
				</div>
				<div class="form-group">
				   <label class="col-sm-2 control-label"><? echo $vis_language['TXTCITYPE']; ?></label>
				   <div class="col-sm-10" id="citype_list">
					<select class="form-control selectpicker" onchange="set_property(this.value,$('#vis_department').val());" name="vis_ci_type_id" id="vis_ci_type_id" disabled>
					<option value=""> <? echo $vis_language['TXTSELECT']; ?> </option>
					  <? /*
					  for($i=0;$i<count($citype_details);$i++) {
						  ?>
					  <option value="<? echo $citype_details[$i]['item_id']; ?>"> <? echo $citype_details[$i]['name']; ?></option>
					  <? } */?>
					</select>
				   </div>
				</div>
				<div class="form-group" >
				   <label class="col-sm-2 control-label"><? echo $vis_language['TXTIMPACT']; ?></label>
				   <div class="col-sm-10" id="impact_list">
					<select class="form-control selectpicker" name="vis_impact_id" id="vis_impact_id" disabled>
					<option value=""> <? echo $vis_language['TXTSELECT']; ?> </option>
					  <? /*for($i=0;$i<count($impact_details);$i++) { ?>
					  <option value="<? echo $impact_details[$i]['impact_id']; ?>"> <? echo $impact_details[$i]['name']; ?></option>
					  <? } */?>
					</select>
				   </div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTDESCRIPTION']; ?></label>
					<div class="col-sm-10">
						<textarea name="vis_description" id="vis_description" class="form-control" rows="10"></textarea>
					</div>
				</div>
				<div id="assets_property" style="display:none;">
                </div>
				<div id="custom_fields"></div>
				<div class="line b-b line-lg pull-in"></div>
				<br/>
				<div class="form-group"><label class="col-sm-2 control-label"><strong><? echo $vis_language['TXTASSIGNMENT']; ?></strong></label></div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTMANAGEDBY']; ?></label>
					<div class="col-sm-10" id="staff_list">
 						<select class="form-control selectpicker" name="vis_managed_by" id="vis_managed_by" disabled>
							<option value=""> <? echo $vis_language['TXTSELECT']; ?> </option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTUSEDBY']; ?></label>
					<div class="col-sm-10">
					<input class="form-control input-sm" type="text" name="vis_usedby" id="vis_usedby"  placeholder="<?= $vis_language['TXTTYPETOSEARCHEXISTINGCLIENTSEMAILADDRESS']?>" data-resize="no" style="width:100%"/>
                                <script type="text/javascript">
                                    $(document).ready(function() {
                                        $("#vis_usedby").tokenInput(
                                            "index.php?vis_module=cmdb&vis_operation=get_staff_client_details",
                                            {
                                                theme: "facebook",
                                                searchDelay: 300,
                                                minChars: 3,
                                                queryParam: "vis_data",
                                                propertyToSearch: "email",
                                                tokenValue: "email",
                                                tokenLimit: 1,
                                                preventDuplicates: true,
                                                resultsFormatter: function(item) {
                                                    return "<li>" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.full_name + " < " + item.email + " ></div></div></li>";
                                                },
                                                tokenFormatter: function(item) {
                                                    return "<li><p>" + item.email + "</p></li>";
                                                }
                                            }
                                        );
                                        $("div.token-input-dropdown-facebook").css('width', $(".token-input-list-facebook").width() + 2 + 'px');
                                        $("#token-input-vis_usedby").parent().css('width','100%');
                                    });</script>
                     </div>
				</div>
				<div class="form-group">
				   <label class="col-sm-2 control-label"><? echo $vis_language['TXTLOCATION']; ?></label>
				   <div class="col-sm-10" id="location_list">
					<select class="form-control selectpicker" name="vis_location_id" id="vis_location_id" disabled>
					<option value=""> <? echo $vis_language['TXTSELECT']; ?> </option>
					  <? /*
					  for($i=0;$i<count($location_details);$i++) {
						  ?>
					  <option value="<? echo $location_details[$i]['location_id']; ?>"> <? echo $location_details[$i]['name']; ?></option>
					  <? } */?>
					</select>
				   </div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTASSIGNEDON']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm from_date" data-type="text" data-required="true" name="vis_assigned_on" id="vis_assigned_on" value="<? //date("M-d, Y H:m")?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTATTACHFILE']; ?></label>
					<div class="col-sm-10">
						<input type="file" name="files[]" multiple="multiple" onchange=" $(this).visExecution('upload_file', {'vis_static_area':'#vis_csv_attachments', 'vis_form':'vis_add_assets_form', 'vis_form_attachment_area':'#vis_attachments'})" class="filestyle" data-input="false" data-icon="true" data-classButton="btn btn-link link" data-iconName="vh-chat" data-buttonText="<?=$vis_language['TXTCHOOSEFILE']?>" data-badge="true"/>
						<input type="hidden" name="vis_location" value="<? echo VIS_DOMAIN; ?>" />
						<input type="hidden" name="vis_attachments" id="vis_attachments" value="" />
						<div id="vis_csv_attachments"></div>
					</div>
				</div>
		    </form>
            <div class="b-2x b-t m-b-md"></div>
				<div class="col-sm col-sm-offset-2">
					<button type="button" class="btn btn-primary" onClick="file_read();"><? echo $vis_language['TXTADD']; ?></button>
				</div> <br/>
			</div>
    </section>
</section>
<? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>	<script src="<?= VIS_PATH_PLUGINS; ?>redactor/source.js"></script> <?}?>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<script>
	check_expiry();
	<? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>
	$(function() {
            $('#vis_description').redactor({
				buttonSource: true,
				minHeight: 180, // pixels
                maxHeight: 180,
                imageUpload: false,
                imageUploadParam: 'files',
                deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet'],
                plugins: ['source']		
            });
			$(".redactor-toolbar").attr('z-index', '3 !important');
        });
    <?php }?>
var d = new Date();
var curr_time = d.getHours()+":"+d.getMinutes();
var curr_date= '<? echo date("M-d, Y")?> '+curr_time+'';
//''+curr_day+'-'+curr_month+'-'+curr_year+''
	$(".selectpicker").selectpicker();
	//$('.from_date').val(new Date());
	$('.from_date').datetimepicker({ format: "<?php echo VIS_DATETIMEPICKER_FORMAT;?>",defaultDate: curr_date});
	$("#vis_department").change(function () {
		var data = { vis_module:"<?=$operation['vis_module'];?>", vis_operation:"get_filterdata_list", vis_department_id:this.value };
		$.ajax({
			url: 'index.php',
			data: data,
			type: "POST",
			dataType: "json",
			success: function(data) {
				$("#citype_list").html('');
				$("#staff_list").html('');
				$("#impact_list").html('');
				$("#location_list").html('');
				if(data!=-1)
					$("#citype_list").html(data.citype_list);
					$("#staff_list").html(data.staff_list);
					$("#impact_list").html(data.impact_list);
					$("#location_list").html(data.location_list);
					$(".selectpicker").selectpicker();
			},
			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
		});
	});
	function get_cidata(id){
		var data = { vis_module:"cmdb", vis_operation:"get_custom_fields", ci_type_id:id, assets_id:'' };   
		$.ajax({
			url: 'index.php',
			data: data,
			type: "POST",
			dataType: "json",
			success: function(data) {
				$("#custom_fields").html('');
				if(data!=-1)
				{
					$("#custom_fields").html(data);
					$('.date').datetimepicker({ format: "<?php echo VIS_DATETIMEPICKER_FORMAT;?>"});
				}
			},
			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
		});
	}

	/*$("#vis_ci_type_id").change(function () {
		var data = { vis_module:"<?=$operation['vis_module'];?>", vis_operation:"get_custom_fields", ci_type_id:this.value, assets_id:'-1' };
		$.ajax({
			url: 'index.php',
			data: data,
			type: "POST",
			dataType: "json",
			success: function(data) {
				$("#custom_fields").html('');
				if(data!=-1)
					$("#custom_fields").html(data);
			},
			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
		});
	});*/

	function check_expiry(){
		if ($('#vis_notify_expiry').is(":checked"))$('#notify_expiry').show();
		else $('#notify_expiry').hide();
	}

	function vis_remove_attachment(file_id, attach_location){
		var loc = '';
		loc = (attach_location != "" && typeof(attach_location) != "undefined") ? attach_location : "vis_image_attachments";
		$("#" + loc).val( $("#" + loc).val().replace(file_id + ',', '') );
	}

	$(document).ready(function () {
		$(":file").filestyle({input: false});
		
      });

	function toggle_dept_list(){
       if($('#vis_department_all').is(":checked")) $('#vis_dept_list_section').hide();
       else $('#vis_dept_list_section').show();
	    $('.dept_access_list').each(function(index) {
        $(this).find('input[type="checkbox"]').removeAttr('checked');
       });
    }
	function set_property(vis_config_id ,deptid){
		$("#custom_fields").html('');
		get_cidata(vis_config_id);
		$('#assets_property').show();
		$('#assets_property').visExecution('load_operations', {'vis_module':'cmdb', 'vis_operation':'get_assets_properties','vis_config_id':''+vis_config_id+'','vis_module_section':'add','vis_departmentid':deptid});
	}
	
	function file_read(){
	var textArray = Array.prototype.slice.call(document.querySelectorAll('.btn.btn-xs.alert-success')).map(function(span){
	return span.textContent;
	
	 });
	 
    $('#vis_add_assets_form').visExecution('submit_form',{'vis_module':'<?=$operation['vis_module'];?>', 'vis_operation':'add_ci','vis_attach_name':''+textArray+'', 'vis_form':'vis_add_assets_form'});
}
</script>
</section>
