var shortcodeDropdown, shortcodeCategory, blankStart, memberView, amenityGroups, listBox, detailBox, target, boxTarget, shortcodeString,
editor_shortcodes, category_id, groups_id, shortcodeValues = {}, editor_content, debug = false;
-
debug = true;
+
$("#showDetail").hide();
$("#categoryBox").hide();
$("#packageListAttr").hide();
$('#activeCategories').hide();
$('#activeGroups').hide();
+ $('#activeRegions').hide();
$('#glmRemoveShortCode').hide();
-
- /////////////////////////////////////////////////////////////////////////////////////////
- // CHANGE MAIN SHORTCODE
- /////////////////////////////////////////////////////////////////////////////////////////
+/*
+ * Change Main Shortcode
+ */
// fire events and reset settings when switching between shortcodes
$("[id$=shortcodeDropdown]").on("change", function () {
if($('#id-scDropdown').length)
document.getElementById('id-scDropdown').options[0].selected = 'selected';
-// uncheckAll();
-
// delete the object properties to reset the object
shortcodeString = "";
$("#category-scDropdown").show();
$(".scCategories").show();
$("#amenitygroup-scDropdown").show();
+ $("#region-search-scDropdown").show();
$('#activeCategories').show();
$('#activeGroups').show();
+ $('#activeRegions').show();
}
-
if(shortcodeDropdown === "glm-members-packaging-list"){
$("#blank-start-scDropdown").hide();
$("#showCategory").hide();
$('#activeCategories').hide();
$('#activeGroups').hide();
}
-
});
-
- ////////////////////////////////////////////////////////////////////
- // PAGE LOAD FUNCTIONS
- /////////////////////////////////////////////////////////////////////
// shortcode attribute name from dropdowns containing '-scDropdown' in their ID
// Then append the values to the shortcode object
$("[id$=-scDropdown]").on("change", function () {
shortcodeValues[target] = targetVal;
}
});
- // use jquery dialog to separate the checkbox lists
- $("#showCategory").on("click", function () {
- $("#categoryBox").dialog().dialog("option", "width", 450 );
- });
- $("#detailBtn").on("click", function () {
- $("#showDetail").dialog().dialog("option", "width", 422);
- });
-
// get shortcodes between square brackets
var regExp = /\[([^)]+)\]/;
} else {
return;
}
-
} else {
-
- // get the shortcode from the editor with [ ] as the delimiters
-
+ // get the shortcode from the editor with [ ] as the delimiter
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];
}
if ( editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null ) {
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];
+ } 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];
* 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;
+ var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), empty_space, category_missing;
$('#category-scDropdown').change( function() {
editor_shortcodes = get_tinymce_content();
+
+ if ( editor_shortcodes ) {
+ if ( editor_shortcodes.match( /glm-members-list category="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* category="(.*?)"/ ) ){
+ category_missing = false;
+ ids = editor_shortcodes.match( /category="(.*?)"/ )[1];
- 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(',');
+ if ( ids !== "" ) {
+ ids = ids.split(',');
- ids = category_id.join(',');
- empty_space = false;
+ ids = ids.join(',');
+ empty_space = false;
} else {
ids = 'category=""';
- // this determines if the category option is blank "" to determine if the jquery replace method works properly
+ // this determines if the groups option is blank "" to determine if the jquery replace method works properly
empty_space = true;
}
+ } else {
+ category_missing = true;
+ empty_space = false;
}
}
}
});
-
// If not found, Add the category
if (!found) {
$('#activeCategories').append('<div data-id="' + catValue
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();
- if ( empty_space ) {
+ if ( $("#content").css("display") !== "none" ) {
+ editor_content = content.val();
+ if ( empty_space ) {
editor_content = editor_content.replace( ids, 'category="' + id_string + '"' );
content.val( editor_content );
- } else {
+ } else if ( category_missing ) {
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ editor_content = editor_content.replace( shortcodeReg, '$1 category="' + id_string + '"$2' );
+ content.val( editor_content );
+ } else {
editor_content = editor_content.replace( 'category="' + ids, 'category="' + id_string );
content.val( editor_content );
- }
- } else if ( tinyMCE.activeEditor !== null ) {
- if ( empty_space ) {
+ }
+ } else if ( tinyMCE.activeEditor !== null ) {
+ if ( empty_space ) {
editor_content = tinyMCE.get('content').getContent({format: 'raw'});
- editor_content = editor_content.replace(ids, 'category="' + id_string + '"' );
+ editor_content = editor_content.replace( ids, 'category="' + id_string + '"' );
tinyMCE.activeEditor.setContent(editor_content);
- } else {
+ } else if ( category_missing ) {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ var catMatch = editor_content.match( shortcodeReg );
+ editor_content = editor_content.replace( shortcodeReg, '$1 category="' + id_string + '"$2' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ } else {
editor_content = tinyMCE.get('content').getContent({format: 'raw'});
editor_content = editor_content.replace('category="' + ids, 'category="' + id_string);
tinyMCE.activeEditor.setContent(editor_content);
- }
- }
+ }
+ }
// Reset picklist
$('#category-scDropdown').val('Select Category');
$('#amenitygroup-scDropdown').change(function(){
editor_shortcodes = get_tinymce_content();
if ( editor_shortcodes ) {
- if ( editor_shortcodes.match( /amenity-groups="(.*?)"/ ) !== null ){
+ if ( editor_shortcodes.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ ) ){
group_missing = false;
groups_id = editor_shortcodes.match( /amenity-groups="(.*?)"/ )[1];
editor_content = editor_content.replace( group_ids, 'amenity-groups="' + group_id_string + '"' );
content.val( editor_content );
} else if ( group_missing ) {
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ editor_content = editor_content.replace( shortcodeReg, '$1 amenity-groups="' + group_id_string + '"$2' );
content.val( editor_content );
} else {
editor_content = editor_content.replace( 'amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string );
tinyMCE.activeEditor.setContent(editor_content);
} else if ( group_missing ) {
editor_content = tinyMCE.get('content').getContent({format: 'raw'});
- var shortcodeReg = /(\[glm-members-list .*)(\])/;
+ 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);
// Reset picklist
$('#amenitygroup-scDropdown').val('Select Groups');
});
+
+ var regions_id, regions_id_string, regions_new_ids = new Array(), regions_empty_space, regions_missing;
+ $('#region-search-scDropdown').change(function(){
+ editor_shortcodes = get_tinymce_content();
+ if ( editor_shortcodes ) {
+ if ( editor_shortcodes.match( /glm-members-list region-search="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){
+ regions_missing = false;
+ regions_id = editor_shortcodes.match( /region-search="(.*?)"/ )[1];
+
+ if ( regions_id !== "" ) {
+ regions_id = regions_id.split(',');
+
+ regions_id = regions_id.join(',');
+ regions_empty_space = false;
+ } else {
+
+ regions_id = 'region-search=""';
+
+ // this determines if the groups option is blank "" to determine if the jquery replace method works properly
+ regions_empty_space = true;
+ }
+ } else {
+ regions_missing = true;
+ regions_empty_space = false;
+ }
+ }
+
+ // Get the ID, name
+ var regionsValue = $('#region-search-scDropdown').val();
+ var regionsName = $('#region-search-scDropdown').find(':selected').text();
+
+ // Check if the group has already been added
+ var found = false;
+ $(".glm-members-regions").each( function() {
+ var id = $(this).attr('data-id');
+ if (id === regionsValue) {
+ found = true;
+ }
+ });
+
+ // If not found, Add the group
+ if (!found) {
+ $('#activeRegions').append('<div data-id="' + regionsValue
+ + '" class="glm-regions-dynSelect-item glm-members-regions">'
+ + regionsName.trim() + ' (ID: ' + regionsValue + ')' + '<span class="glm-dynSelect-delete regionDelete">X</span>'
+ + '<input type="hidden" name="group[' + regionsValue + ']" value="' + regionsValue + '"></div>');
+ }
+
+ // reset the id string after each set of iterations
+ regions_id_string = '';
+
+ $.each($(".glm-regions-dynSelect-item"), function () {
+ if($.inArray($(this).data("id"), regions_new_ids) === -1){
+ regions_new_ids.push($(this).data("id"));
+ }
+ });
+
+ // if more than one region id in the array, join together with ',' otherwise set the id string to a single value
+ if ( regions_new_ids.length > 1 ){
+ regions_id_string = regions_new_ids.join(',');
+ } else if ( regions_new_ids.length === 1 ) {
+ regions_id_string = regions_new_ids[0];
+ }
+
+ // replace the current content in either the visual or text editor and replace it with a filtered version of the regions
+ if ( $("#content").css("display") !== "none" ) {
+ editor_content = content.val();
+ if ( regions_empty_space ) {
+ editor_content = editor_content.replace( regions_id, 'region-search="' + regions_id_string + '"' );
+ content.val( editor_content );
+ } else if ( regions_missing ) {
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ editor_content = editor_content.replace( shortcodeReg, '$1 region-search="' + regions_id_string + '"$2' );
+ content.val( editor_content );
+ } else {
+ editor_content = editor_content.replace( 'region-search="' + regions_id, 'region-search="' + regions_id_string );
+ content.val( editor_content );
+ }
+ } else if ( tinyMCE.activeEditor !== null ) {
+ if ( regions_empty_space ) {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace(regions_id, 'region-search="' + regions_id_string + '"' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ } else if ( regions_missing ) {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ var regionsMatch = editor_content.match( shortcodeReg );
+ editor_content = editor_content.replace( shortcodeReg, '$1 region-search="' + regions_id_string + '"$2' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ } else {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string);
+ tinyMCE.activeEditor.setContent(editor_content);
+ }
+ }
+
+ // Reset picklist
+ $('#regions-scDropdown').val('Select Regions');
+ });
// Blank Start change event
// These fire when the blank-start select is changed
+ var blank_start_id, blank_start_missing, blank_start_empty_space;
$('#blank-start-scDropdown').change(function(){
- editor_shortcodes = get_tinymce_content();
- editor_content = content.val();
- if ( editor_shortcodes ) {
- if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) {
- blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1];
- if ( $("#content").css("display") !== "none" ) {
- editor_content = editor_content.replace( 'blank-start="' + blankStart +'"', 'blank-start="' + $(this).val() + '"' );
- } else if ( tinyMCE.activeEditor !== null ) {
- 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);
+ editor_shortcodes = get_tinymce_content();
+ if ( editor_shortcodes ) {
+ if ( editor_shortcodes.match( /glm-members-list blank-start="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ){
+ blank_start_missing = false;
+ blank_start_id = editor_shortcodes.match( /blank-start="(.*?)"/ )[1];
+
+ if ( blank_start_id !== "" ) {
+ blank_start_id = blank_start_id.split(',');
+
+ blank_start_id = blank_start_id.join(',');
+ blank_start_empty_space = false;
+ } else {
+
+ blank_start_id = 'blank-start=""';
+
+ // this determines if the groups option is blank "" to determine if the jquery replace method works properly
+ blank_start_empty_space = true;
}
} else {
+ blank_start_missing = true;
+ blank_start_empty_space = false;
+ }
+ }
+ if ( $("#content").css("display") !== "none" ) {
+ editor_content = content.val();
+ if ( blank_start_empty_space ) {
+ console.log("empty space");
+ editor_content = editor_content.replace( blank_start_id, 'blank-start="' + $(this).val() + '"' );
+ content.val( editor_content );
+ } else if ( blank_start_missing ) {
+ console.log("blank start");
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ var blankMatch = editor_content.match( shortcodeReg );
+ console.log(editor_content);
+ editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' );
+ content.val( editor_content );
+ console.log(blankMatch);
+ } else {
+ console.log("none");
+ editor_content = editor_content.replace( 'blank-start="' + blank_start_id, 'blank-start="' + $(this).val() );
+ content.val( editor_content );
+ }
+ } else if ( tinyMCE.activeEditor !== null ) {
+ if ( blank_start_empty_space ) {
+ console.log("empty");
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 blank-start="' + $(this).val() + '"$2' );
+ editor_content = editor_content.replace(blank_start_id, 'blank-start="' + $(this).val() + '"' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ } else if ( blank_start_missing ) {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ console.log(editor_content);
+ var blankMatch = editor_content.match( shortcodeReg );
+ editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ console.log(blankMatch);
+ } else {
+ console.log("none");
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace('blank-start="' + blank_start_id, 'blank-start="' + $(this).val() );
tinyMCE.activeEditor.setContent(editor_content);
}
}
// View dropdown
// These events fire when the View select is changed
+ var view_id, view_missing, view_empty_space;
$('#view-scDropdown').change(function(){
editor_shortcodes = get_tinymce_content();
- editor_content = content.val();
- if ( editor_shortcodes ) {
- if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) {
- memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1];
- if ( $("#content").css("display") !== "none" ) {
- editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' );
- } else if ( tinyMCE.activeEditor !== null ) {
- editor_content = tinyMCE.get('content').getContent({format: 'raw'});
- editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' );
- tinyMCE.activeEditor.setContent(editor_content);
+ if ( editor_shortcodes ) {
+ if ( editor_shortcodes.match( /glm-members-list view="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ){
+ view_missing = false;
+ view_id = editor_shortcodes.match( /view="(.*?)"/ )[1];
+
+ if ( view_id !== "" ) {
+ view_id = view_id.split(',');
+
+ view_id = view_id.join(',');
+ view_empty_space = false;
+ } else {
+
+ view_id = 'view=""';
+
+ // this determines if the groups option is blank "" to determine if the jquery replace method works properly
+ view_empty_space = true;
}
} else {
+ view_missing = true;
+ view_empty_space = false;
+ }
+ }
+ if ( $("#content").css("display") !== "none" ) {
+ editor_content = content.val();
+ if ( view_empty_space ) {
+ editor_content = editor_content.replace( view_id, 'view="' + $(this).val() + '"' );
+ content.val( editor_content );
+ } else if ( view_missing ) {
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' );
+ content.val( editor_content );
+ } else {
+ editor_content = editor_content.replace( 'view="' + view_id, 'view="' + $(this).val() );
+ content.val( editor_content );
+ }
+ } else if ( tinyMCE.activeEditor !== null ) {
+ if ( view_empty_space ) {
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 view="' + $(this).val() + '"$2' );
+ editor_content = editor_content.replace(view_id, 'view="' + $(this).val() + '"' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ } else if ( view_missing ) {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/;
+ var viewMatch = editor_content.match( shortcodeReg );
+ console.log(viewMatch);
+ editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' );
+ tinyMCE.activeEditor.setContent( editor_content );
+ } else {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace('view="' + view_id, 'view="' + $(this).val() );
tinyMCE.activeEditor.setContent(editor_content);
}
}
});
-
function insert_tag( text ) {
if ( tinyMCE && tinyMCE.activeEditor ) {
tinyMCE.activeEditor.selection.setContent(text);
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
+ var replace_me, replace_with;
$("[id$=generate]").on("click", function () {
- count = 0;
- if ( number_of_categories ) {
- count = number_of_categories;
- count++;
- } else {
- count++;
- }
// enforce the selection of a shortcode
if ( shortcodeDropdown ) {
// set up properties for shortcode lists
- 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 ) {
- listString += value + ",";
- });
-
- 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() {
- boxTarget = $(this).attr("class").slice(0, -7);
- return this.value;
- }).get();
-
- var detailString = '';
- detailValues.forEach( function( value ) {
- detailString += value + ",";
- });
- 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;
+ shortcodeString = '[' + shortcodeDropdown;
// populate the shortcode object with all of the shortcode attributes and their values
for (var key in shortcodeValues) {
}
}
}
-
+
// 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 || shortcodeString.match( /glm-members-list .* category="(.*?)"/ ) ) {
+ if(shortcodeString.match( /glm-members-list category="(.*?)"/ ) !== null ){
+ category_id = shortcodeString.match( /glm-members-list category="(.*?)"/ )[1];
+ } else 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);
+ replace_me = 'category="'+ids+'"';
+ replace_with = 'category="'+id_string+'"';
+ shortcodeString = shortcodeString.replace(replace_me, replace_with);
+ }
+ if( shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ ) ){
+ if( shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null ){
+ group_ids = shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ )[1];
+ } else if( shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null){
+ group_ids = shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ )[1];
+ }
+ group_ids = group_ids.split(',');
+ group_ids = group_ids.join(',');
+ replace_me = 'amenity-groups="'+group_ids+'"';
+ replace_with = 'amenity-groups="'+group_id_string+'"';
+ shortcodeString = shortcodeString.replace(replace_me, replace_with);
+ }
+ if( shortcodeString.match( /glm-members-list region-search="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){
+ if( shortcodeString.match( /glm-members-list region-search="(.*?)"/ ) !== null ){
+ regions_id = shortcodeString.match( /glm-members-list region-search="(.*?)"/ )[1];
+ }else if( shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){
+ regions_id = shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ )[1];
+ }
+ regions_id = regions_id.split(',');
+ regions_id = regions_id.join(',');
+ replace_me = 'region-search="'+regions_id+'"';
+ replace_with = 'region-search="'+regions_id_string+'"';
+ shortcodeString = shortcodeString.replace(replace_me, replace_with);
}
- shortcodeString += '] </div>';
+
+ shortcodeString += ']';
// insert shortcode at current cursor position
- if ( $("#content").css("display") !== "none" ) {
+ if ( $("#content").css("display") !== "none" ) {
var cursorPos = $('#content').prop( 'selectionStart' );
var v = $('#content').val();
var textBefore = v.substring(0, cursorPos );
* Deletes the shortcode.
*/
$('#glmRemoveShortCode').on('click', function(){
+
+ editor_shortcodes = get_tinymce_content();
+
var member_list_shortcodes = (editor_shortcodes.match(/glm-members-list/g) || []).length;
var member_package_shortcodes = (editor_shortcodes.match(/glm-members-packaging-list/g) || []).length;
if ( member_list_shortcodes ) {
- console.log( 'removing member list shortcode' );
// find the short code and remove it!
- editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ var shortcodeReg = /(\[glm-members-list .*?])/;
+ if ( $("#content").css("display") !== "none" ) {
+ editor_content = content.val();
+ editor_content = editor_content.replace( shortcodeReg, '' );
+ content.val( editor_content );
+ } else if ( tinyMCE.activeEditor !== null ) {
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace( shortcodeReg, '' );
+ tinyMCE.activeEditor.setContent(editor_content);
+ }
+
var shortcodeReg = /(\[glm-members-list .*?])/;
- editor_content = editor_content.replace( shortcodeReg, '' );
- tinyMCE.activeEditor.setContent(editor_content);
+
$('.glm-dynSelect-item').remove();
$('.glm-group-dynSelect-item').remove();
+ $('.glm-regions-dynSelect-item').remove();
$("#showDetail").hide();
$("#categoryBox").hide();
$("#showCategory").hide();
$("#packageListAttr").hide();
$('#shortcodeDropdown').val('glm-members-list');
window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected';
+ reset_options();
$('#shortcodeDropdown').change();
$('#shortcodeDropdown').show();
$('#activeCategories').hide();
$('#activeGroups').hide();
+ $('#activeRegions').hide();
+ ids, groups_id, regions_id, id_string, group_id_string, regions_id_string = '';
+ group_new_ids.length = 0;
+ new_ids.length = 0;
+ regions_new_ids.length = 0;
} else if ( member_package_shortcodes ) {
- console.log( 'removing member package list shortcode' );
// find the short code and remove it!
editor_content = tinyMCE.get('content').getContent({format: 'raw'});
var shortcodeReg = /(\[glm-members-packaging-list .*?])/;
$('#generate').show();
});
-
- //////////////////////////////////////////////////////////////////////////////////////
- // 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();
- if(editor_shortcodes && editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null){
- category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
+ if( (editor_shortcodes && editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null) || ( editor_shortcodes && editor_shortcodes.match(/glm-members-list .* category="(.*?)"/) !== null)){
+ if( editor_shortcodes.match(/glm-members-list category="(.*?)"/) ){
+ category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1];
+ } else {
+ category_id = editor_shortcodes.match(/glm-members-list .* category="(.*?)"/)[1];
+ }
+
category_id = category_id.split(',');
ids = category_id.join(',');
- }
+ }
$(this).parent().remove();
editor_content = tinyMCE.get('content').getContent({format: 'raw'});
editor_content = editor_content.replace('category="' + ids, 'category="' + id_string);
tinyMCE.activeEditor.setContent(editor_content);
-
}
+ });
+
+ $('.regionDelete').live('click', function() {
+ editor_shortcodes = get_tinymce_content();
+ if( (editor_shortcodes && editor_shortcodes.match(/glm-members-list region-search="(.*?)"/) !== null) || (editor_shortcodes && editor_shortcodes.match(/glm-members-list .* region-search="(.*?)"/) !== null) ){
+ if(editor_shortcodes.match(/glm-members-list region-search="(.*?)"/) ){
+ regions_id = editor_shortcodes.match(/glm-members-list region-search="(.*?)"/)[1];
+ } else {
+ regions_id = editor_shortcodes.match(/glm-members-list .* region-search="(.*?)"/)[1];
+ }
+ regions_id = regions_id.split(',');
+ regions_id = regions_id.join(',');
+ }
+
+ $(this).parent().remove();
+
+ // reset the array after each set of iterations
+ regions_new_ids.length = 0;
+
+ $.each($(".glm-regions-dynSelect-item"), function () {
+ if($.inArray($(this).data("id"), regions_new_ids) === -1){
+ regions_new_ids.push($(this).data("id"));
+ }
+ });
+
+ // create a string of id's from the array
+ regions_id_string = regions_new_ids.join(',');
+
+ // get and replace current editor content
+ if($("#content").css("display") !== "none"){
+
+ editor_content = content.val();
+ editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string );
+ content.val(editor_content);
+ } else if(tinyMCE.activeEditor !== null){
+
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string);
+ tinyMCE.activeEditor.setContent(editor_content);
+ }
});
// group delete
groups_id = editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/)[1];
groups_id = groups_id.split(',');
group_ids = groups_id.join(',');
+ } else 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(',');
+ group_ids = groups_id.join(',');
}
$(this).parent().remove();
});
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // MAINENANCE these were necessary to reset the dropdowns but most of them are no longer needed
// reset dropdowns and checkboxes to default values on page reload
var scd = document.getElementById('shortcodeDropdown');
var catscd = document.getElementById('category-scDropdown');
var members = document.getElementById('member-scDropdown');
var view = document.getElementById('view-scDropdown');
var groups = document.getElementById('amenitygroup-scDropdown');
+ var regions = document.getElementById('region-search-scDropdown');
if ( editor_shortcodes && number_of_categories) {
if ( number_of_categories ) {
$('#shortcodeDropdown').change();
$('#shortcodeDropdown').hide();
}
- if ( scd && !editor_shortcodes && !number_of_categories) {
- window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected';
- }
- if ( catscd ) {
- window.onload = document.getElementById('category-scDropdown').options[0].selected = 'selected';
- }
- if ( blank ) {
- if ( blankStart ) {
- $('#blank-start-scDropdown').val( blankStart );
- } else {
- window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
+ function reset_options(){
+ if ( scd && !editor_shortcodes && !number_of_categories) {
+ window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected';
}
- }
- if ( list ) {
- window.onload = document.getElementById('type-scList').options[0].selected = 'selected';
- }
- if ( members ) {
- window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected';
- }
- if ( view ) {
- if ( memberView ) {
- $('#view-scDropdown').val( memberView );
- } else {
- window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
+ if ( catscd ) {
+ window.onload = document.getElementById('category-scDropdown').options[0].selected = 'selected';
+ }
+ if ( blank ) {
+ if ( blankStart ) {
+ $('#blank-start-scDropdown').val( blankStart );
+ } else {
+ window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected';
+ }
+ }
+ if ( list ) {
+ window.onload = document.getElementById('type-scList').options[0].selected = 'selected';
+ }
+ if ( members ) {
+ window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected';
+ }
+ if ( view ) {
+ if ( memberView ) {
+ $('#view-scDropdown').val( memberView );
+ } else {
+ window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
+ }
+ }
+ if ( groups ) {
+ window.onload = document.getElementById('amenitygroup-scDropdown').options[0].selected = 'selected';
+ }
+ if ( regions ) {
+ window.onload = document.getElementById('region-search-scDropdown').options[0].selected = 'selected';
}
}
- if ( groups ) {
- window.onload = document.getElementById('amenitygroup-scDropdown').options[0].selected = 'selected';
- }
+ reset_options();
});