raw material auto complete box changes
This commit is contained in:
parent
c669e3af7f
commit
9974c62570
@ -123,10 +123,10 @@ class rawmaterialdetails extends BaseController
|
||||
*/
|
||||
function addNewRawMaterial()
|
||||
{
|
||||
|
||||
$TempArr = [];
|
||||
$this->form_validation->set_rules('MaterialName','Material Name','trim|required|');
|
||||
$this->form_validation->set_rules('MaterialType','MaterialType','trim|callback_MaterialType_validate');
|
||||
$this->form_validation->set_rules('MaterialCategory','MaterialCategory','trim|callback_materialcategory_validate');
|
||||
// $this->form_validation->set_rules('MaterialCategory','MaterialCategory','trim|callback_materialcategory_validate');
|
||||
$this->form_validation->set_rules('UOM','UOM','trim|callback_UOM_validate');
|
||||
|
||||
if($this->form_validation->run() == FALSE)
|
||||
@ -138,7 +138,26 @@ class rawmaterialdetails extends BaseController
|
||||
$MaterialName = $this->input->post('MaterialName');//print_r($MaterialName);
|
||||
$MaterialType = $this->input->post('MaterialType');
|
||||
$UOM = $this->input->post('UOM');
|
||||
$MaterialCategory = $this->input->post('MaterialCategory');
|
||||
//$MaterialCategory = $this->input->post('MaterialCategory');
|
||||
$MaterialCategory = $this->input->post('MatCate');
|
||||
$materialcategoryarray = $this->rawmaterialdetails_model->getmaterialCategory();
|
||||
|
||||
foreach($materialcategoryarray as $mc){
|
||||
$TempArr[] = $mc->ConfigValue;
|
||||
|
||||
}
|
||||
//print_r($TempArr);
|
||||
if (in_array($MaterialCategory, $TempArr))
|
||||
{
|
||||
//echo "Match found";
|
||||
}
|
||||
else
|
||||
{
|
||||
//echo "Match not found";
|
||||
$configcode = 'C023';
|
||||
$config = array('Config_ID'=>$configcode,'ConfigValue'=>$MaterialCategory);
|
||||
$query= $this->rawmaterialdetails_model->insertvalueintoconfig($config);
|
||||
}
|
||||
$Remarks = $this->input->post('remarks');
|
||||
$asset = $this->input->post('Assetcode');//print_r($AssetCode);
|
||||
$costcentercode = $this->input->post('Costcenter');//print_r($CostCenterCode);
|
||||
@ -267,7 +286,26 @@ class rawmaterialdetails extends BaseController
|
||||
$MaterialCode = $this->input->post('MaterialCode');
|
||||
$MaterialName = $this->input->post('MaterialName');
|
||||
$MaterialType = $this->input->post('MaterialType');
|
||||
//$MaterialCategory =$this->input->post('MaterialCategory');
|
||||
$MaterialCategory =$this->input->post('MaterialCategory');
|
||||
$materialcategoryarray = $this->rawmaterialdetails_model->getmaterialCategory();
|
||||
|
||||
foreach($materialcategoryarray as $mc){
|
||||
$TempArr[] = $mc->ConfigValue;
|
||||
|
||||
}
|
||||
//print_r($TempArr);
|
||||
if (in_array($MaterialCategory, $TempArr))
|
||||
{
|
||||
//echo "Match found";
|
||||
}
|
||||
else
|
||||
{
|
||||
//echo "Match not found";
|
||||
$configcode = 'C023';
|
||||
$config = array('Config_ID'=>$configcode,'ConfigValue'=>$MaterialCategory);
|
||||
$query= $this->rawmaterialdetails_model->insertvalueintoconfig($config);
|
||||
}
|
||||
$UOM = $this->input->post('UOM');
|
||||
$rmcode = $this->input->post('RMcode');
|
||||
$Remarks = $this->input->post('remarks');
|
||||
@ -338,6 +376,31 @@ class rawmaterialdetails extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
function autocomplete()
|
||||
{
|
||||
|
||||
$this->load->model('model','rawmaterialdetails_model');
|
||||
|
||||
$mc = $this->input->get('query');
|
||||
|
||||
$query= $this->rawmaterialdetails_model->checkMaterialCategory($mc);
|
||||
|
||||
echo json_encode($query);
|
||||
|
||||
}
|
||||
|
||||
function insertvalueintoconfig(){
|
||||
$this->load->model('model','rawmaterialdetails_model');
|
||||
$mc = $this->input->post('id');
|
||||
$configcode = 'C023';
|
||||
$config = array('Config_ID'=>$configcode,'ConfigValue'=>$mc);
|
||||
|
||||
$query= $this->rawmaterialdetails_model->insertvalueintoconfig($config);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To Check and display the already existing material list
|
||||
*/
|
||||
|
||||
@ -185,5 +185,32 @@ class rawmaterialdetails_model extends CI_Model
|
||||
// $this->db->update('T_PurchaseOrderDetails', $POInfo);
|
||||
// return $this->db->affected_rows();
|
||||
// }
|
||||
|
||||
function insertvalueintoconfig($config){
|
||||
|
||||
$this->db->insert('T_ConfigDetails', $config);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function checkMaterialCategory($mc){
|
||||
|
||||
$temp[] = '' ;
|
||||
$temparr[] = '' ;
|
||||
|
||||
$this->db->distinct();
|
||||
$this->db->select('ConfigValue');
|
||||
$this->db->from('T_ConfigDetails');
|
||||
$this->db->where('Config_ID','C023');
|
||||
$this->db->like('ConfigValue',$mc);
|
||||
|
||||
$query = $this->db->get();
|
||||
|
||||
foreach($query->result() as $arr){
|
||||
$temparr[] = $arr->ConfigValue ;
|
||||
}
|
||||
|
||||
$temp['suggestions'] = $temparr;
|
||||
return $temp;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,55 +1,12 @@
|
||||
<script>
|
||||
function isNumberKey(evt)
|
||||
{
|
||||
var charCode = (evt.which) ? evt.which : evt.keyCode;
|
||||
if (charCode != 46 && charCode > 31
|
||||
&& (charCode < 48 || charCode > 57))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function BlockSpecial(evt) {
|
||||
var charCode;
|
||||
// if (window.event)
|
||||
// charCode = window.event.keyCode; //for IE
|
||||
// else
|
||||
// charCode = evt.which; //for firefox
|
||||
|
||||
if (charCode >= 91 && charCode <= 96)
|
||||
return false;
|
||||
if (charCode >= 123 && charCode <= 126)
|
||||
return false;
|
||||
if (charCode >= 33 && charCode <= 47)
|
||||
return false;
|
||||
if (charCode >= 58&& charCode <= 64)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function onlyAlphabets(evt) {
|
||||
var charCode;
|
||||
if (window.event)
|
||||
charCode = window.event.keyCode; //for IE
|
||||
else
|
||||
charCode = evt.which; //for firefox
|
||||
if (charCode == 32) //for <space> symbol
|
||||
return true;
|
||||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
<style>
|
||||
.autocomplete-suggestion{
|
||||
cursor:pointer;
|
||||
background-color:White;
|
||||
/* background-color: darkgrey; */
|
||||
outline: 1px solid slategrey;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="<?php echo base_url();?>assets/Autocomplete/jquery.autocomplete.js"></script>
|
||||
<div class="content-wrapper" style="min-height: 537px;">
|
||||
<!-- Content Header (Page header) -->
|
||||
<section class="content-header">
|
||||
@ -79,7 +36,7 @@ function BlockSpecial(evt) {
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="MaterialName">Material Name</label><font color="Red">*</font>
|
||||
<input type="text" class="form-control required " onkeypress="return BlockSpecial(event);" onchange="hello()" required id="MaterialName" name="MaterialName" maxlength="255">
|
||||
<input type="text" class="form-control required " onkeypress="return BlockSpecial(event);" required id="MaterialName" name="MaterialName" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -104,7 +61,16 @@ function BlockSpecial(evt) {
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-3" >
|
||||
<div class="form-group autoSearch" id="mc">
|
||||
<label for="Matcate">Material Caterogy</label><font color="Red">*</font>
|
||||
<input type="text" class="form-control required " required id="MatCate" name="MatCate" maxlength="255" >
|
||||
<!-- <div id="tagsname"></div> -->
|
||||
<!-- <input type="text" class="form-control" id="HideMatCate" name="HideMatCate" readonly> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="MaterialCategory">Material Category</label><font color="Red">*</font>
|
||||
<select class="form-control required select2" id="MaterialCategory" name="MaterialCategory" onchange="changeTextBox()">
|
||||
@ -122,7 +88,7 @@ function BlockSpecial(evt) {
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
@ -243,41 +209,103 @@ function BlockSpecial(evt) {
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?php
|
||||
$this->load->helper('form');
|
||||
$error = $this->session->flashdata('error');
|
||||
if($error)
|
||||
{
|
||||
?>
|
||||
<div class="alert alert-danger alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<?php echo $this->session->flashdata('error'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$success = $this->session->flashdata('success');
|
||||
if($success)
|
||||
{
|
||||
?>
|
||||
<div class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<?php echo $this->session->flashdata('success'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<script src="<?php echo base_url(); ?>assets/js/addUser.js" type="text/javascript"></script>
|
||||
<script>
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
$("#MaterialType").select2();
|
||||
// $("#MaterialCategory").select2();
|
||||
$("#UOM").select2();
|
||||
$("#Assetcode").select2();
|
||||
$("#Costcenter").select2();
|
||||
$("#conversionfactorUOM").select2();
|
||||
|
||||
$('#MatCate').autocomplete({
|
||||
|
||||
onSearchStart: function (query) {
|
||||
|
||||
$('#MatCate').autocomplete("option", "minLength", 0);
|
||||
},
|
||||
|
||||
serviceUrl: "<?php echo base_url();?>rawmaterialdetails/autocomplete",
|
||||
onSelect: function (suggestion) {
|
||||
|
||||
var data = suggestion.ConfigValue;
|
||||
var selectedvalue = $('input[name=MatCate]').val();
|
||||
if(selectedvalue=='Spares')
|
||||
{
|
||||
//alert('good');
|
||||
//$('#contest_num').hide();
|
||||
$('#Assetcode').prop('disabled', false);
|
||||
$('#Costcenter').prop('disabled', false);
|
||||
}
|
||||
else{
|
||||
// // alert('bad');
|
||||
$('#Assetcode').prop('disabled', 'disabled');
|
||||
$('#Costcenter').prop('disabled', 'disabled');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
function isNumberKey(evt)
|
||||
{
|
||||
var charCode = (evt.which) ? evt.which : evt.keyCode;
|
||||
if (charCode != 46 && charCode > 31
|
||||
&& (charCode < 48 || charCode > 57))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function BlockSpecial(evt) {
|
||||
var charCode;
|
||||
// if (window.event)
|
||||
// charCode = window.event.keyCode; //for IE
|
||||
// else
|
||||
// charCode = evt.which; //for firefox
|
||||
|
||||
if (charCode >= 91 && charCode <= 96)
|
||||
return false;
|
||||
if (charCode >= 123 && charCode <= 126)
|
||||
return false;
|
||||
if (charCode >= 33 && charCode <= 47)
|
||||
return false;
|
||||
if (charCode >= 58&& charCode <= 64)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function onlyAlphabets(evt) {
|
||||
var charCode;
|
||||
if (window.event)
|
||||
charCode = window.event.keyCode; //for IE
|
||||
else
|
||||
charCode = evt.which; //for firefox
|
||||
if (charCode == 32) //for <space> symbol
|
||||
return true;
|
||||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function Validate()
|
||||
{
|
||||
if($("#MaterialName").val().length < 1)
|
||||
@ -360,27 +388,17 @@ $('#MaterialName').change(function() {
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
$("#MaterialType").select2();
|
||||
$("#MaterialCategory").select2();
|
||||
$("#UOM").select2();
|
||||
$("#Assetcode").select2();
|
||||
$("#Costcenter").select2();
|
||||
$("#conversionfactorUOM").select2();
|
||||
|
||||
|
||||
});
|
||||
function changeTextBox() {
|
||||
var x = document.getElementById("MaterialCategory");
|
||||
if(x.value=='Spares')
|
||||
{
|
||||
document.getElementById("Assetcode").disabled=false;
|
||||
document.getElementById("Costcenter").disabled=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("Assetcode").disabled=true;
|
||||
document.getElementById("Costcenter").disabled=true; }
|
||||
}
|
||||
|
||||
// function changeTextBox() {
|
||||
// var x = document.getElementById("MaterialCategory");
|
||||
// if(x.value=='Spares')
|
||||
// {
|
||||
// document.getElementById("Assetcode").disabled=false;
|
||||
// document.getElementById("Costcenter").disabled=false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// document.getElementById("Assetcode").disabled=true;
|
||||
// document.getElementById("Costcenter").disabled=true; }
|
||||
// }
|
||||
</script>
|
||||
373
application/views/addRawMaterial0.php
Executable file
373
application/views/addRawMaterial0.php
Executable file
@ -0,0 +1,373 @@
|
||||
<style>
|
||||
.autocomplete-suggestion{
|
||||
cursor:pointer;
|
||||
background-color:skyblue;
|
||||
/* background-color: darkgrey; */
|
||||
outline: 1px solid slategrey;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="<?php echo base_url();?>assets/Autocomplete/jquery.autocomplete.js"></script>
|
||||
<div class="content-wrapper" style="min-height: 537px;">
|
||||
<!-- Content Header (Page header) -->
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
|
||||
<center>Siddharth Industries - Add New Material </center>
|
||||
|
||||
</h1>
|
||||
|
||||
</section>
|
||||
|
||||
<section class="content" id="content">
|
||||
<div style="text-align:right;">
|
||||
<a href="<?php echo base_url() ?>rawmaterialdetails/rawmaterialListing" class="btn btn-primary" value="Back"/>Back</a>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="row">
|
||||
<!-- left column -->
|
||||
<div class="col-md-12">
|
||||
<!-- general form elements -->
|
||||
<div class="box box-primary">
|
||||
|
||||
<!-- form start -->
|
||||
|
||||
<form id="addUser" action="<?php echo base_url() ?>rawmaterialdetails/addNewRawMaterial" method="post" role="form">
|
||||
|
||||
|
||||
<div class="box-body">
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="MaterialName">Material Name</label><font color="Red">*</font>
|
||||
<input type="text" class="form-control required " onkeypress="return BlockSpecial(event);" required id="MaterialName" name="MaterialName" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="MaterialType">Material Type</label><font color="Red">*</font>
|
||||
<select class="form-control select2" required id="MaterialType" name="MaterialType">
|
||||
<option value="" required>Select Material Type</option>
|
||||
<?php
|
||||
if(!empty($material))
|
||||
{
|
||||
foreach ($material as $SID)
|
||||
{
|
||||
?>
|
||||
<option value="<?php echo $SID->ConfigValue ?>"><?php echo $SID->ConfigValue ?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="col-md-3" >
|
||||
<div class="form-group autoSearch" id="mc">
|
||||
<label for="Matcate">Material Caterogy</label><font color="Red">*</font>
|
||||
<input type="text" class="form-control required " required id="MatCate" name="MatCate" maxlength="255" >
|
||||
<!-- <div id="tagsname"></div> -->
|
||||
<!-- <input type="text" class="form-control" id="HideMatCate" name="HideMatCate" readonly> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="UOM">Unit of Measurement</label><font color="Red">*</font>
|
||||
<select class="form-control required select2" id="UOM" name="UOM" >
|
||||
<option value="" required>Select UOM</option>
|
||||
<?php
|
||||
if(!empty($UOM))
|
||||
{
|
||||
foreach ($UOM as $SID)
|
||||
{
|
||||
?>
|
||||
<option value="<?php echo $SID->ConfigValue; ?>"><?php echo $SID->ConfigValue ?>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="Assetcode">Asset Code</label>
|
||||
<select class="form-control select2" id="Assetcode" name="Assetcode" disabled="true">
|
||||
<option value="0">Select Asset Code</option>
|
||||
<?php
|
||||
if(!empty($assetcode))
|
||||
{
|
||||
foreach ($assetcode as $AC)
|
||||
{
|
||||
?>
|
||||
<option value="<?php echo $AC->AssetCode ?>"><?php echo $AC->AssetCode ?> - <?php echo $AC->AssetName ?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="Costcenter">Cost Center Code</label>
|
||||
<select class="form-control select2" id="Costcenter" name="Costcenter" disabled="true">
|
||||
<option value="0">Select Cost Center</option>
|
||||
<?php
|
||||
if(!empty($costcentercode))
|
||||
{
|
||||
foreach ($costcentercode as $CC)
|
||||
{
|
||||
?>
|
||||
<option value="<?php echo $CC->CostCenterCode ?>"><?php echo $CC->CostCenterCode ?> - <?php echo $CC->CostCenterName?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="conversionfactor">Conversion Factor</label>
|
||||
<input type="text" class="form-control" id="conversionfactor" name="conversionfactor" maxlength="255" onkeypress="return onlyAlphabets(event);">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="conversionfactorUOM">Conversion Factor UOM</label>
|
||||
<select class="form-control select2" id="conversionfactorUOM" name="conversionfactorUOM">
|
||||
<option value="0">Select Conversion Factor UOM</option>
|
||||
<?php
|
||||
if(!empty($cfUOM))
|
||||
{
|
||||
foreach ($cfUOM as $cfuom)
|
||||
{
|
||||
?>
|
||||
<option value="<?php echo $cfuom->ConfigValue; ?>"><?php echo $cfuom->ConfigValue ?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="HSNcode">HSN code</label>
|
||||
<input type="text" class="form-control" id="HSNcode" onkeypress="return isNumberKey(event)" name="HSNcode" maxlength="8">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="remarks">Remarks</label>
|
||||
<input type="text" class="form-control" id="remarks" name="remarks" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="Active">IsActive</label> <br>
|
||||
<input type="checkbox" id="isactive" name="isactive" >
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!-- /.box-body -->
|
||||
|
||||
<div class="box-footer" style="text-align:right">
|
||||
<input type="reset" class="btn btn-primary" value="Reset" />
|
||||
<input type="submit" onclick="Validate();" value="Submit" class="btn btn-primary">
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?php
|
||||
$this->load->helper('form');
|
||||
$error = $this->session->flashdata('error');
|
||||
if($error)
|
||||
{
|
||||
?>
|
||||
<div class="alert alert-danger alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<?php echo $this->session->flashdata('error'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$success = $this->session->flashdata('success');
|
||||
if($success)
|
||||
{
|
||||
?>
|
||||
<div class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<?php echo $this->session->flashdata('success'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<script src="<?php echo base_url(); ?>assets/js/addUser.js" type="text/javascript"></script>
|
||||
<script>
|
||||
|
||||
|
||||
//var tempARRAY = [];
|
||||
$(document).ready(function(){
|
||||
$("#MaterialType").select2();
|
||||
|
||||
// $("#MaterialCategory").select2();
|
||||
$("#UOM").select2();
|
||||
$("#Assetcode").select2();
|
||||
$("#Costcenter").select2();
|
||||
$("#conversionfactorUOM").select2();
|
||||
|
||||
$('#MatCate').autocomplete({
|
||||
|
||||
onSearchStart: function (query) {
|
||||
//alert(query);
|
||||
$('#MatCate').autocomplete("option", "minLength", 0);
|
||||
},
|
||||
|
||||
serviceUrl: "<?php echo base_url();?>rawmaterialdetails/autocomplete",
|
||||
onSelect: function (suggestion) {
|
||||
|
||||
var data = suggestion.ConfigValue;
|
||||
var selectedvalue = $('input[name=MatCate]').val();
|
||||
if(selectedvalue=='Spares')
|
||||
{
|
||||
//alert('good');
|
||||
//$('#contest_numofwinners').hide();
|
||||
$('#Assetcode').prop('disabled', false);
|
||||
$('#Costcenter').prop('disabled', false);
|
||||
}
|
||||
else{
|
||||
// // alert('bad');
|
||||
$('#Assetcode').prop('disabled', 'disabled');
|
||||
$('#Costcenter').prop('disabled', 'disabled');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
function isNumberKey(evt)
|
||||
{
|
||||
var charCode = (evt.which) ? evt.which : evt.keyCode;
|
||||
if (charCode != 46 && charCode > 31
|
||||
&& (charCode < 48 || charCode > 57))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function onlyAlphabets(evt) {
|
||||
var charCode;
|
||||
if (window.event)
|
||||
charCode = window.event.keyCode; //for IE
|
||||
else
|
||||
charCode = evt.which; //for firefox
|
||||
if (charCode == 32) //for <space> symbol
|
||||
return true;
|
||||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$('#MaterialName').change(function() {
|
||||
|
||||
var materialname = $('#MaterialName').val();
|
||||
//var s = "I am Given String ";
|
||||
//material = material.replace(/\s*$/,"");
|
||||
var material = materialname.replace(/ /g,'');
|
||||
//alert(m.length+" "+m+" "+s+" "+s.length);
|
||||
$('#content').loader('show');
|
||||
$.ajax({
|
||||
data:{id:material},
|
||||
type:"POST",
|
||||
url:"<?php echo base_url();?>rawmaterialdetails/checkmaterial",
|
||||
success:function(data) {
|
||||
var count = data.length;
|
||||
//alert(count);
|
||||
|
||||
if(count >2 ){
|
||||
$('#content').loader('hide');
|
||||
alert('Material name already existed ! ');
|
||||
dat = JSON.parse(data);
|
||||
var related_name = "";
|
||||
$.each(dat,function(i,obj){
|
||||
|
||||
related_name += obj.MaterialCode +" - "+ obj.MaterialName+" - "+obj.MaterialType+" - "+obj.Category+"\n";
|
||||
|
||||
});
|
||||
|
||||
alert("'" + materialname + "' - related materials are , " + " \n \n" + related_name);
|
||||
$("#MaterialName").focus();
|
||||
}
|
||||
else{
|
||||
$('#content').loader('hide');
|
||||
// alert("empty data");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function Validate()
|
||||
{
|
||||
if($("#MaterialName").val().length < 1)
|
||||
{
|
||||
alert('Please Enter MaterialName');
|
||||
$("#MaterialName").focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if($("option:selected", $("#UOM")).val() == "")
|
||||
{
|
||||
alert('Please Select UOM ');
|
||||
$("#UOM").focus();
|
||||
return false;
|
||||
}
|
||||
if($("option:selected", $("#MaterialCategory")).val() == "")
|
||||
{
|
||||
alert('Please Select Material Category');
|
||||
$("#MaterialCategory").focus();
|
||||
return false;
|
||||
}
|
||||
if($("option:selected", $("#MaterialType")).val() == "")
|
||||
{
|
||||
alert('Please Select Material Type');
|
||||
$("#MaterialType").focus();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -46,99 +46,15 @@ if(!empty($materialDetails))
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
//$("#MaterialType").select2();
|
||||
//$("#MaterialCategory").select2();
|
||||
// $("#UOM").select2();
|
||||
// $("#Assetcode").select2();
|
||||
// $("#Costcenter").select2();
|
||||
// $("#conversionfactorUOM").select2();
|
||||
|
||||
var x = $("#MaterialCategory").val() == 'Spares';
|
||||
if(x)
|
||||
{
|
||||
document.getElementById("Assetcode").disabled=false;
|
||||
document.getElementById("Costcenter").disabled=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//alert('i am a else part');
|
||||
document.getElementById("Assetcode").disabled=true;
|
||||
document.getElementById("Costcenter").disabled=true;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
function onlyAlphabets(evt) {
|
||||
var charCode;
|
||||
if (window.event)
|
||||
charCode = window.event.keyCode; //for IE
|
||||
else
|
||||
charCode = evt.which; //for firefox
|
||||
if (charCode == 32) //for <space> symbol
|
||||
return true;
|
||||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
function isNumberKey(evt)
|
||||
{
|
||||
var charCode = (evt.which) ? evt.which : evt.keyCode;
|
||||
if (charCode != 46 && charCode > 31
|
||||
&& (charCode < 48 || charCode > 57))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
// $(function() {
|
||||
// $('#MaterialCategory').change(function() {
|
||||
// var x = $(this).val();
|
||||
// alert(x);
|
||||
// $('#mchiddenfield').val(x);
|
||||
// });
|
||||
// });
|
||||
|
||||
function onlyAlphabets(evt) {
|
||||
var charCode;
|
||||
if (window.event)
|
||||
charCode = window.event.keyCode; //for IE
|
||||
else
|
||||
charCode = evt.which; //for firefox
|
||||
if (charCode == 32) //for <space> symbol
|
||||
return true;
|
||||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function changeTextBox() {
|
||||
//alert('changeTextBox entered');
|
||||
var x = document.getElementById("MaterialCategory");
|
||||
if(x.value=='Spares')
|
||||
{
|
||||
//alert('i am an if part');
|
||||
document.getElementById("Assetcode").disabled=false;
|
||||
document.getElementById("Costcenter").disabled=false;}
|
||||
else
|
||||
{
|
||||
//alert('i am a else part');
|
||||
document.getElementById("Assetcode").disabled=true;
|
||||
document.getElementById("Costcenter").disabled=true;}
|
||||
<style>
|
||||
.autocomplete-suggestion{
|
||||
cursor:pointer;
|
||||
background-color:White;
|
||||
/* background-color: darkgrey; */
|
||||
outline: 1px solid slategrey;
|
||||
}
|
||||
</script>
|
||||
</style>
|
||||
<script type="text/javascript" src="<?php echo base_url();?>assets/Autocomplete/jquery.autocomplete.js"></script>
|
||||
|
||||
<div class="content-wrapper" style="min-height: 537px;">
|
||||
<!-- Content Header (Page header) -->
|
||||
@ -208,11 +124,17 @@ function changeTextBox() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group autoSearch" id="mc">
|
||||
<label for="Matcate">Material Caterogy</label><font color="Red">*</font>
|
||||
<input type="text" class="form-control required " required id="MaterialCategory" name="MaterialCategory" value="<?php echo $MaterialCategory;?>" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
<!--<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="MaterialCategory">Material Category</label>
|
||||
<input type="text" class="form-control" readonly id="MaterialCategory" name="MaterialCategory" value="<?php echo $MaterialCategory;?>" onChange="changeTextBox();">
|
||||
<!-- <select class="form-control readonly select2" id="MaterialCategory" name="MaterialCategory" onChange="changeTextBox();">
|
||||
<!- <select class="form-control readonly select2" id="MaterialCategory" name="MaterialCategory" onChange="changeTextBox();">
|
||||
<option value="<?php echo $MaterialCategory;?> "><?php echo $MaterialCategory;?></option>
|
||||
<?php
|
||||
if(!empty($materialCategory))
|
||||
@ -226,9 +148,9 @@ function changeTextBox() {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
--> <!-- <input type='hidden' id='mchiddenfield' name='mchiddenfield' value=''> -->
|
||||
<!- <input type='hidden' id='mchiddenfield' name='mchiddenfield' value=''>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
@ -354,41 +276,132 @@ function changeTextBox() {
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?php
|
||||
$this->load->helper('form');
|
||||
$error = $this->session->flashdata('error');
|
||||
if($error)
|
||||
{
|
||||
?>
|
||||
<div class="alert alert-danger alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<?php echo $this->session->flashdata('error'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$success = $this->session->flashdata('success');
|
||||
if($success)
|
||||
{
|
||||
?>
|
||||
<div class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<?php echo $this->session->flashdata('success'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4"></div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<script src="<?php echo base_url(); ?>assets/js/editUser.js" type="text/javascript"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
//$("#MaterialType").select2();
|
||||
//$("#MaterialCategory").select2();
|
||||
$("#UOM").select2();
|
||||
$("#Assetcode").select2();
|
||||
$("#Costcenter").select2();
|
||||
$("#conversionfactorUOM").select2();
|
||||
|
||||
$('#MaterialCategory').autocomplete({
|
||||
|
||||
onSearchStart: function (query) {
|
||||
//alert(query);
|
||||
$('#MaterialCategory').autocomplete("option", "minLength", 0);
|
||||
},
|
||||
|
||||
serviceUrl: "<?php echo base_url();?>rawmaterialdetails/autocomplete",
|
||||
onSelect: function (suggestion) {
|
||||
|
||||
var data = suggestion.ConfigValue;
|
||||
var selectedvalue = $('input[name=MaterialCategory]').val();
|
||||
if(selectedvalue=='Spares')
|
||||
{
|
||||
//alert('good');
|
||||
$('#Assetcode').prop('disabled', false);
|
||||
$('#Costcenter').prop('disabled', false);
|
||||
}
|
||||
else{
|
||||
// // alert('bad');
|
||||
$('#Assetcode').prop('disabled', 'disabled');
|
||||
$('#Costcenter').prop('disabled', 'disabled');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var x = $("#MaterialCategory").val() == 'Spares';
|
||||
if(x)
|
||||
{
|
||||
document.getElementById("Assetcode").disabled=false;
|
||||
document.getElementById("Costcenter").disabled=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//alert('i am a else part');
|
||||
document.getElementById("Assetcode").disabled=true;
|
||||
document.getElementById("Costcenter").disabled=true;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
function onlyAlphabets(evt) {
|
||||
var charCode;
|
||||
if (window.event)
|
||||
charCode = window.event.keyCode; //for IE
|
||||
else
|
||||
charCode = evt.which; //for firefox
|
||||
if (charCode == 32) //for <space> symbol
|
||||
return true;
|
||||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
function isNumberKey(evt)
|
||||
{
|
||||
var charCode = (evt.which) ? evt.which : evt.keyCode;
|
||||
if (charCode != 46 && charCode > 31
|
||||
&& (charCode < 48 || charCode > 57))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
// $(function() {
|
||||
// $('#MaterialCategory').change(function() {
|
||||
// var x = $(this).val();
|
||||
// alert(x);
|
||||
// $('#mchiddenfield').val(x);
|
||||
// });
|
||||
// });
|
||||
|
||||
function onlyAlphabets(evt) {
|
||||
var charCode;
|
||||
if (window.event)
|
||||
charCode = window.event.keyCode; //for IE
|
||||
else
|
||||
charCode = evt.which; //for firefox
|
||||
if (charCode == 32) //for <space> symbol
|
||||
return true;
|
||||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||||
return false;
|
||||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// function changeTextBox() {
|
||||
// //alert('changeTextBox entered');
|
||||
// var x = document.getElementById("MaterialCategory");
|
||||
// if(x.value=='Spares')
|
||||
// {
|
||||
// //alert('i am an if part');
|
||||
// document.getElementById("Assetcode").disabled=false;
|
||||
// document.getElementById("Costcenter").disabled=false;}
|
||||
// else
|
||||
// {
|
||||
// //alert('i am a else part');
|
||||
// document.getElementById("Assetcode").disabled=true;
|
||||
// document.getElementById("Costcenter").disabled=true;}
|
||||
// }
|
||||
|
||||
$('#MaterialName').change(function() {
|
||||
|
||||
|
||||
1
assets/Autocomplete/countries.js
Normal file
1
assets/Autocomplete/countries.js
Normal file
@ -0,0 +1 @@
|
||||
var countries={AD:"Andorra",AE:"United Arab Emirates",AF:"Afghanistan",AG:"Antigua and Barbuda",AI:"Anguilla",AL:"Albania",AM:"Armenia",AN:"Netherlands Antilles",AO:"Angola",AQ:"Antarctica",AR:"Argentina",AS:"American Samoa",AT:"Austria",AU:"Australia",AW:"Aruba",AX:"Åland Islands",AZ:"Azerbaijan",BA:"Bosnia and Herzegovina",BB:"Barbados",BD:"Bangladesh",BE:"Belgium",BF:"Burkina Faso",BG:"Bulgaria",BH:"Bahrain",BI:"Burundi",BJ:"Benin",BL:"Saint Barthélemy",BM:"Bermuda",BN:"Brunei",BO:"Bolivia",BQ:"British Antarctic Territory",BR:"Brazil",BS:"Bahamas",BT:"Bhutan",BV:"Bouvet Island",BW:"Botswana",BY:"Belarus",BZ:"Belize",CA:"Canada",CC:"Cocos [Keeling] Islands",CD:"Congo - Kinshasa",CF:"Central African Republic",CG:"Congo - Brazzaville",CH:"Switzerland",CI:"Côte d’Ivoire",CK:"Cook Islands",CL:"Chile",CM:"Cameroon",CN:"China",CO:"Colombia",CR:"Costa Rica",CS:"Serbia and Montenegro",CT:"Canton and Enderbury Islands",CU:"Cuba",CV:"Cape Verde",CX:"Christmas Island",CY:"Cyprus",CZ:"Czech Republic",DD:"East Germany",DE:"Germany",DJ:"Djibouti",DK:"Denmark",DM:"Dominica",DO:"Dominican Republic",DZ:"Algeria",EC:"Ecuador",EE:"Estonia",EG:"Egypt",EH:"Western Sahara",ER:"Eritrea",ES:"Spain",ET:"Ethiopia",FI:"Finland",FJ:"Fiji",FK:"Falkland Islands",FM:"Micronesia",FO:"Faroe Islands",FQ:"French Southern and Antarctic Territories",FR:"France",FX:"Metropolitan France",GA:"Gabon",GB:"United Kingdom",GD:"Grenada",GE:"Georgia",GF:"French Guiana",GG:"Guernsey",GH:"Ghana",GI:"Gibraltar",GL:"Greenland",GM:"Gambia",GN:"Guinea",GP:"Guadeloupe",GQ:"Equatorial Guinea",GR:"Greece",GS:"South Georgia and the South Sandwich Islands",GT:"Guatemala",GU:"Guam",GW:"Guinea-Bissau",GY:"Guyana",HK:"Hong Kong SAR China",HM:"Heard Island and McDonald Islands",HN:"Honduras",HR:"Croatia",HT:"Haiti",HU:"Hungary",ID:"Indonesia",IE:"Ireland",IL:"Israel",IM:"Isle of Man",IN:"India",IO:"British Indian Ocean Territory",IQ:"Iraq",IR:"Iran",IS:"Iceland",IT:"Italy",JE:"Jersey",JM:"Jamaica",JO:"Jordan",JP:"Japan",JT:"Johnston Island",KE:"Kenya",KG:"Kyrgyzstan",KH:"Cambodia",KI:"Kiribati",KM:"Comoros",KN:"Saint Kitts and Nevis",KP:"North Korea",KR:"South Korea",KW:"Kuwait",KY:"Cayman Islands",KZ:"Kazakhstan",LA:"Laos",LB:"Lebanon",LC:"Saint Lucia",LI:"Liechtenstein",LK:"Sri Lanka",LR:"Liberia",LS:"Lesotho",LT:"Lithuania",LU:"Luxembourg",LV:"Latvia",LY:"Libya",MA:"Morocco",MC:"Monaco",MD:"Moldova",ME:"Montenegro",MF:"Saint Martin",MG:"Madagascar",MH:"Marshall Islands",MI:"Midway Islands",MK:"Macedonia",ML:"Mali",MM:"Myanmar [Burma]",MN:"Mongolia",MO:"Macau SAR China",MP:"Northern Mariana Islands",MQ:"Martinique",MR:"Mauritania",MS:"Montserrat",MT:"Malta",MU:"Mauritius",MV:"Maldives",MW:"Malawi",MX:"Mexico",MY:"Malaysia",MZ:"Mozambique",NA:"Namibia",NC:"New Caledonia",NE:"Niger",NF:"Norfolk Island",NG:"Nigeria",NI:"Nicaragua",NL:"Netherlands",NO:"Norway",NP:"Nepal",NQ:"Dronning Maud Land",NR:"Nauru",NT:"Neutral Zone",NU:"Niue",NZ:"New Zealand",OM:"Oman",PA:"Panama",PC:"Pacific Islands Trust Territory",PE:"Peru",PF:"French Polynesia",PG:"Papua New Guinea",PH:"Philippines",PK:"Pakistan",PL:"Poland",PM:"Saint Pierre and Miquelon",PN:"Pitcairn Islands",PR:"Puerto Rico",PS:"Palestinian Territories",PT:"Portugal",PU:"U.S. Miscellaneous Pacific Islands",PW:"Palau",PY:"Paraguay",PZ:"Panama Canal Zone",QA:"Qatar",RE:"Réunion",RO:"Romania",RS:"Serbia",RU:"Russia",RW:"Rwanda",SA:"Saudi Arabia",SB:"Solomon Islands",SC:"Seychelles",SD:"Sudan",SE:"Sweden",SG:"Singapore",SH:"Saint Helena",SI:"Slovenia",SJ:"Svalbard and Jan Mayen",SK:"Slovakia",SL:"Sierra Leone",SM:"San Marino",SN:"Senegal",SO:"Somalia",SR:"Suriname",ST:"São Tomé and Príncipe",SU:"Union of Soviet Socialist Republics",SV:"El Salvador",SY:"Syria",SZ:"Swaziland",TC:"Turks and Caicos Islands",TD:"Chad",TF:"French Southern Territories",TG:"Togo",TH:"Thailand",TJ:"Tajikistan",TK:"Tokelau",TL:"Timor-Leste",TM:"Turkmenistan",TN:"Tunisia",TO:"Tonga",TR:"Turkey",TT:"Trinidad and Tobago",TV:"Tuvalu",TW:"Taiwan",TZ:"Tanzania",UA:"Ukraine",UG:"Uganda",UM:"U.S. Minor Outlying Islands",US:"United States",UY:"Uruguay",UZ:"Uzbekistan",VA:"Vatican City",VC:"Saint Vincent and the Grenadines",VD:"North Vietnam",VE:"Venezuela",VG:"British Virgin Islands",VI:"U.S. Virgin Islands",VN:"Vietnam",VU:"Vanuatu",WF:"Wallis and Futuna",WK:"Wake Island",WS:"Samoa",YD:"People's Democratic Republic of Yemen",YE:"Yemen",YT:"Mayotte",ZA:"South Africa",ZM:"Zambia",ZW:"Zimbabwe",ZZ:"Unknown or Invalid Region"}
|
||||
833
assets/Autocomplete/jquery.autocomplete.js
Normal file
833
assets/Autocomplete/jquery.autocomplete.js
Normal file
@ -0,0 +1,833 @@
|
||||
/**
|
||||
* Ajax Autocomplete for jQuery, version 1.2.9
|
||||
* (c) 2013 Tomas Kirda
|
||||
*
|
||||
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
|
||||
* For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
|
||||
*
|
||||
*/
|
||||
|
||||
/*jslint browser: true, white: true, plusplus: true */
|
||||
/*global define, window, document, jQuery */
|
||||
|
||||
// Expose plugin as an AMD module if AMD loader is present:
|
||||
(function (factory) {
|
||||
'use strict';
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
'use strict';
|
||||
|
||||
var
|
||||
utils = (function () {
|
||||
return {
|
||||
escapeRegExChars: function (value) {
|
||||
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||
},
|
||||
createNode: function (containerClass) {
|
||||
var div = document.createElement('div');
|
||||
div.className = containerClass;
|
||||
div.style.position = 'absolute';
|
||||
div.style.display = 'none';
|
||||
return div;
|
||||
}
|
||||
};
|
||||
}()),
|
||||
|
||||
keys = {
|
||||
ESC: 27,
|
||||
TAB: 9,
|
||||
RETURN: 13,
|
||||
LEFT: 37,
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
DOWN: 40
|
||||
};
|
||||
|
||||
function Autocomplete(el, options) {
|
||||
var noop = function () { },
|
||||
that = this,
|
||||
defaults = {
|
||||
autoSelectFirst: false,
|
||||
appendTo: 'body',
|
||||
serviceUrl: null,
|
||||
lookup: null,
|
||||
onSelect: null,
|
||||
width: 'auto',
|
||||
minChars: 1,
|
||||
maxHeight: 300,
|
||||
deferRequestBy: 0,
|
||||
params: {},
|
||||
formatResult: Autocomplete.formatResult,
|
||||
delimiter: null,
|
||||
zIndex: 9999,
|
||||
type: 'GET',
|
||||
noCache: false,
|
||||
onSearchStart: noop,
|
||||
onSearchComplete: noop,
|
||||
onSearchError: noop,
|
||||
containerClass: 'autocomplete-suggestions',
|
||||
tabDisabled: false,
|
||||
dataType: 'text',
|
||||
currentRequest: null,
|
||||
triggerSelectOnValidInput: true,
|
||||
preventBadQueries: true,
|
||||
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
|
||||
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
|
||||
},
|
||||
paramName: 'query',
|
||||
transformResult: function (response) {
|
||||
return typeof response === 'string' ? $.parseJSON(response) : response;
|
||||
}
|
||||
};
|
||||
|
||||
// Shared variables:
|
||||
that.element = el;
|
||||
that.el = $(el);
|
||||
that.suggestions = [];
|
||||
that.badQueries = [];
|
||||
that.selectedIndex = -1;
|
||||
that.currentValue = that.element.value;
|
||||
that.intervalId = 0;
|
||||
that.cachedResponse = {};
|
||||
that.onChangeInterval = null;
|
||||
that.onChange = null;
|
||||
that.isLocal = false;
|
||||
that.suggestionsContainer = null;
|
||||
that.options = $.extend({}, defaults, options);
|
||||
that.classes = {
|
||||
selected: 'autocomplete-selected',
|
||||
suggestion: 'autocomplete-suggestion'
|
||||
};
|
||||
that.hint = null;
|
||||
that.hintValue = '';
|
||||
that.selection = null;
|
||||
|
||||
// Initialize and set options:
|
||||
that.initialize();
|
||||
that.setOptions(options);
|
||||
}
|
||||
|
||||
Autocomplete.utils = utils;
|
||||
|
||||
$.Autocomplete = Autocomplete;
|
||||
|
||||
Autocomplete.formatResult = function (suggestion, currentValue) {
|
||||
var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';
|
||||
|
||||
return suggestion.value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
|
||||
};
|
||||
|
||||
Autocomplete.prototype = {
|
||||
|
||||
killerFn: null,
|
||||
|
||||
initialize: function () {
|
||||
var that = this,
|
||||
suggestionSelector = '.' + that.classes.suggestion,
|
||||
selected = that.classes.selected,
|
||||
options = that.options,
|
||||
container;
|
||||
|
||||
// Remove autocomplete attribute to prevent native suggestions:
|
||||
that.element.setAttribute('autocomplete', 'off');
|
||||
|
||||
that.killerFn = function (e) {
|
||||
if ($(e.target).closest('.' + that.options.containerClass).length === 0) {
|
||||
that.killSuggestions();
|
||||
that.disableKillerFn();
|
||||
}
|
||||
};
|
||||
|
||||
that.suggestionsContainer = Autocomplete.utils.createNode(options.containerClass);
|
||||
|
||||
container = $(that.suggestionsContainer);
|
||||
|
||||
container.appendTo(options.appendTo);
|
||||
|
||||
// Only set width if it was provided:
|
||||
if (options.width !== 'auto') {
|
||||
container.width(options.width);
|
||||
}
|
||||
|
||||
// Listen for mouse over event on suggestions list:
|
||||
container.on('mouseover.autocomplete', suggestionSelector, function () {
|
||||
that.activate($(this).data('index'));
|
||||
});
|
||||
|
||||
// Deselect active element when mouse leaves suggestions container:
|
||||
container.on('mouseout.autocomplete', function () {
|
||||
that.selectedIndex = -1;
|
||||
container.children('.' + selected).removeClass(selected);
|
||||
});
|
||||
|
||||
// Listen for click event on suggestions list:
|
||||
container.on('click.autocomplete', suggestionSelector, function () {
|
||||
that.select($(this).data('index'));
|
||||
});
|
||||
|
||||
that.fixPosition();
|
||||
|
||||
that.fixPositionCapture = function () {
|
||||
if (that.visible) {
|
||||
that.fixPosition();
|
||||
}
|
||||
};
|
||||
|
||||
$(window).on('resize.autocomplete', that.fixPositionCapture);
|
||||
|
||||
that.el.on('keydown.autocomplete', function (e) { that.onKeyPress(e); });
|
||||
that.el.on('keyup.autocomplete', function (e) { that.onKeyUp(e); });
|
||||
that.el.on('blur.autocomplete', function () { that.onBlur(); });
|
||||
that.el.on('focus.autocomplete', function () { that.onFocus(); });
|
||||
that.el.on('change.autocomplete', function (e) { that.onKeyUp(e); });
|
||||
},
|
||||
|
||||
onFocus: function () {
|
||||
var that = this;
|
||||
that.fixPosition();
|
||||
if (that.options.minChars <= that.el.val().length) {
|
||||
that.onValueChange();
|
||||
}
|
||||
},
|
||||
|
||||
onBlur: function () {
|
||||
this.enableKillerFn();
|
||||
},
|
||||
|
||||
setOptions: function (suppliedOptions) {
|
||||
var that = this,
|
||||
options = that.options;
|
||||
|
||||
$.extend(options, suppliedOptions);
|
||||
|
||||
that.isLocal = $.isArray(options.lookup);
|
||||
|
||||
if (that.isLocal) {
|
||||
options.lookup = that.verifySuggestionsFormat(options.lookup);
|
||||
}
|
||||
|
||||
// Adjust height, width and z-index:
|
||||
$(that.suggestionsContainer).css({
|
||||
'max-height': options.maxHeight + 'px',
|
||||
'width': options.width + 'px',
|
||||
'z-index': options.zIndex
|
||||
});
|
||||
},
|
||||
|
||||
clearCache: function () {
|
||||
this.cachedResponse = {};
|
||||
this.badQueries = [];
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
this.clearCache();
|
||||
this.currentValue = '';
|
||||
this.suggestions = [];
|
||||
},
|
||||
|
||||
disable: function () {
|
||||
var that = this;
|
||||
that.disabled = true;
|
||||
if (that.currentRequest) {
|
||||
that.currentRequest.abort();
|
||||
}
|
||||
},
|
||||
|
||||
enable: function () {
|
||||
this.disabled = false;
|
||||
},
|
||||
|
||||
fixPosition: function () {
|
||||
var that = this,
|
||||
offset,
|
||||
styles;
|
||||
|
||||
// Don't adjsut position if custom container has been specified:
|
||||
if (that.options.appendTo !== 'body') {
|
||||
return;
|
||||
}
|
||||
|
||||
offset = that.el.offset();
|
||||
|
||||
styles = {
|
||||
top: (offset.top + that.el.outerHeight()) + 'px',
|
||||
left: offset.left + 'px'
|
||||
};
|
||||
|
||||
if (that.options.width === 'auto') {
|
||||
styles.width = (that.el.outerWidth() - 2) + 'px';
|
||||
}
|
||||
|
||||
$(that.suggestionsContainer).css(styles);
|
||||
},
|
||||
|
||||
enableKillerFn: function () {
|
||||
var that = this;
|
||||
$(document).on('click.autocomplete', that.killerFn);
|
||||
},
|
||||
|
||||
disableKillerFn: function () {
|
||||
var that = this;
|
||||
$(document).off('click.autocomplete', that.killerFn);
|
||||
},
|
||||
|
||||
killSuggestions: function () {
|
||||
var that = this;
|
||||
that.stopKillSuggestions();
|
||||
that.intervalId = window.setInterval(function () {
|
||||
that.hide();
|
||||
that.stopKillSuggestions();
|
||||
}, 50);
|
||||
},
|
||||
|
||||
stopKillSuggestions: function () {
|
||||
window.clearInterval(this.intervalId);
|
||||
},
|
||||
|
||||
isCursorAtEnd: function () {
|
||||
var that = this,
|
||||
valLength = that.el.val().length,
|
||||
selectionStart = that.element.selectionStart,
|
||||
range;
|
||||
|
||||
if (typeof selectionStart === 'number') {
|
||||
return selectionStart === valLength;
|
||||
}
|
||||
if (document.selection) {
|
||||
range = document.selection.createRange();
|
||||
range.moveStart('character', -valLength);
|
||||
return valLength === range.text.length;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
onKeyPress: function (e) {
|
||||
var that = this;
|
||||
|
||||
// If suggestions are hidden and user presses arrow down, display suggestions:
|
||||
if (!that.disabled && !that.visible && e.which === keys.DOWN && that.currentValue) {
|
||||
that.suggest();
|
||||
return;
|
||||
}
|
||||
|
||||
if (that.disabled || !that.visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.which) {
|
||||
case keys.ESC:
|
||||
that.el.val(that.currentValue);
|
||||
that.hide();
|
||||
break;
|
||||
case keys.RIGHT:
|
||||
if (that.hint && that.options.onHint && that.isCursorAtEnd()) {
|
||||
that.selectHint();
|
||||
break;
|
||||
}
|
||||
return;
|
||||
case keys.TAB:
|
||||
if (that.hint && that.options.onHint) {
|
||||
that.selectHint();
|
||||
return;
|
||||
}
|
||||
// Fall through to RETURN
|
||||
case keys.RETURN:
|
||||
if (that.selectedIndex === -1) {
|
||||
that.hide();
|
||||
return;
|
||||
}
|
||||
that.select(that.selectedIndex);
|
||||
if (e.which === keys.TAB && that.options.tabDisabled === false) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case keys.UP:
|
||||
that.moveUp();
|
||||
break;
|
||||
case keys.DOWN:
|
||||
that.moveDown();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// Cancel event if function did not return:
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
},
|
||||
|
||||
onKeyUp: function (e) {
|
||||
var that = this;
|
||||
|
||||
if (that.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.which) {
|
||||
case keys.UP:
|
||||
case keys.DOWN:
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(that.onChangeInterval);
|
||||
|
||||
if (that.currentValue !== that.el.val()) {
|
||||
that.findBestHint();
|
||||
if (that.options.deferRequestBy > 0) {
|
||||
// Defer lookup in case when value changes very quickly:
|
||||
that.onChangeInterval = setInterval(function () {
|
||||
that.onValueChange();
|
||||
}, that.options.deferRequestBy);
|
||||
} else {
|
||||
that.onValueChange();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onValueChange: function () {
|
||||
var that = this,
|
||||
options = that.options,
|
||||
value = that.el.val(),
|
||||
query = that.getQuery(value),
|
||||
index;
|
||||
|
||||
if (that.selection) {
|
||||
that.selection = null;
|
||||
(options.onInvalidateSelection || $.noop).call(that.element);
|
||||
}
|
||||
|
||||
clearInterval(that.onChangeInterval);
|
||||
that.currentValue = value;
|
||||
that.selectedIndex = -1;
|
||||
|
||||
// Check existing suggestion for the match before proceeding:
|
||||
if (options.triggerSelectOnValidInput) {
|
||||
index = that.findSuggestionIndex(query);
|
||||
if (index !== -1) {
|
||||
that.select(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (query.length < options.minChars) {
|
||||
that.hide();
|
||||
} else {
|
||||
that.getSuggestions(query);
|
||||
}
|
||||
},
|
||||
|
||||
findSuggestionIndex: function (query) {
|
||||
var that = this,
|
||||
index = -1,
|
||||
queryLowerCase = query.toLowerCase();
|
||||
|
||||
$.each(that.suggestions, function (i, suggestion) {
|
||||
if (suggestion.value.toLowerCase() === queryLowerCase) {
|
||||
index = i;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return index;
|
||||
},
|
||||
|
||||
getQuery: function (value) {
|
||||
var delimiter = this.options.delimiter,
|
||||
parts;
|
||||
|
||||
if (!delimiter) {
|
||||
return value;
|
||||
}
|
||||
parts = value.split(delimiter);
|
||||
return $.trim(parts[parts.length - 1]);
|
||||
},
|
||||
|
||||
getSuggestionsLocal: function (query) {
|
||||
var that = this,
|
||||
options = that.options,
|
||||
queryLowerCase = query.toLowerCase(),
|
||||
filter = options.lookupFilter,
|
||||
limit = parseInt(options.lookupLimit, 10),
|
||||
data;
|
||||
|
||||
data = {
|
||||
suggestions: $.grep(options.lookup, function (suggestion) {
|
||||
return filter(suggestion, query, queryLowerCase);
|
||||
})
|
||||
};
|
||||
|
||||
if (limit && data.suggestions.length > limit) {
|
||||
data.suggestions = data.suggestions.slice(0, limit);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
getSuggestions: function (q) {
|
||||
var response,
|
||||
that = this,
|
||||
options = that.options,
|
||||
serviceUrl = options.serviceUrl,
|
||||
params,
|
||||
cacheKey;
|
||||
|
||||
options.params[options.paramName] = q;
|
||||
params = options.ignoreParams ? null : options.params;
|
||||
|
||||
if (that.isLocal) {
|
||||
response = that.getSuggestionsLocal(q);
|
||||
} else {
|
||||
if ($.isFunction(serviceUrl)) {
|
||||
serviceUrl = serviceUrl.call(that.element, q);
|
||||
}
|
||||
cacheKey = serviceUrl + '?' + $.param(params || {});
|
||||
response = that.cachedResponse[cacheKey];
|
||||
}
|
||||
|
||||
if (response && $.isArray(response.suggestions)) {
|
||||
that.suggestions = response.suggestions;
|
||||
that.suggest();
|
||||
} else if (!that.isBadQuery(q)) {
|
||||
if (options.onSearchStart.call(that.element, options.params) === false) {
|
||||
return;
|
||||
}
|
||||
if (that.currentRequest) {
|
||||
that.currentRequest.abort();
|
||||
}
|
||||
that.currentRequest = $.ajax({
|
||||
url: serviceUrl,
|
||||
data: params,
|
||||
type: options.type,
|
||||
dataType: options.dataType
|
||||
}).done(function (data) {
|
||||
var result;
|
||||
that.currentRequest = null;
|
||||
result = options.transformResult(data);
|
||||
that.processResponse(result, q, cacheKey);
|
||||
options.onSearchComplete.call(that.element, q, result.suggestions);
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
isBadQuery: function (q) {
|
||||
if (!this.options.preventBadQueries){
|
||||
return false;
|
||||
}
|
||||
|
||||
var badQueries = this.badQueries,
|
||||
i = badQueries.length;
|
||||
|
||||
while (i--) {
|
||||
if (q.indexOf(badQueries[i]) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
var that = this;
|
||||
that.visible = false;
|
||||
that.selectedIndex = -1;
|
||||
$(that.suggestionsContainer).hide();
|
||||
that.signalHint(null);
|
||||
},
|
||||
|
||||
suggest: function () {
|
||||
if (this.suggestions.length === 0) {
|
||||
this.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
var that = this,
|
||||
options = that.options,
|
||||
formatResult = options.formatResult,
|
||||
value = that.getQuery(that.currentValue),
|
||||
className = that.classes.suggestion,
|
||||
classSelected = that.classes.selected,
|
||||
container = $(that.suggestionsContainer),
|
||||
beforeRender = options.beforeRender,
|
||||
html = '',
|
||||
index,
|
||||
width;
|
||||
|
||||
if (options.triggerSelectOnValidInput) {
|
||||
index = that.findSuggestionIndex(value);
|
||||
if (index !== -1) {
|
||||
that.select(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Build suggestions inner HTML:
|
||||
$.each(that.suggestions, function (i, suggestion) {
|
||||
html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value) + '</div>';
|
||||
});
|
||||
|
||||
// If width is auto, adjust width before displaying suggestions,
|
||||
// because if instance was created before input had width, it will be zero.
|
||||
// Also it adjusts if input width has changed.
|
||||
// -2px to account for suggestions border.
|
||||
if (options.width === 'auto') {
|
||||
width = that.el.outerWidth() - 2;
|
||||
container.width(width > 0 ? width : 300);
|
||||
}
|
||||
|
||||
container.html(html);
|
||||
|
||||
// Select first value by default:
|
||||
if (options.autoSelectFirst) {
|
||||
that.selectedIndex = 0;
|
||||
container.children().first().addClass(classSelected);
|
||||
}
|
||||
|
||||
if ($.isFunction(beforeRender)) {
|
||||
beforeRender.call(that.element, container);
|
||||
}
|
||||
|
||||
container.show();
|
||||
that.visible = true;
|
||||
|
||||
that.findBestHint();
|
||||
},
|
||||
|
||||
findBestHint: function () {
|
||||
var that = this,
|
||||
value = that.el.val().toLowerCase(),
|
||||
bestMatch = null;
|
||||
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.each(that.suggestions, function (i, suggestion) {
|
||||
var foundMatch = suggestion.value.toLowerCase().indexOf(value) === 0;
|
||||
if (foundMatch) {
|
||||
bestMatch = suggestion;
|
||||
}
|
||||
return !foundMatch;
|
||||
});
|
||||
|
||||
that.signalHint(bestMatch);
|
||||
},
|
||||
|
||||
signalHint: function (suggestion) {
|
||||
var hintValue = '',
|
||||
that = this;
|
||||
if (suggestion) {
|
||||
hintValue = that.currentValue + suggestion.value.substr(that.currentValue.length);
|
||||
}
|
||||
if (that.hintValue !== hintValue) {
|
||||
that.hintValue = hintValue;
|
||||
that.hint = suggestion;
|
||||
(this.options.onHint || $.noop)(hintValue);
|
||||
}
|
||||
},
|
||||
|
||||
verifySuggestionsFormat: function (suggestions) {
|
||||
// If suggestions is string array, convert them to supported format:
|
||||
if (suggestions.length && typeof suggestions[0] === 'string') {
|
||||
return $.map(suggestions, function (value) {
|
||||
return { value: value, data: null };
|
||||
});
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
},
|
||||
|
||||
processResponse: function (result, originalQuery, cacheKey) {
|
||||
var that = this,
|
||||
options = that.options;
|
||||
|
||||
result.suggestions = that.verifySuggestionsFormat(result.suggestions);
|
||||
|
||||
// Cache results if cache is not disabled:
|
||||
if (!options.noCache) {
|
||||
that.cachedResponse[cacheKey] = result;
|
||||
if (options.preventBadQueries && result.suggestions.length === 0) {
|
||||
that.badQueries.push(originalQuery);
|
||||
}
|
||||
}
|
||||
|
||||
// Return if originalQuery is not matching current query:
|
||||
if (originalQuery !== that.getQuery(that.currentValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
that.suggestions = result.suggestions;
|
||||
that.suggest();
|
||||
},
|
||||
|
||||
activate: function (index) {
|
||||
var that = this,
|
||||
activeItem,
|
||||
selected = that.classes.selected,
|
||||
container = $(that.suggestionsContainer),
|
||||
children = container.children();
|
||||
|
||||
container.children('.' + selected).removeClass(selected);
|
||||
|
||||
that.selectedIndex = index;
|
||||
|
||||
if (that.selectedIndex !== -1 && children.length > that.selectedIndex) {
|
||||
activeItem = children.get(that.selectedIndex);
|
||||
$(activeItem).addClass(selected);
|
||||
return activeItem;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
selectHint: function () {
|
||||
var that = this,
|
||||
i = $.inArray(that.hint, that.suggestions);
|
||||
|
||||
that.select(i);
|
||||
},
|
||||
|
||||
select: function (i) {
|
||||
var that = this;
|
||||
that.hide();
|
||||
that.onSelect(i);
|
||||
},
|
||||
|
||||
moveUp: function () {
|
||||
var that = this;
|
||||
|
||||
if (that.selectedIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (that.selectedIndex === 0) {
|
||||
$(that.suggestionsContainer).children().first().removeClass(that.classes.selected);
|
||||
that.selectedIndex = -1;
|
||||
that.el.val(that.currentValue);
|
||||
that.findBestHint();
|
||||
return;
|
||||
}
|
||||
|
||||
that.adjustScroll(that.selectedIndex - 1);
|
||||
},
|
||||
|
||||
moveDown: function () {
|
||||
var that = this;
|
||||
|
||||
if (that.selectedIndex === (that.suggestions.length - 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
that.adjustScroll(that.selectedIndex + 1);
|
||||
},
|
||||
|
||||
adjustScroll: function (index) {
|
||||
var that = this,
|
||||
activeItem = that.activate(index),
|
||||
offsetTop,
|
||||
upperBound,
|
||||
lowerBound,
|
||||
heightDelta = 25;
|
||||
|
||||
if (!activeItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
offsetTop = activeItem.offsetTop;
|
||||
upperBound = $(that.suggestionsContainer).scrollTop();
|
||||
lowerBound = upperBound + that.options.maxHeight - heightDelta;
|
||||
|
||||
if (offsetTop < upperBound) {
|
||||
$(that.suggestionsContainer).scrollTop(offsetTop);
|
||||
} else if (offsetTop > lowerBound) {
|
||||
$(that.suggestionsContainer).scrollTop(offsetTop - that.options.maxHeight + heightDelta);
|
||||
}
|
||||
|
||||
that.el.val(that.getValue(that.suggestions[index].value));
|
||||
that.signalHint(null);
|
||||
},
|
||||
|
||||
onSelect: function (index) {
|
||||
var that = this,
|
||||
onSelectCallback = that.options.onSelect,
|
||||
suggestion = that.suggestions[index];
|
||||
|
||||
that.currentValue = that.getValue(suggestion.value);
|
||||
|
||||
if (that.currentValue !== that.el.val()) {
|
||||
that.el.val(that.currentValue);
|
||||
}
|
||||
|
||||
that.signalHint(null);
|
||||
that.suggestions = [];
|
||||
that.selection = suggestion;
|
||||
|
||||
if ($.isFunction(onSelectCallback)) {
|
||||
onSelectCallback.call(that.element, suggestion);
|
||||
}
|
||||
},
|
||||
|
||||
getValue: function (value) {
|
||||
var that = this,
|
||||
delimiter = that.options.delimiter,
|
||||
currentValue,
|
||||
parts;
|
||||
|
||||
if (!delimiter) {
|
||||
return value;
|
||||
}
|
||||
|
||||
currentValue = that.currentValue;
|
||||
parts = currentValue.split(delimiter);
|
||||
|
||||
if (parts.length === 1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return currentValue.substr(0, currentValue.length - parts[parts.length - 1].length) + value;
|
||||
},
|
||||
|
||||
dispose: function () {
|
||||
var that = this;
|
||||
that.el.off('.autocomplete').removeData('autocomplete');
|
||||
that.disableKillerFn();
|
||||
$(window).off('resize.autocomplete', that.fixPositionCapture);
|
||||
$(that.suggestionsContainer).remove();
|
||||
}
|
||||
};
|
||||
|
||||
// Create chainable jQuery plugin:
|
||||
$.fn.autocomplete = function (options, args) {
|
||||
var dataKey = 'autocomplete';
|
||||
// If function invoked without argument return
|
||||
// instance of the first matched element:
|
||||
if (arguments.length === 0) {
|
||||
return this.first().data(dataKey);
|
||||
}
|
||||
|
||||
return this.each(function () {
|
||||
var inputElement = $(this),
|
||||
instance = inputElement.data(dataKey);
|
||||
|
||||
if (typeof options === 'string') {
|
||||
if (instance && typeof instance[options] === 'function') {
|
||||
instance[options](args);
|
||||
}
|
||||
} else {
|
||||
// If instance already exists, destroy it:
|
||||
if (instance && instance.dispose) {
|
||||
instance.dispose();
|
||||
}
|
||||
instance = new Autocomplete(this, options);
|
||||
inputElement.data(dataKey, instance);
|
||||
}
|
||||
});
|
||||
};
|
||||
}));
|
||||
Loading…
Reference in New Issue
Block a user