').parent().html().replace(re,'_'+keyNew+'$1'),
$nodeNew = $(html).css({'style':'display:none;'});
$nodeNew.find('input').each( function() {
var $node = $(this);
$node.val(null);
//wf2_addValidation(node);
//input_node_observe(node);
});
$nodeLast.after($nodeNew);
showHide($nodeNew, 'show');
GPSapp.edit.linkUpdate();
return false;
});
console.groupEnd();
return;
};
/**
*
*/
GPSapp.edit.linkUpdate = function() {
console.group('linkUpdate');
var keys = [],
keysEmpty = [],
removeSelector = '.link a.remove';
/*
var $node = $(this),
if ( $node.hasClass('img') ) {
$node.find('input[type=url]').before(GPSapp.strings.img_image).css({'marginLeft':'4px'});
$node.find('.field_container img').css({float:'left'}); // ,'marginLeft':'1em'
}
*/
$('.link input[type=url]').each( function() {
var key = $(this).prop('id').match(/(\d+)$/)[0];
if ( $(this).val() && $(this).val() != $(this).prop('placeholder') ) {
keys.push(key);
} else {
keysEmpty.push(key);
}
});
console.log('keys',keys);
console.log('keysEmpty',keysEmpty);
$('#geoEdit_link_keys').val(keys.join(','));
//
if ( keysEmpty.length ) {
showHide('#link_add', 'hide');
} else {
showHide('#link_add', 'show');
}
if ( keys.length + keysEmpty.length == 1 ) {
console.log('just one... don\'t show remove');
$(removeSelector).hide();
} else {
$(removeSelector).show();
}
console.groupEnd();
return;
};
/**
* set up event listeners for phone numbers
*/
GPSapp.edit.phoneObserve = function() {
$('body').on('change', 'input[type=tel]', GPSapp.edit.phoneUpdate);
$('body').on('click', '.phonenumber a.remove', function() {
console.log('removing phone', this);
var $nodeContainer = $(this).closest('.phonenumber');
showHide($nodeContainer, 'hide', null, function(){
console.log('removed',this);
$(this).remove();
GPSapp.edit.phoneUpdate();
});
return false;
});
return;
};
/**
*
*/
GPSapp.edit.phoneUpdate = function() {
console.group('phoneUpdate', this);
var keys = [],
keysEmpty = [],
removeSelector = '.phonenumber a.remove',
$nodeLast = $('.phonenumber').last(),
key = $nodeLast.find('input').prop('id').match(/(\d+)$/)[0],
keyNew = parseInt(key, 10) + 1,
re = new RegExp('_'+key+'([_"])','g'),
html,
$node,
$nodeNew;
// gather empty and non-empty keys
$('.phonenumber input[type=tel]').each( function() {
var key2 = $(this).prop('id').match(/(\d+)$/)[0];
if ( $(this).val() && $(this).val() != $(this).prop('placeholder') ) {
keys.push(key2);
} else {
keysEmpty.push(key2);
}
});
console.log('keys',keys);
console.log('keysEmpty',keysEmpty);
$('#geoEdit_phonenumber_keys').val(keys.join(','));
if ( keysEmpty.length === 0 ) {
$(removeSelector).show();
console.log('need to add an empty');
html = $nodeLast.clone().wrap('
').parent().html().replace(re,'_'+keyNew+'$1');
$nodeNew = $(html).css({'style':'display:none;'});
$nodeNew.find('input, select').each( function() {
$(this).val(null);
//wf2_addValidation(node);
//input_node_observe(node);
});
$nodeNew.find('.remove').hide();
$nodeNew.find('.bootstrap-select').remove();
/*
$nodeNew.find('.select2').select2({
// style: 'btn-secondary btn-sm'
});
*/
// $nodeNew.find(".input-group-btn .btn").addClass("btn-sm");
$nodeLast.after($nodeNew);
showHide($nodeNew, 'show');
} else if ( keysEmpty.length > 1 ) {
console.log('more than one empty!... remove the first');
$node = $('#geoEdit_phonenumber_'+keysEmpty[0]).closest('.phonenumber');
$node.find('a.remove').click();
} else if ( keys.length + keysEmpty.length == 1 ) {
console.log('just one... don\'t show remove');
$(removeSelector).hide();
} else {
console.log('show em all.. except for empty');
$.each(keys, function(key) {
$node = $('geoEdit_phonenumber_'+key).closest('.phonenumber');
$node.find('.remove').show();
});
}
console.groupEnd();
return;
};
/**
*
*/
GPSapp.edit.updateLocAjax = function(id,vals) {
console.log('updateLocAjax');
vals = $.extend({
action : 'edit',
id : id
},vals);
Ajax.Request(getSelfURL(), {
method : 'post',
parameters : vals,
onSuccess : function(t) {
var response = t.responseJSON,
success = response.get('success');
console.log('success',success);
if ( success ) {
GPSapp.edit.updateLoc(vals);
GPSapp.feedback.push('Marker updated');
} else {
GPSapp.map.resetMarkerPos(id);
}
},
onFailure : function(t) {
GPSapp.map.resetMarkerPos(id);
}
});
return;
};
/*
Updates TR with new values
if infoWindow is open, will update infoWindow
if location changes, will update marker pos
*/
GPSapp.edit.updateLoc = function(vals,closeModal) {
console.group('updateLoc');
//vals = $H(vals);
var id = vals.id,
cols = ['edit','sym','name & links','desc','address','city','state','postalcode','phonenumber'],
$node_tr = $('#loc_id_'+id),
$node_tds = $node_tr.children(),
$node_sym = $node_tr.find('.symbol'),
str_class = '',
a = [],
marker = GPSapp.map.markers[id],
pos_cur,
pos_new,
openInfoWindow = false
feedbackMsg = vals.remove !== undefined && vals.remove
? 'Marker removed'
: 'Marker updated';
console.log('vals',vals);
console.log('node_tds',$node_tds);
if ( closeModal ) {
parent.jQuery.colorbox.close()
parent.GPSapp.feedback.push(feedbackMsg);
}
$.each(vals, function(k,v) {
var i = cols.indexOf(k),
classname = null,
$node_td,
$node;
console.groupCollapsed(k);
console.log('v', v);
if ( k == 'sym' ) {
classname = 'symbol';
$node = $node_td.find('.'+classname);
// find & remove existing icon-geo-* class
a = $node.prop('class').split(/\s+/);
$.each(a, function(i,className) {
if ( className.indexOf('icon-geo-') === 0 ) {
$node.removeClass(className);
}
});
str_class = 'icon-geo-'+v.replace(/\W+/g,'');
$node.addClass('symbol '+str_class);
if ( $('#map_canvas').length ) {
console.log('update marker icon (if mapped)',v);
if ( marker ) {
marker.setIcon(GPSapp.map.getMarkerImage(v));
}
}
} else if ( i >= 0 ) {
$node_td = $node_tds.eq(i);
$node_td.html(v);
} else if ( $node_tr.find('.'+k) ) {
classname = k;
}
//console.log('classname', classname);
if ( classname ) {
$node = $node_tr.find('.'+classname);
$node.html(v);
}
console.groupEnd();
});
if ( $node_tr.hasClass('noGeoCode') ) {
$node_sym.prop('title','This location is unknown');
GPSapp.map.geoCodeQueue.add(id);
} else if ( $node_tr.hasClass('approx') ) {
$node_sym.prop('title','This location is approximate');
GPSapp.map.geoCodeQueue.add(id);
} else {
$node_sym.prop('title',$node_sym.text());
}
if ( vals.remove ) {
$node_tr.remove();
}
if ( $('#map_canvas') ) {
if ( vals.remove ) {
if ( GPSapp.map.clusterer && !marker.getMap() ) {
console.log('marker is in cluster');
GPSapp.map.clusterer.removeMarker(marker);
} else {
marker.setMap(null);
}
delete GPSapp.map.markers[id];
} else {
pos_cur = marker.getPosition();
if ( vals.lat && vals.lon && vals.lat != pos_cur.lat() && vals.lon != pos_cur.lng() ) {
console.log('updating position');
pos_new = new google.maps.LatLng(vals.lat, vals.lon);
marker.setPosition(pos_new);
}
if ( $node_tr.hasClass('noGeoCode') ) {
GPSapp.map.geoCodeQueue.add(id);
}
}
if ( GPSapp.map.infoWindowCur && GPSapp.map.infoWindowCur.id == id ) {
console.log('close infoWindow');
GPSapp.map.infoWindowCur.close();
openInfoWindow = !vals.remove;
}
if ( openInfoWindow ) {
GPSapp.map.infoWindowOpen(id);
}
}
console.groupEnd();
return;
};
/**
* Garmin
*/
/**
*
*/
GPSapp.sendTo = (function(module,GPSapp) {
return module;
}(GPSapp.sendTo || {}, GPSapp));
/**
* 3 Methods
* push : displays a message which will display for duration
* working : display a message which will remain until workingRemove is called
* workingRemove : remove a working message
*
* @param string container selector or node
* @param object opts options
*/
feedbackClass = function(container,opts) {
thisself = this;
this.$container = $(container);
this.opts = $.extend({
duration : 3000,
animate_working : true,
animation_id : 'status_ani_wrap'
},opts);
this.push = function(msg) {
var $nodeNew = this.createAndShow(msg);
//console.log('feedback.push',msg);
setTimeout(function() {
$nodeNew.slideUp({
complete : function() {
$nodeNew.remove();
if ( thisself.$container.children().length == 1 ) // just animation node
thisself.$container.hide();
}
});
}, this.opts['duration']);
};
this.working = function(msg,opts) {
console.log('feedback.working',msg,opts);
var $nodeNew = $();
opts = $.extend({
id : null
},opts);
$found = this.workingFind(msg, opts['id']);
if ( $found.length ) {
$found.html('
'+msg+'
');
return $found;
}
if ( this.opts['animate_working'] ) {
$( '#' + this.opts['animation_id'] ).show();
}
$nodeNew = this.createAndShow(msg)
.addClass('working');
if ( opts['id'] )
$nodeNew.prop('id',opts['id']);
$nodeNew.queue(function() {
var props = {
opacity:0
};
$(this).pulse(props,{
pulses : -1, // pulse indefinitely
duration : 1000
});
$(this).dequeue();
});
return $nodeNew;
};
this.workingRemove = function(msg,id) {
console.log('feedback.workingRemove',msg, id);
var $found = this.workingFind(msg, id);
$found.slideUp({
complete : function() {
$found.pulse('destroy')
.remove();
if ( thisself.opts['animate_working'] && !thisself.$container.find('.working').length )
$( '#' + thisself.opts['animation_id'] ).hide();
if ( thisself.$container.children().length == 1 ) // just animation node
thisself.$container.hide();
}
});
};
// private functions
this.workingFind = function(msg,id) {
//console.log('workingFind',msg,id);
var $found = $(),
stripped = '';
if ( id ) {
$found = $('#'+id);
} else {
stripped = $('
').html(msg).text();
this.$container.find('.working').each( function() {
var $node = $(this);
if ( stripped == $node.text() ) {
$found = $node;
return false; // break;
}
});
}
return $found;
};
this.createAndShow = function(msg) {
//console.log('createAndShow',msg);
var $nodeNew = $('
').html(msg).css({display:'none'});
if ( !this.$container.is(':visible') )
this.$container.show();
this.$container.append($nodeNew);
$nodeNew.queue(function(){
$(this).fadeIn(200).dequeue();
})
return $nodeNew;
};
};
/**
* http://jsoverson.github.io/jquery.pulse.js/
*/
(function(t,n){"use strict";var e={pulses:1,interval:0,returnDelay:0,duration:500};t.fn.pulse=function(u,r,a){var i="destroy"===u;return"function"==typeof r&&(a=r,r={}),r=t.extend({},e,r),r.interval>=0||(r.interval=0),r.returnDelay>=0||(r.returnDelay=0),r.duration>=0||(r.duration=500),r.pulses>=-1||(r.pulses=1),"function"!=typeof a&&(a=function(){}),this.each(function(){function e(){return s.data("pulse").stop?void 0:r.pulses>-1&&++c>r.pulses?a.apply(s):(s.animate(u,{duration:r.duration/2,complete:function(){n.setTimeout(function(){s.animate(l,{duration:r.duration/2,complete:function(){n.setTimeout(e,r.interval)}})},r.returnDelay)}}),void 0)}var o,s=t(this),l={},p=s.data("pulse")||{};p.stop=i,s.data("pulse",p);for(o in u)u.hasOwnProperty(o)&&(l[o]=s.css(o));var c=0;e()})}})(jQuery,window,document);function fieldTrigger(c){$(document).ready(function(){$.each(c,function(e,d){d=b(d);$(d.selector).change(function(f){a(d,f)});a(d)})});function a(f,e){var i=(typeof e=="undefined"),h=[],d=[],g=[];$(f.selector).each(function(j,k){var l=null;if($(k).is(":checkbox, :radio")){if($(k).is(":checked")){h.push($(k).val())}}else{if($(k).is("select")&&$(k).prop("multiple")){l=$(k).val();if(l===null){l=[]}h=$.unique($.merge(h,l))}else{h.push($(k).val())}}});if(f.always){d.push(f.always)}$(f.conditions).each(function(k,j){if($.inArray(j["if"],h)>-1){d.push(j.then);g.push(j["else"])}else{d.push(j["else"]);g.push(j.then)}});$(d).each(function(k,j){if(typeof j=="function"){if(i){if(f.execOnInit){j.call($(f.selector))}else{return}}else{j.call($(f.selector),e)}}else{showHide(j,"show",i?"none":"slide")}});$(g).each(function(k,j){if(typeof j=="function"){if(i){if(f.execOnInit){j.call($(f.selector))}else{return}}else{j.call($(f.selector),e)}}else{showHide(j,"hide",i?"none":"slide")}})}function b(d){var e={selector:null,conditions:[],"else":null,always:null,execOnInit:false};if($.isArray(d)){d=$.extend(e,{selector:d[0],conditions:[{"if":d[1],then:d[2],"else":d[3]}]})}else{if(typeof d.conditions!="undefined"&&!$.isArray(d.conditions)){d.conditions=[d.conditions]}d=$.extend(e,d)}return d}};