-/*
- *
- * Other needed Admin JS code
- * Block level comments used temporarily to make finding sections of the code easier
- * alot of duplicate code and unecessary variables I need to clean up, need to change case from camel case to snake case
- * need to create a function for setting the edtior content because it is duplicated a few times
+/**
+ * Other needed Admin JS code
+ * Block level comments used temporarily to make finding sections of the code easier
+ * a lot of duplicate code and unnecessary variables I need to clean up, need to change case from camel case to snake case
+ * need to create a function for setting the editor content because it is duplicated a few times
*/
jQuery(document).ready(function ($) {
-
+
'use strict';
-
+
var shortcodeDropdown, shortcodeCategory, blankStart, memberView, amenityGroups, listBox, detailBox, target, boxTarget, shortcodeString,
- editor_shortcodes, category_id, shortcodeValues = {}, editor_content, debug = false;
-
+ editor_shortcodes, category_id, groups_id, shortcodeValues = {}, editor_content, debug = false;
+
debug = true;
$("#showDetail").hide();
$("#packageListAttr").hide();
//$(".scCategories").hide();
-
+
/////////////////////////////////////////////////////////////////////////////////////////
- // CHANGE MAIN SHORTCODE
+ // CHANGE MAIN SHORTCODE
/////////////////////////////////////////////////////////////////////////////////////////
// fire events and reset settings when switching between shortcodes
$("[id$=shortcodeDropdown]").on("change", function () {
-
+
// reset the dropdowns and checkbox if when switching shortcodes
document.getElementById('category-scDropdown').options[0].selected = 'selected';
if($('#blank-start-scDropdown').length)
document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
if($('#id-scDropdown').length)
document.getElementById('id-scDropdown').options[0].selected = 'selected';
-
+
// uncheckAll();
-
+
// delete the object properties to reset the object
shortcodeString = "";
-
+
for (var prop in shortcodeValues){
delete shortcodeValues[prop];
}
-
+
// get the shortcode option name and hide / show necessary elements
shortcodeDropdown = $(".shortcodeDropdown option:selected").val();
-
+
// many of these are not necessary as much of the shortcode has been stripped
if(shortcodeDropdown === "glm-members-list"){
$("#showCategory").show();
$("#view-scDropdown").show();
$("#map-opened-scDropdown").show();
$("[id^='packageList']").hide();
- $("#category-scDropdown").show();
+ $("#category-scDropdown").show();
$(".scCategories").show();
+ $("#amenitygroup-scDropdown").show();
}
-
+
if(shortcodeDropdown === "glm-members-packaging-list"){
$("#blank-start-scDropdown").hide();
$("#showCategory").hide();
$("[id^='packageList']").show();
$("#view-scDropdown").hide();
$(".scCategories").hide();
- }
+ }
});
-
-
+
////////////////////////////////////////////////////////////////////
- // PAGE LOAD FUNCTIONS
+ // PAGE LOAD FUNCTIONS
/////////////////////////////////////////////////////////////////////
// shortcode attribute name from dropdowns containing '-scDropdown' in their ID
// Then append the values to the shortcode object
$("#detailBtn").on("click", function () {
$("#showDetail").dialog().dialog("option", "width", 422);
});
-
+
// get shortcodes between square brackets
var regExp = /\[([^)]+)\]/;
// function used to get everything out of the visual and text editors
function get_tinymce_content(){
if (jQuery("#wp-content-wrap").hasClass("tmce-active")){
-
+
tinyMCE.triggerSave();
if(regExp.exec($('#content').val())){
}
} else {
-
+
// get the shortcode from the editor with [ ] as the delimiters
editor_content = regExp.exec($("#content").val());
-
+
// getting an array as the value from the previous reExp, will need to investigate
if(regExp.exec($("#content").val())){
return editor_content[0];
//$('#shortcodeBuilder').hide();
}
- if(editor_shortcodes){
+ if ( editor_shortcodes ) {
if ( editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null ) {
- if ( debug ) {
- console.info('DEBUG INFO: editor_shortcodes.match amenity-groups ', editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/)[1] );
- }
+ amenityGroups = editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ )[1];
+ groups_id = amenityGroups.split(',');
+ } else if ( editor_shortcodes.match( /glm-members-list .* amenity-groups=""/ ) !== null ) {
+ groups_id = editor_shortcodes.match( /glm-members-list .* amenity-groups=""/ )[1];
}
if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) {
blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1];
- if ( debug ) {
- console.info('DEBUG INFO: editor_shortcodes.match blank-start ', blankStart );
- }
}
if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) {
memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1];
- if ( debug ) {
- console.info('DEBUG INFO: editor_shortcodes.match view ', memberView );
- }
}
if(editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null){
-
+
// return the category option from the shortcode
category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
-
+
// pull the ID numbers from the returned category string
category_id = category_id.split(',');
} else if (editor_shortcodes.match(/glm-members-list category=""/) !== null){
- category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
+ category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
}
- $('#shortcodeDropdown').val('glm-members-list');
+ $('#shortcodeDropdown').val( 'glm-members-list' );
}
+ // find the category names from the category select
var category_names_ids = new Array();
- var categoryNames = $("#category-scDropdown>option").map(function() {
+ var categoryNames = $("#category-scDropdown>option").map(function() {
var index = $.inArray($(this).val(), category_id);
if(index !== -1 && index !== ""){
category_names_ids.push([$(this).text(), $(this).val()]);
- return $(this).text();
+ return $(this).text();
}
}).get();
+ // add the category names to #activeCategories
$.each( category_names_ids, function (index, obj) {
$('#activeCategories').append('<div data-id="' + obj[1]
- + '" class="glm-dynSelect-item glm-members-catgegory">'
+ + '" class="glm-dynSelect-item glm-members-categories">'
+ obj[0] + " (ID: " + obj[1] + ')' + '<span class="glm-dynSelect-delete catDelete">X</span>'
+ '<input type="hidden" name="category[' + obj[0] + ']" value="' + obj[0] + '"></div>');
});
+ // find the group names from the group select
+ var group_names_ids = new Array();
+ var groupNames = $("#amenitygroup-scDropdown>option").map(function() {
+ var index = $.inArray($(this).val(), groups_id);
+ if(index !== -1 && index !== ""){
+ group_names_ids.push([$(this).text(), $(this).val()]);
+ return $(this).text();
+ }
+ }).get();
+ console.log( 'group_names_id', group_names_ids );
+
+ // add the group names to #activeGroups
+ $.each( group_names_ids, function (index, obj) {
+ $('#activeGroups').append('<div data-id="' + obj[1]
+ + '" class="glm-group-dynSelect-item glm-members-groups">'
+ + obj[0] + " (ID: " + obj[1] + ')' + '<span class="glm-group-dynSelect-delete groupDelete">X</span>'
+ + '<input type="hidden" name="group[' + obj[0] + ']" value="' + obj[0] + '"></div>');
+ });
+
/////////////////////////////////////////////////////////////////////////////////////////////
/*
* Category Selection these functions fire whenever the 'select category' dropdown is changed
*/
- //////////////////////////////////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////////////////////////////////
var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), empty_space, count;
-
+
$('#category-scDropdown').change( function() {
editor_shortcodes = get_tinymce_content();
if ( editor_shortcodes ) {
if ( editor_shortcodes.match( /category="(.*?)"/ ) !== null ){
category_id = editor_shortcodes.match( /glm-members-list category="(.*?)"/ )[1];
-
+
if ( category_id !== "" ) {
category_id = category_id.split(',');
-
+
ids = category_id.join(',');
empty_space = false;
} else {
ids = 'category=""';
-
+
// this determines if the category option is blank "" to determine if the jquery replace method works properly
empty_space = true;
}
}
}
-
+
// Get the ID, name, and parent of the category
- var catValue = $('#category-scDropdown').val();
+ var catValue = $('#category-scDropdown').val();
var catName = $('#category-scDropdown').find(':selected').text();
var catParent = $('#category-scDropdown').find(':selected').attr('data-parent');
// Check if the category has already been added
- var found = false;
+ var found = false;
$(".glm-members-catgegory").each( function() {
var id = $(this).attr('data-id');
if (id === catValue) {
// If not found, Add the category
if (!found) {
$('#activeCategories').append('<div data-id="' + catValue
- + '" class="glm-dynSelect-item glm-members-catgegory">'
+ + '" class="glm-dynSelect-item glm-members-catgegory">'
+ catName.trim() + ' (ID: ' + catValue + ')' + '<span class="glm-dynSelect-delete catDelete">X</span>'
+ '<input type="hidden" name="category[' + catValue + ']" value="' + catValue + '"></div>');
}
-
+
// reset the id string after each set of iterations
id_string = '';
-
+
$.each($(".glm-dynSelect-item"), function () {
if($.inArray($(this).data("id"), new_ids) === -1){
new_ids.push($(this).data("id"));
}
- });
-
- // if more than one category id in the array, join together with ',' otherwise set the id string to a single value
+ });
+
+ // if more than one category id in the array, join together with ',' otherwise set the id string to a single value
if ( new_ids.length > 1 ){
id_string = new_ids.join(',');
} else if ( new_ids.length === 1 ) {
id_string = new_ids[0];
}
-
-
+
+
// replace the current content in either the visual or text editor and replace it with a filtered version of the categories
if ( $("#content").css("display") !== "none" ) {
editor_content = content.val();
$('#category-scDropdown').val('Select Category');
});
+ var group_ids, group_id_string, group_new_ids = new Array(), group_empty_space, group_missing;
+
+ // Amenity Groups
+ // This fires when the groups select is changed
+ $('#amenitygroup-scDropdown').change(function(){
+ editor_shortcodes = get_tinymce_content();
+ if ( editor_shortcodes ) {
+ if ( editor_shortcodes.match( /amenity-groups="(.*?)"/ ) !== null ){
+ group_missing = false;
+ groups_id = editor_shortcodes.match( /amenity-groups="(.*?)"/ )[1];
+
+ if ( groups_id !== "" ) {
+ groups_id = groups_id.split(',');
+
+ group_ids = groups_id.join(',');
+ group_empty_space = false;
+ } else {
+
+ group_ids = 'amenity-groups=""';
+
+ // this determines if the groups option is blank "" to determine if the jquery replace method works properly
+ group_empty_space = true;
+ }
+ } else {
+ group_missing = true;
+ group_empty_space = false;
+ }
+ }
+
+ // Get the ID, name
+ var groupValue = $('#amenitygroup-scDropdown').val();
+ var groupName = $('#amenitygroup-scDropdown').find(':selected').text();
+
+ // Check if the group has already been added
+ var found = false;
+ $(".glm-members-groups").each( function() {
+ var id = $(this).attr('data-id');
+ if (id === groupValue) {
+ found = true;
+ }
+ });
+
+ // If not found, Add the group
+ if (!found) {
+ $('#activeGroups').append('<div data-id="' + groupValue
+ + '" class="glm-group-dynSelect-item glm-members-groups">'
+ + groupName.trim() + ' (ID: ' + groupValue + ')' + '<span class="glm-group-dynSelect-delete groupDelete">X</span>'
+ + '<input type="hidden" name="group[' + groupValue + ']" value="' + groupValue + '"></div>');
+ }
+
+ // reset the id string after each set of iterations
+ group_id_string = '';
+
+ $.each($(".glm-group-dynSelect-item"), function () {
+ if($.inArray($(this).data("id"), group_new_ids) === -1){
+ group_new_ids.push($(this).data("id"));
+ }
+ });
+
+ // if more than one category id in the array, join together with ',' otherwise set the id string to a single value
+ if ( group_new_ids.length > 1 ){
+ group_id_string = group_new_ids.join(',');
+ } else if ( group_new_ids.length === 1 ) {
+ group_id_string = group_new_ids[0];
+ }
+
+ // replace the current content in either the visual or text editor and replace it with a filtered version of the groups
+ if ( $("#content").css("display") !== "none" ) {
+ editor_content = content.val();
+ if ( group_empty_space ) {
+ editor_content = editor_content.replace( group_ids, 'amenity-groups="' + group_id_string + '"' );
+ content.val( editor_content );
+ } else if ( group_missing ) {
+ content.val( editor_content );
+ } else {
+ editor_content = editor_content.replace( 'amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string );
+ content.val( editor_content );
+ }
+ } else if ( tinyMCE.activeEditor !== null ) {
+ if ( group_empty_space ) {
+ console.log( 'group empty space found 2' );
+ console.log( 'group_ids', group_ids );
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace(group_ids, 'amenity-groups="' + group_id_string + '"' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ } else if ( group_missing ) {
+ console.log( 'group missing found 2' );
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ var shortcodeReg = /(\[glm-members-list .*)(\])/;
+ var groupMatch = editor_content.match( shortcodeReg );
+ editor_content = editor_content.replace( shortcodeReg, '$1 amenity-groups="' + group_id_string + '"$2' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ } else {
+ console.log( 'group normal found 2' );
+ console.log( 'tinyMCE replace amenity-group', group_ids, group_id_string );
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string);
+ tinyMCE.activeEditor.setContent(editor_content);
+ }
+ }
+
+ // Reset picklist
+ $('#amenitygroup-scDropdown').val('Select Groups');
+ });
+
+ // Blank Start change event
+ // These fire when the blank-start select is changed
$('#blank-start-scDropdown').change(function(){
editor_shortcodes = get_tinymce_content();
editor_content = content.val();
+ if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) {
+ blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1];
+ }
+ if ( editor_shortcodes ) {
+ if ( $("#content").css("display") !== "none" ) {
+ editor_content = editor_content.replace( 'blank-start="' + blankStart +'"', 'blank-start="' + $(this).val() + '"' );
+ } else if ( tinyMCE.activeEditor !== null ) {
+ console.log( 'Found #2', $(this).val() );
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace( 'blank-start="' + blankStart +'"', 'blank-start="' + $(this).val() + '"' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ }
+ }
+ });
+
+ // View dropdown
+ // These events fire when the View select is changed
+ $('#view-scDropdown').change(function(){
+ editor_shortcodes = get_tinymce_content();
+ editor_content = content.val();
+ if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) {
+ memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1];
+ }
if ( editor_shortcodes ) {
if ( $("#content").css("display") !== "none" ) {
- editor_content = editor_content.replace( ids, 'blank-start="' + $(this).val() + '"' );
+ editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' );
} else if ( tinyMCE.activeEditor !== null ) {
+ console.log( 'Found #2', $(this).val() );
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' );
+ tinyMCE.activeEditor.setContent(editor_content);
}
}
});
}
return false;
}
-
+
/////////////////////////////////////////////////////////////////////////////////////////////////
// INSERT SHORTCODE FUNCTION these fire when the 'insert shortcode' button is clicked
/////////////////////////////////////////////////////////////////////////////////////////////////
// generate the shortcode into a string and insert into the content upon clicking
$("[id$=generate]").on("click", function () {
count = 0;
- if(number_of_categories){
+ if ( number_of_categories ) {
count = number_of_categories;
count++;
} else {
count++;
}
// enforce the selection of a shortcode
- if(shortcodeDropdown){
+ if ( shortcodeDropdown ) {
// set up properties for shortcode lists
- if(shortcodeDropdown === "glm-members-list"){
- var listValues = $('input[name="listBox"]:checkbox:checked').map(function() {
+ if ( shortcodeDropdown === "glm-members-list" ) {
+ var listValues = $('input[name="listBox"]:checkbox:checked').map( function() {
boxTarget = $(this).attr("class").slice(0, -5);
return this.value;
}).get();
-
-
+
+
var listString = "";
- listValues.forEach(function(value){
+ listValues.forEach( function( value ) {
listString += value + ",";
});
- if(listValues !== ""){
- listString = listString.replace(/,\s*$/, "");
+ if ( listValues !== "" ) {
+ listString = listString.replace( /,\s*$/, "" );
shortcodeValues[boxTarget] = listString;
}
// set up properties for detail shortcode
} else if( shortcodeDropdown === "glm-member-detail"){
- var detailValues = $('input[name="detailBox"]:checkbox:checked').map(function() {
+ var detailValues = $('input[name="detailBox"]:checkbox:checked').map( function() {
boxTarget = $(this).attr("class").slice(0, -7);
return this.value;
}).get();
-
+
var detailString = '';
- detailValues.forEach(function(value){
+ detailValues.forEach( function( value ) {
detailString += value + ",";
});
- if(detailValues !== ""){
- detailString = detailString.replace(/,\s*$/, "");
+ if ( detailValues !== "" ) {
+ detailString = detailString.replace( /,\s*$/, "" );
shortcodeValues[boxTarget] = detailString;
}
}
-
+
// start the shortcode string that will be added to the tinymce editor
shortcodeString = '<div class="previewCodes" id="' + shortcodeDropdown + '_' + count + '"> [' + shortcodeDropdown;
-
+
// populate the shortcode object with all of the shortcode attributes and their values
for (var key in shortcodeValues) {
if (shortcodeValues.hasOwnProperty(key)) {
}
}
}
-
+
// add the list of category ids instead of the single value originally inserted
- if(shortcodeString.match(/glm-members-list category="(.*?)"/) !== null){
- category_id = shortcodeString.match(/glm-members-list category="(.*?)"/)[1];
+ if ( shortcodeString.match( /glm-members-list category="(.*?)"/ ) !== null ) {
+ category_id = shortcodeString.match( /glm-members-list category="(.*?)"/ )[1];
category_id = category_id.split(',');
ids = category_id.join(',');
shortcodeString = shortcodeString.replace(ids, id_string);
shortcodeString += '] </div>';
// insert shortcode at current cursor position
- if($("#content").css("display") !== "none"){
- var cursorPos = $('#content').prop('selectionStart');
+ if ( $("#content").css("display") !== "none" ) {
+ var cursorPos = $('#content').prop( 'selectionStart' );
var v = $('#content').val();
var textBefore = v.substring(0, cursorPos );
var textAfter = v.substring( cursorPos, v.length );
$('#content').val( textBefore + shortcodeString + textAfter );
-
- } else if($("#content").css("display") === "none") {
-
- insert_tag(shortcodeString);
+
+ } else if( $("#content").css("display") === "none" ) {
+
+ insert_tag( shortcodeString );
}
- } else {
+ } else {
alert("Please Select a Shortcode");
}
});
+ $('#glmRemoveShortCode').on('click', function(){
+ // find the short code and remove it!
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ var shortcodeReg = /(\[glm-members-list .*?])/;
+ editor_content = editor_content.replace( shortcodeReg, '' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ });
+
+
//////////////////////////////////////////////////////////////////////////////////////
// DELETE CATEGORY these fire when a category box's X is clicked to delete a category
/////////////////////////////////////////////////////////////////////////////////////
// Action to de-select a category and dynamically adjust the shortcode categories in the editor
-
+
$('.catDelete').live('click', function() {
editor_shortcodes = get_tinymce_content();
}
$(this).parent().remove();
-
+
// reset the array after each set of iterations
new_ids.length = 0;
-
+
$.each($(".glm-dynSelect-item"), function () {
if($.inArray($(this).data("id"), new_ids) === -1){
new_ids.push($(this).data("id"));
// create a string of id's from the array
id_string = new_ids.join(',');
-
+
// get and replace current editor content
if($("#content").css("display") !== "none"){
-
+
editor_content = content.val();
editor_content = editor_content.replace('category="' + ids, 'category="' + id_string );
content.val(editor_content);
-
+
} else if(tinyMCE.activeEditor !== null){
-
+
editor_content = tinyMCE.get('content').getContent({format: 'raw'});
editor_content = editor_content.replace('category="' + ids, 'category="' + id_string);
tinyMCE.activeEditor.setContent(editor_content);
-
+
+ }
+
+ });
+
+ // group delete
+ $('.groupDelete').live('click', function(){
+ editor_shortcodes = get_tinymce_content();
+
+ if(editor_shortcodes && editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/) !== null){
+ groups_id = editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/)[1];
+ groups_id = groups_id.split(',');
+ console.log( 'found - ', groups_id );
+ group_ids = groups_id.join(',');
+ }
+
+ $(this).parent().remove();
+
+ // reset the array after each set of iterations
+ group_new_ids.length = 0;
+
+ $.each($(".glm-group-dynSelect-item"), function () {
+ if($.inArray($(this).data("id"), group_new_ids) === -1){
+ group_new_ids.push($(this).data("id"));
+ }
+ });
+
+ // create a string of id's from the array
+ group_id_string = group_new_ids.join(',');
+
+ // get and replace current editor content
+ if($("#content").css("display") !== "none"){
+ editor_content = content.val();
+ editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string );
+ content.val(editor_content);
+ } else if(tinyMCE.activeEditor !== null){
+ console.log( 'amenity-groups replacement reached' );
+ console.log( 'group_id_string', group_id_string );
+ console.log( 'group_ids', group_ids );
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string);
+ tinyMCE.activeEditor.setContent(editor_content);
}
});
-
/////////////////////////////////////////////////////////////////////////////////////////////////
// MAINENANCE these were necessary to reset the dropdowns but most of them are no longer needed
var list = document.getElementById('type-scList');
var members = document.getElementById('member-scDropdown');
var view = document.getElementById('view-scDropdown');
+ var groups = document.getElementById('amenitygroup-scDropdown');
if ( editor_shortcodes ) {
$('#shortcodeDropdown').val('glm-members-list');
$('#shortcodeDropdown').change();
+ $('#shortcodeDropdown').hide();
$('#generate').hide();
}
- if( scd ){
+ if( scd && !editor_shortcodes ){
window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected';
}
if( catscd ){
window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
}
}
-});
-
+ if ( groups ) {
+ window.onload = document.getElementById('amenitygroup-scDropdown').options[0].selected = 'selected';
+ }
+});