/*
* Commercial Codebase by RETS PRO Development Team.
* Copyright RETS PRO - 2009 - 2020 - All Rights Reserved
* License: https://retspro.com/faq/license/
*/
var infowindow = null;
WPR.polygon;
var myPoly;
(function ($, WPR, infowindow)
{
//var WPR = WPR || {};
window.GetModuleConfig = function (moduleName, callback)
{
$.getJSON(
WPR.ajaxurl,
{
controller: "System",
action: "GetModuleSettings",
module_name: moduleName
},
function (data)
{
if (data !== null)
{
callback(data);
} else
{
var data2 = {module: moduleName};
callback(data2);
}
jQuery('body select').select2('destroy');
jQuery("body select").select2({width: '100%'});
}
);
}
window.formToObj = function (formId)
{
/*
// Prep the checkboxes to always provide a value
$('#' + formId + ' input[type="checkbox"]').each(function(_, value){
// This interfaces with the uniformjs checkbox
$(value).val($(value).parent().hasClass('checked') ? 'true' : 'no');
//alert($(value).val());
//$(this).val($(this).prop('checked')); // 1.7+
// The reason for checking the field is because we use true or false for a value. since we do not do $.uniform.update() no ui shift occurs
$(this).attr('checked', true);
//$(this).prop('checked', true); // 1.7+
})
*/
// Now serialize the form
var paramObj = {};
$.each($('#' + formId).serializeArray(), function (_, kv)
{
if (kv.value == undefined) //
return true;
else if (paramObj.hasOwnProperty(kv.name))
{
paramObj[kv.name] = $.makeArray(paramObj[kv.name]);
paramObj[kv.name].push(kv.value);
} else
{
paramObj[kv.name] = kv.value;
}
});
return paramObj;
}
window.populateSettings = function (data)
{
WPR[data.module] = WPR[data.module] || {};
WPR[data.module].settings = WPR[data.module].settings || {};
$.each(data.objectContents, function (key, value)
{
WPR[data.module].settings[key] = value;
});
//alert(JSON.stringify(WPR[data.module].settings));
// move to rpxsearch
defaultMapSettings = {
zoom: WPR[data.module].settings['zoom'] ? parseInt(WPR[data.module].settings['zoom']) : 10,
center: {
lat: WPR[data.module].settings['ctr-lat'] ? parseFloat(WPR[data.module].settings['ctr-lat']) : 28.489997965086314,
lng: WPR[data.module].settings['ctr-lng'] ? parseFloat(WPR[data.module].settings['ctr-lng']) : -81.35369869873051
},
mapTypeId: WPR[data.module].settings['map_type'],
disableDefaultUI: true,
maxZoom: WPR[data.module].settings['max-zoom'] ? WPR[data.module].settings['max-zoom'] : null
} // bw style -> styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}]
var afterSettingsLoaded;
//console.log(navigator.appName);
if (navigator.appName == 'Microsoft Internet Explorer' || navigator.appName == 'Netscape')
{
afterSettingsLoaded = document.createEvent('CustomEvent');
afterSettingsLoaded.initCustomEvent("RPxSettingsLoaded", true, true, {message: 'done'});
} else
{
afterSettingsLoaded = new CustomEvent(
"RPxSettingsLoaded",
{
detail: {
message: 'done'
},
bubbles: true,
cancelable: true
}
);
}
var mapSettings = $.extend(defaultMapSettings, {});
WPR.map = new google.maps.Map(WPR.mapDiv, mapSettings);
bindMapEvent();
document.getElementById('listing_map').dispatchEvent(afterSettingsLoaded);
};
window.clearMapEvent = function ()
{
google.maps.event.clearListeners(WPR.map, 'idle');
}
window.bindMapEvent = function ()
{
new google.maps.event.addListener(WPR.map, 'idle', function ()
{
console.log(WPR.isBoundSearch);
if (WPR.isBoundSearch === false)
{
return true;
}
console.log("IN");
if (WPR.isGeoSearch)
{
return true;
}
if (WPR.preventRefresh && WPR.isPolySearch && 0)
{// why the 0?
return true;
}
WPR.listingOffset = 0;
if (WPR.preventRefresh && WPR.infoWindowsCount < 1)
{
WPR.preventRefresh = false;
if (infowindow)
{
infowindow.close();
}
return true;
} else if (WPR.preventRefresh)
{
WPR.preventRefresh = false;
return true;
} else
{
if (infowindow)
{
infowindow.close();
}
}
//console.log('called');
toggleMapLoadingOverlay();
if (WPR.isPolySearch)
{
//alert(JSON.stringify(WPR.polygon));
WPR.GetPolygon('Markers', WPR.polygon);
} else
{
getListings('GetTemplatedListings');
getListings('GetMarkers');
}
});
};
window.populateForm = function (data)
{
//console.log(data);
WPR[data.module] = WPR[data.module] || {};
WPR[data.module].settings = WPR[data.module].settings || {};
$.each(data.objectContents, function (key, value)
{
WPR[data.module].settings[key] = value;
if ($('input[name="' + key + '"], select[name="' + key + '"]').length)
{
if ($('input[name="' + key + '"]').length)
{
if ($('input[name="' + key + '"]').attr('type') == 'checkbox')
{
$('input[name="' + key + '"]').attr('checked', value === 'true'); // 1.7+ change to prop
if (value === 'true')
jQuery.uniform.update();
} else if ($('input[name="' + key + '"]').attr('type') == 'radio')
{
$('input[name="' + key + '"][value="' + value + '"]').attr('checked', true);
jQuery.uniform.update();
} else
{
$('input[name="' + key + '"]').val(value);
}
} else
{
$('select[name="' + key + '"] option[value="' + value + '"]').attr('selected', 'selected');
if (typeof (jQuery.uniform) !== 'undefined' && typeof (jQuery.uniform.update) === 'function')
jQuery.uniform.update();
}
}
});
if (typeof (jQuery.uniform) !== 'undefined' && typeof (jQuery.uniform.update) === 'function')
jQuery.uniform.update();
var afterFormLoaded = new CustomEvent(
"RPxAdminFormLoaded",
{
detail: {
message: 'done'
},
bubbles: true,
cancelable: true
}
);
document.getElementById('Settings').dispatchEvent(afterFormLoaded);
}
window.saveConfig = function (target)
{
var formData = formToObj('Settings');
var submitData = $.extend(formData, {controller: 'System', action: 'SetModuleSettings', module_name: $(target).data('module')});
$.getJSON(
WPR.ajaxurl,
submitData,
function (data)
{
alert('Config Updated');
GetModuleConfig($(target).data('module'), populateForm);
});
}
/**
*
* @param {type} data
* @param {Obje} meta
* @returns {void}
*/
WPR.MakeFieldSelect = function (data, meta)
{
//console.log(meta);
var selector;
if (typeof meta !== 'undefined' && typeof meta.form !== 'undefined')
selector = '#' + meta.form + ' select[name=' + meta.selectName + ']';
else
selector = 'select[name=' + meta.selectName + ']';
if (data !== null)
{
$(selector).append($('<option value="">Select Field</option>'));
$.each(data.objectContents, function (i, val)
{
if (meta.selected == val)
{
$(selector).append($('<option selected="selected" value="' + val + '">' + val + '</option>'));
return;
}
$(selector).append($('<option value="' + val + '">' + val + '</option>'));
});
} else
{
$(selector).append($('<option value="">No Values Found</option>'));
}
jQuery.uniform.update();
}
WPR.GetTableCols = function (callback, meta)
{
$.getJSON(
WPR.ajaxurl,
{
controller: "System",
action: "GetTableFieldsFiltered",
tablename: meta.table
},
function (data)
{
callback(data, meta);
}
);
}
WPR.GetDistinctList = function (table, fieldname, callback)
{
$.get(WPR.ajaxurl,
{
controller: 'System',
action: 'GetDistinctList',
tablename: table,
fieldname: fieldname
},
function (data)
{
if (!data)
return;
var obj = $.parseJSON(data);
callback(obj.objectContents);
});
};
WPR.UploadFile = function (formEl, callback)
{
var formData = new FormData(formEl);
$.ajax({
url: WPR.ajaxurl + '?controller=System&action=UploadFile&module=' + $(formEl).data('module') + '&type=' + $(formEl).data('type'),
type: "POST",
data: formData,
contentType: false,
cache: false,
dataType: "json",
processData: false,
success: function (data)
{
callback({data: data, formData: formData, formEl: formEl});
}
});
}
WPR.encodeFileName = function (filename)
{
if (filename == null)
return 'default_marker';
var encoded_name = filename.replace(/ /g, '--').replace(/\//g, '__');
return encoded_name;
}
WPR.decodeFileName = function (filename)
{
var decoded_filename = filename.replace(/--/g, ' ').replace(/__/g, '/');
return decoded_filename;
}
WPR.setTitle = function (element, newTitle)
{
$(element).attr('title', newTitle);
}
WPR.SetupSelects = function ()
{
$.each($(".live-select"), function (i, val)
{
//alert(JSON.stringify(WPR[$(this).attr('data-module')]['settings']))
//var sets = WPR[$(this).attr('data-module')]['settings'];
//console.log(sets.stage_2);
;
WPR.GetTableCols(WPR.MakeFieldSelect,
{
module: $(this).attr('data-module'), // Remember this - has to be there
selectName: $(this).attr('name'),
selected: WPR[$(this).attr('data-module')]['settings'][$(this).attr('name')] || '',
table: $(this).attr('data-table')
})
})
}
$(document).ready(function ()
{
$.ajaxSetup({cache: false});
$(".icon-form").on('submit', function (e)
{
e.preventDefault();
WPR.UploadFile(this);
});
$('#UpdateConfig').click(function (e)
{
e.preventDefault();
saveConfig(this);
});
})
})(WPR.jq || jQuery, WPR, infowindow);
function localStorageAvailable()
{
var type = 'localStorage';
try
{
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
} catch (e)
{
return false;
}
}
function AddListingAction(idPrefix, idOrMls, classname, title)
{
//alert('hit');
jQuery('.listing_actions').each(function ()
{
var ident = jQuery(this).closest('.property_listing').data(idOrMls);
//var mls = jQuery(this).closest('.property_listing').data('mls');
jQuery(this).append('<span id="' + idPrefix + ident + '" class="' + classname + '" title="' + title + '"></span>');
})
}
function RPxListingAction()
{
this.addAction = function (classname)
{
jQuery.each(jQuery('.listing_actions'), function (i, v)
{
v.append('<span>woot</span>');
})
}
}