| Current Path : /home/zieirix/www/plugins/system/jaosmap/layouts/ |
| Current File : /home/zieirix/www/plugins/system/jaosmap/layouts/items.php |
<?php
/**
* ------------------------------------------------------------------------
* JA Open Street Map
* ------------------------------------------------------------------------
* Copyright (C) 2004-2018 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
* @license - Copyrighted Commercial Software
* Author: J.O.O.M Solutions Co., Ltd
* Websites: http://www.joomlart.com - http://www.joomlancers.com
* This file may not be redistributed in whole or significant part.
* ------------------------------------------------------------------------
*/
defined('JPATH_BASE') or die;
$field = $displayData['field'];
$attributes = $displayData['attributes'];
$items = $displayData['items'];
//$value = htmlspecialchars($field->value, ENT_COMPAT, 'UTF-8');
$value = $field->value;
$id = $field->id;
$name = $field->name;
$hideLabel = (bool) $attributes['hiddenLabel'];
$label = JText::_((string) $attributes['label']);
$desc = JText::_((string) $attributes['description']);
$width = 90/count ($items);
$field_items = array();
if(is_array($value) && count($value)) {
foreach($value as $f_name => $f_items) {
if(is_array($f_items) && (count($f_items) > count($field_items))) {
$field_items = $f_items;
}
}
}
if(!count($field_items)) {
$field_items = array(0 => null);
}
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#get_loc_loading').hide();
jQuery('a#getLocation').on('click', function(e) {
let availAddress = {}; // {index of td : value}
jQuery('table.jalist tbody tr').each(function(i) {
let address = jQuery(this).find('td').eq(0).find('input').val();
let _lat = jQuery(this).find('td').eq(1).find('input').val();
let _long = jQuery(this).find('td').eq(2).find('input').val();
if (_lat == '' || _long == '') { // only if no lat long.
if (address != '') { // only if address available.
availAddress[i] = address;
}
}
});
if (Object.keys(availAddress).length) {
jQuery('#get_loc_loading').show();
jQuery.ajax({
type: "POST",
dataType: 'json',
method: "POST",
url: '<?php echo JUri::root(); ?>',
data: {
'option' : 'com_ajax',
'plugin' : 'jaosmap',
'address': availAddress,
'group' : 'system',
'format' : 'json'
},
success: function(response) {
jQuery('#get_loc_loading').hide();
let addr = response.data;
if (addr.length) {
let address = addr[0];
for (let ad in address) {
jQuery('table.jalist tbody tr').eq(ad).find('input').eq(1).val(address[ad][0]);
jQuery('table.jalist tbody tr').eq(ad).find('input').eq(2).val(address[ad][1]);
}
}
},
error: function(data, text) {
jQuery('#get_loc_loading').hide();
alert('AJAX ERROR');
}
});
}
e.preventDefault();
return false;
});
});
</script>
<p>
<a id="getLocation" class="btn" href="#">
Get Lat Long By Location.
</a>
<span id="get_loc_loading">Getting Location</span>
</p>
<div class="jaacm-list <?php echo $id ?>" data-index="<?php echo count($field_items); ?>">
<?php if ($hideLabel): ?>
<h4><?php echo $label ?></h4>
<p><?php echo $desc ?></p>
<?php endif ?>
<table class="jalist" width="100%">
<thead>
<tr>
<?php foreach ($items as $item) : ?>
<th>
<?php echo $item->getLabel() ?>
</th>
<?php endforeach ?>
<th> </th>
</tr>
</thead>
<tbody>
<?php $cnt = 0; ?>
<?php foreach($field_items as $index => $v): ?>
<tr class="<?php if(!$cnt) echo 'first'; ?>">
<?php foreach ($items as $_item) :
$item = clone $_item;
//$item->id .= '_'.$cnt;
$item->value = (isset($value[$item->fieldname][$index]) ? $value[$item->fieldname][$index] : '');
if($item->type == 'Calendar') {
$item->class = ($field->class) ? $field->class . ' type-calendar' : 'type-calendar';
}
$input = $item->getInput();
if($item->type == 'Calendar') {
if($cnt == 0) {
$input = str_replace(array($item->name), array($item->name.'['.$cnt.']'), $input);
} else {
$input = str_replace(array($item->name, $item->id), array($item->name.'['.$cnt.']', $item->id.'_'.$cnt), $input);
JHtml::_('calendar', $item->value, $item->name.'['.$cnt.']', $item->id.'_'.$cnt);
}
} else {
$input = str_replace(array($item->name, $item->id), array($item->name.'['.$cnt.']', $item->id.'_'.$cnt), $input);
}
?>
<td>
<?php echo $input; ?>
</td>
<?php endforeach ?>
<td>
<span class="btn action btn-clone" data-action="clone_row" title="<?php echo JText::_('JTOOLBAR_DUPLICATE'); ?>"><i><?php echo JText::_('JTOOLBAR_DUPLICATE'); ?></i></span>
<span class="btn action btn-delete" data-action="delete_row" title="<?php echo JText::_('JTOOLBAR_REMOVE'); ?>"><i><?php echo JText::_('JTOOLBAR_REMOVE'); ?></i></span>
</td>
</tr>
<?php $cnt++; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
<script type="text/javascript">
jQuery('.<?php echo $id ?>').jalist();
</script>