Revize 2376
Přidáno uživatelem David Raška před asi 10 roky(ů)
freenetis/branches/addresses/application/controllers/json.php | ||
---|---|---|
}
|
||
else
|
||
{
|
||
json_encode(array());
|
||
echo json_encode(array());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
json_encode(array());
|
||
echo json_encode(array());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Validates address point
|
||
*
|
||
* @author David Raška
|
||
*/
|
||
public function validate_address()
|
||
{
|
||
if (Address_points_Controller::is_address_point_server_active())
|
||
{
|
||
$curl = new Curl_HTTP_Client();
|
||
$result = $curl->fetch_url(Settings::get('address_point_url').server::query_string().'&mode=validate');
|
||
|
||
if ($curl->get_http_response_code() == 200 && $result !== FALSE)
|
||
|
||
if ($result !== FALSE)
|
||
{
|
||
echo $result;
|
||
}
|
||
else
|
||
{
|
||
echo json_encode(array('state' => FALSE));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
echo json_encode(array('state' => FALSE));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Returns address point details of given ID
|
||
*
|
||
* @author David Raška
|
||
*/
|
||
public function get_named_address_point()
|
||
{
|
||
$id = (int) $this->input->get('id');
|
freenetis/branches/addresses/application/views/js/base.php | ||
---|---|---|
});
|
||
|
||
// replace jQuery validator internal function
|
||
(function(showErrors) {
|
||
jQuery.validator.prototype.showErrors = function()
|
||
{
|
||
// call original function
|
||
var result = showErrors.apply(this, arguments);
|
||
|
||
// disable for #filter_form
|
||
if ($('input.error:first').parents('form').attr('id') !== 'filter_form')
|
||
{
|
||
$('input.error').each(function(){
|
||
// open group if element is in closed group
|
||
var input_tr = $(this).parent().parent();
|
||
if (input_tr.attr('class').indexOf('group-') !== -1 && input_tr.is(':hidden'))
|
||
{
|
||
input_tr.prevAll('.group_title:first').find('img').click();
|
||
}
|
||
});
|
||
}
|
||
return result;
|
||
};
|
||
})(jQuery.validator.prototype.showErrors);
|
||
(function(showErrors) {
|
||
jQuery.validator.prototype.showErrors = function()
|
||
{
|
||
// call original function
|
||
var result = showErrors.apply(this, arguments);
|
||
|
||
// disable for #filter_form
|
||
if ($('input.error:first').parents('form').attr('id') !== 'filter_form')
|
||
{
|
||
$('input.error').each(function(){
|
||
// open group if element is in closed group
|
||
var input_tr = $(this).parent().parent();
|
||
if (input_tr.attr('class').indexOf('group-') !== -1 && input_tr.is(':hidden'))
|
||
{
|
||
input_tr.prevAll('.group_title:first').find('img').click();
|
||
}
|
||
});
|
||
}
|
||
return result;
|
||
};
|
||
})(jQuery.validator.prototype.showErrors);
|
||
|
||
// validate all form and filters
|
||
$('.form, #filter_form').each(function() {
|
freenetis/branches/addresses/application/views/js/devices_add.php | ||
---|---|---|
{
|
||
return false;
|
||
}
|
||
// disable previous fields
|
||
disable_solid_fields();
|
||
// remove add buttons
|
||
$this.find('a.popup_link').remove();
|
||
// loader
|
||
$this.after('<?php echo html::image(array('src' => 'media/images/icons/animations/ajax-loader.gif', 'id' => 'da_loader', 'class' => 'ajax-loader')); ?>');
|
||
// build form
|
||
$.getJSON('<?php echo url_lang::base() ?>json/get_device_template_value', {
|
||
device_template_id: $('#device_template_id').val()
|
||
}, function (d)
|
||
|
||
var new_submit = function(d)
|
||
{
|
||
create_form_from_device_template(d);
|
||
// change button
|
||
$this.find('.submit').text('<?php echo __('Save') ?>');
|
||
// remove this action
|
||
$this.unbind('submit');
|
||
// add new
|
||
$this.submit(function ()
|
||
if ($('#town').length > 0 &&
|
||
!$('#allow_invalid').is(':checked') &&
|
||
(
|
||
typeof d.state === "undefined" ||
|
||
d.state.length === 0 ||
|
||
!d.state
|
||
))
|
||
{
|
||
if ($(this).validate().form())
|
||
$('#device_add_form').validate().showErrors({'street': '<?php echo __('Invalid address point.')?>'});
|
||
// hide loader
|
||
$('#da_loader').hide();
|
||
return false;
|
||
}
|
||
|
||
// disable previous fields
|
||
disable_solid_fields();
|
||
$('#named_address_point').parent().parent().remove();
|
||
// remove add buttons
|
||
$this.find('a.popup_link').remove();
|
||
// build form
|
||
$.getJSON('<?php echo url_lang::base() ?>json/get_device_template_value', {
|
||
device_template_id: $('#device_template_id').val()
|
||
}, function (d)
|
||
{
|
||
create_form_from_device_template(d);
|
||
// change button
|
||
$this.find('.submit').text('<?php echo __('Save') ?>');
|
||
// remove this action
|
||
$this.unbind('submit');
|
||
// add new
|
||
$this.submit(function ()
|
||
{
|
||
var isValid = true;
|
||
// check if all IP addresses are unique
|
||
var ips = [];
|
||
$.each($('input[name^="ip["]'), function (i, v)
|
||
if ($(this).validate().form())
|
||
{
|
||
var ip = trim($(v).val());
|
||
if (ip.length)
|
||
var isValid = true;
|
||
// check if all IP addresses are unique
|
||
var ips = [];
|
||
$.each($('input[name^="ip["]'), function (i, v)
|
||
{
|
||
if (ips.indexOf(ip) == -1)
|
||
var ip = trim($(v).val());
|
||
if (ip.length)
|
||
{
|
||
ips.push(trim($(v).val()));
|
||
}
|
||
else
|
||
{
|
||
alert('<?php echo __('Some IP addresses are same, please change them') ?>!');
|
||
isValid = false;
|
||
}
|
||
if (ips.indexOf(ip) == -1)
|
||
{
|
||
ips.push(trim($(v).val()));
|
||
}
|
||
else
|
||
{
|
||
alert('<?php echo __('Some IP addresses are same, please change them') ?>!');
|
||
isValid = false;
|
||
}
|
||
|
||
var gateway = $(v).parent().children('input[name^="gateway["]').val();
|
||
var gateway = $(v).parent().children('input[name^="gateway["]').val();
|
||
|
||
var subnet_id = $(v).parent().children('select[name^="subnet["]').val();
|
||
var subnet_id = $(v).parent().children('select[name^="subnet["]').val();
|
||
|
||
// subnet has already have gateway
|
||
if (in_array(subnet_id, gateway_subnets) && gateway == 1)
|
||
{
|
||
alert('<?php echo __('Subnet has already have gateway') ?>');
|
||
isValid = false;
|
||
// subnet has already have gateway
|
||
if (in_array(subnet_id, gateway_subnets) && gateway == 1)
|
||
{
|
||
alert('<?php echo __('Subnet has already have gateway') ?>');
|
||
isValid = false;
|
||
}
|
||
}
|
||
}
|
||
});
|
||
// check if all MAC addresses are unique
|
||
var macs = [];
|
||
$.each($('input[name^="mac["]'), function (i, v)
|
||
{
|
||
var mac = trim($(v).val());
|
||
if (mac.length)
|
||
});
|
||
// check if all MAC addresses are unique
|
||
var macs = [];
|
||
$.each($('input[name^="mac["]'), function (i, v)
|
||
{
|
||
if (macs.indexOf(mac) == -1)
|
||
var mac = trim($(v).val());
|
||
if (mac.length)
|
||
{
|
||
macs.push(trim($(v).val()));
|
||
if (macs.indexOf(mac) == -1)
|
||
{
|
||
macs.push(trim($(v).val()));
|
||
}
|
||
else
|
||
{
|
||
alert('<?php echo __('Some MAC addresses are same, please change them') ?>!');
|
||
isValid = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
alert('<?php echo __('Some MAC addresses are same, please change them') ?>!');
|
||
isValid = false;
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
// send form
|
||
return isValid;
|
||
}
|
||
// send form
|
||
return isValid;
|
||
}
|
||
|
||
return false;
|
||
return false;
|
||
});
|
||
// hide loader
|
||
$('#da_loader').hide();
|
||
});
|
||
// hide loader
|
||
$('#da_loader').hide();
|
||
});
|
||
}
|
||
|
||
// loader
|
||
$this.after('<?php echo html::image(array('src' => 'media/images/icons/animations/ajax-loader.gif', 'id' => 'da_loader', 'class' => 'ajax-loader')); ?>');
|
||
|
||
if ($('#town').length > 0)
|
||
{
|
||
$.getJSON('<?php echo url_lang::base() ?>json/validate_address', {
|
||
country: $('#country_id').val(),
|
||
town: $('#town').val(),
|
||
district: $('#district').val(),
|
||
street: $('#street').val(),
|
||
zip: $('#zip').val()
|
||
}, new_submit);
|
||
}
|
||
else
|
||
{
|
||
new_submit();
|
||
}
|
||
|
||
// do not send form
|
||
return false;
|
||
});
|
freenetis/branches/addresses/media/css/style.css | ||
---|---|---|
margin-left: 10px;
|
||
}
|
||
|
||
#town + b {
|
||
margin-right: 20px;
|
||
}
|
||
|
||
table.languages td {
|
||
padding-right: 5px;
|
||
}
|
Také k dispozici: Unified diff
Upravy:
- refs #855: Validace adresy hned po kliknuti na "Potvrdit" pri vytvareni noveho zarizeni