jQuery(document).ready(function ($) {
'use strict';
-
+
var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString,
- editor_shortcodes, category_id;
- var shortcodeValues = {};
+ editor_shortcodes, category_id, shortcodeValues = {};
+
$("#showDetail").hide();
$("#categoryBox").hide();
$("#showCategory").hide();
$(".scCategories").hide();
// reset checkboxes after page load
- function uncheckAll() {
- var w = document.getElementsByTagName('input');
- for (var i = 0; i < w.length; i++){
- if(w[i].type === 'checkbox'){
- w[i].checked = false;
- }
- }
- }
+// function uncheckAll() {
+// var w = document.getElementsByTagName('input');
+// for (var i = 0; i < w.length; i++){
+// if(w[i].type === 'checkbox'){
+// w[i].checked = false;
+// }
+// }
+// }
+ var shortcode = $("#shortcode_container").not('.glm-dynSelect-item'), clone, id_count;
+ id_count = 0;
+// $("#additionalShortcode").on( "click", function () {
+// id_count++;
+// clone = shortcode.clone(true);
+// clone.find("#shortcodeDropdown").attr("id", "shortcodeDropdown" + "_" + id_count);
+// clone.find(".glm-dynSelect-item").remove();
+// clone.find("#generate").attr("id", "generate" + "_" + id_count);
+// clone.insertAfter("#shortcode_container:last");
+//
+// });
+
+
+ /////////////////////////////////////////////////////////////////////////////////////////
+ // CHANGE MAIN SHORTCODE
+ /////////////////////////////////////////////////////////////////////////////////////////
// fire core events and reset settings when switching between shortcodes
- $("#shortcodeDropdown").on("change", function () {
+ $("[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)
if($('#id-scDropdown').length)
document.getElementById('id-scDropdown').options[0].selected = 'selected';
- uncheckAll();
+// uncheckAll();
// delete the object properties to reset the object
shortcodeString = "";
}
// get the shortcode option name and hide / show necessary elements
- shortcodeDropdown = $("#shortcodeDropdown option:selected").val();
+ shortcodeDropdown = $(".shortcodeDropdown option:selected").val();
if(shortcodeDropdown === "glm-members-list"){
$("#showCategory").show();
$(".scCategories").show();
}
- if(shortcodeDropdown === "glm-member-detail") {
- $("#detailBtn").show();
- $("#showCategory").hide();
- $("#blank-start-scDropdown").show();
- $("#category-scDropdown").hide();
- $("#id-scDropdown").hide();
- $("[id^='packageList']").hide();
- $("#view-scDropdown").hide();
- }
-
if(shortcodeDropdown === "glm-members-packaging-list"){
$("#blank-start-scDropdown").hide();
$("#showCategory").hide();
$("#view-scDropdown").hide();
$(".scCategories").hide();
}
-
- if (shortcodeDropdown === "glm-members-packaging-detail"){
- $("#blank-start-scDropdown").hide();
- $("#showCategory").hide();
- $("#category-scDropdown").hide();
- $("#detailBtn").hide();
- $("#id-scDropdown").show();
- $("[id^='packageList']").hide();
- $("#view-scDropdown").hide();
- }
- if (shortcodeDropdown === "glm-members-event-list"){
- $("#blank-start-scDropdown").hide();
- $("#showCategory").hide();
- $("#category-scDropdown").hide();
- $("#detailBtn").hide();
- $("[id^='packageList']").hide();
- $("#id-scDropdown").hide();
- $("#view-scDropdown").hide();
- }
- if (shortcodeDropdown === "glm-members-event-detail"){
- $("#blank-start-scDropdown").hide();
- $("#showCategory").hide();
- $("#category-scDropdown").hide();
- $("#detailBtn").hide();
- $("[id^='packageList']").hide();
- $("#id-scDropdown").hide();
- $("#view-scDropdown").hide();
- $("#view-scDropdown").hide();
- }
- if (shortcodeDropdown === "glm-members-event-front-add"){
- $("#blank-start-scDropdown").hide();
- $("#showCategory").hide();
- $("#category-scDropdown").hide();
- $("#detailBtn").hide();
- $("[id^='packageList']").hide();
- $("#id-scDropdown").hide();
- $("#view-scDropdown").hide();
- }
- });
+ });
+
+
+
+
+
+
+ ////////////////////////////////////////////////////////////////////
+ // GET ATTRIBUTES
+ /////////////////////////////////////////////////////////////////////
// shortcode attribute name from dropdowns containing '-scDropdown' in their ID
// Then append the values to the shortcode object
$("[id$=-scDropdown]").on("change", function () {
$("#showDetail").dialog().dialog("option", "width", 422);
});
+// var regExp = /\[([^)]+)\]/;
+ var regExp = /glm_members_list_/g;
function get_tinymce_content(){
if (jQuery("#wp-content-wrap").hasClass("tmce-active")){
- var regExp = /\[([^)]+)\]/;
-
tinyMCE.triggerSave();
if(regExp.exec($('#content').val())){
} else {
// get the shortcode from the editor with [ ] as the delimiters
- var regExp = /\[([^)]+)\]/;
+
var editorContent = regExp.exec($("#content").val());
// getting an array as the value from the previous reExp, will need to investigate
return editorContent[0];
}
}
- }
+ }
editor_shortcodes = get_tinymce_content();
- console.debug(editor_shortcodes);
+ if(editor_shortcodes){
+
+ var number_of_categories = (editor_shortcodes.match(/category="(.*?)"/g) || []).length;
+
+ }
+ console.debug(number_of_categories);
+
+ console.debug(editor_shortcodes);
if(editor_shortcodes){
if(editor_shortcodes.match(/category="(.*?)"/) !== null){
category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
+// console.debug(category_id);
+// var cat_id_array = [];
+// $.each(category_id, function (key, value) {
+// cat_id_array.push(value.match(/"(.*?)"/)[1]);
+// });
+
category_id = category_id.split(',');
+
+ } else if (editor_shortcodes.match(/category=""/) !== null){
+ category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
}
}
}
+
+
+
+
+
+
+ /////////////////////////////////////////////////////////////////////////////////////////////
/*
* Category Selection
*/
- var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), editor_content;
-
+ //////////////////////////////////////////////////////////////////////////////////////////////
+ var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), editor_content, 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(/category="(.*?)"/)[1];
- category_id = category_id.split(',');
- ids = category_id.join(',');
- editor_category_index = editor_shortcodes.indexOf('category=');
+
+ if(category_id !== ""){
+ category_id = category_id.split(',');
+
+ ids = category_id.join(',');
+ empty_space = false;
+ } else {
+
+ ids = 'category=""';
+ empty_space = true;
+ }
}
}
}
});
- // Check if there's a parent
-// parentName = '';
-// if (catParent !== '') {
-// parentName = catParent + ': ';
-// }
// If not found, Add the category
if (!found) {
}
id_string = '';
+
$.each($(".glm-dynSelect-item"), function () {
if($.inArray($(this).data("id"), new_ids) === -1){
new_ids.push($(this).data("id"));
}
- });
-
- id_string = new_ids.join(',');
-
+ });
+
+ if ( new_ids.length > 1){
+ id_string = new_ids.join(',');
+ } else if ( new_ids.length === 1) {
+ id_string = new_ids[0];
+ }
+
if($("#content").css("display") !== "none"){
editor_content = content.val();
- editor_content = editor_content.replace(ids, id_string);
- content.val(editor_content);
+ if(empty_space){
+ editor_content = editor_content.replace(ids, 'category="' + id_string + '"');
+ content.val(editor_content);
+ } else {
+ 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(ids, id_string);
- tinyMCE.activeEditor.setContent(editor_content);
+ if(empty_space){
+ editor_content = tinyMCE.get('content').getContent({format: 'raw'});
+ editor_content = editor_content.replace(ids, 'category="' + id_string + '"' );
+ 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');
});
+
+ function insert_tag(text){
+ if(tinyMCE && tinyMCE.activeEditor)
+ {
+ tinyMCE.activeEditor.selection.setContent(text);
+ }
+ return false;
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////
+ // INSERT SHORTCODE FUNCTION
+ /////////////////////////////////////////////////////////////////////////////////////////////////
// generate the shortcode into a string and insert into the content upon clicking
- $("#generate").on("click", function () {
+ $("[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 + ",";
- });
+ 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;
}
}
// start the shortcode string that will be added to the tinymce editor
- shortcodeString = "[" + shortcodeDropdown;
+ shortcodeString = '<div class="previewCodes" id="' + shortcodeDropdown + '_' + count + '"> [' + shortcodeDropdown;
// populate the shortcode object
for (var key in shortcodeValues) {
ids = category_id.join(',');
shortcodeString = shortcodeString.replace(ids, id_string);
}
- shortcodeString += ']';
+ shortcodeString += '] </div>';
// insert shortcode at current cursor position
if($("#content").css("display") !== "none"){
$('#content').val( textBefore + shortcodeString + textAfter );
} else if($("#content").css("display") === "none") {
- function insert_tag(text){
- if(tinyMCE && tinyMCE.activeEditor)
- {
- console.log(tinyMCE.activeEditor.id);
- tinyMCE.activeEditor.selection.setContent(text);
- }
- return false;
- }
+
insert_tag(shortcodeString);
}
} else {
}
});
+
+
+
+
+
+
+ /////////////////////////////////////////////////////////////////
+ // DELETE 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.match(/category="(.*?)"/) !== null){
+ if(editor_shortcodes && editor_shortcodes.match(/category="(.*?)"/) !== null){
category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
category_id = category_id.split(',');
ids = category_id.join(',');
- }
+ }
$(this).parent().remove();
new_ids.push($(this).data("id"));
}
});
-
+
id_string = new_ids.join(',');
-
+
if($("#content").css("display") !== "none"){
+
editor_content = content.val();
- editor_content = editor_content.replace(ids, id_string);
+ 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(ids, id_string);
+ editor_content = editor_content.replace('category="' + ids, 'category="' + id_string);
tinyMCE.activeEditor.setContent(editor_content);
+
}
+
});
+
+
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // MAINENANCE
// reset dropdowns and checkboxes to default values on page reload
var scd = document.getElementById('shortcodeDropdown');
var catscd = document.getElementById('category-scDropdown');
if(view){
window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
}
- window.onload = uncheckAll();
-
-
-});
\ No newline at end of file
+// window.onload = uncheckAll();
+});
+
{
public $prefixSlugs = array();
public $requiredPages = array();
+// s
/**
* WordPress Database Object
*
parent::__construct(false, false);
}
- public function updateRequiredPages(){
+ public function updateRequiredPages(){
$this->requiredPages = array();
+// $this->reqPageTitlesStatic = array();
foreach ($this->config['addOns'] as $a) {
if (isset($a['requiredPages'])) {
foreach($a['requiredPages'] as $pageName => $pageData) {
+// $this->reqPageTitlesStatic[] = strtolower(str_replace(" ","-",$pageName));
$pageID = get_option(GLM_MEMBERS_PLUGIN_OPTION_PREFIX.$pageData['underscored_title']);
$this->prefixSlugs[] = GLM_MEMBERS_PLUGIN_OPTION_PREFIX.$pageData['underscored_title'];
$this->requiredPages[$a['underscored_name']][$pageName]['id'] = $pageID;
$page = get_post($pageID);
$this->requiredPages[$a['underscored_name']][$pageName]['slug'] = $page->post_name;
$this->requiredPages[$a['underscored_name']][$pageName]['title'] = $page->post_title;
+ $this->requiredPages[$a['underscored_name']][$pageName]['static_name'] = strtolower(str_replace(" ","-",$pageName));
}
}
}
$settingsUpdated = false;
$settingsUpdateError = false;
$requiredPagesUpdateError = false;
- $idError = false;
- $titleError = false;
+ $id_error = false;
+ $title_error = false;
// General settings are always stored in a record with ID=1.
$id = 1;
// Check for submission option
$option = '';
- if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'submit') {
+ if ( isset( $_REQUEST[ 'option' ] ) && $_REQUEST[ 'option' ] == 'submit' ) {
$option = $_REQUEST['option'];
}
$this->updateRequiredPages();
- switch($option) {
+ switch( $option ) {
// Update General Settings and redisplay the form
case 'submit':
-
- // get all of the IDs from the form
- $requiredPagesIDs = array_intersect_key($_REQUEST, array_flip(preg_grep('/^glm_members_database_id/', array_keys($_REQUEST))));
+ foreach ( $this->config[ 'addOns' ] as $a ) {
+ if ( isset( $a[ 'requiredPages' ] ) ) {
+ foreach( $a[ 'requiredPages'] as $pageName => $pageData ) {
+
+ $current_page_id_value = get_option( GLM_MEMBERS_PLUGIN_OPTION_PREFIX.$pageData[ 'underscored_title' ] );
- foreach($requiredPagesIDs as $id){
- $page = get_post($id);
- $pageTitle = $page->post_title;
- $pageSlug= $page->post_name;
- $slug = 'glm_members_database_option_' . $pageSlug;
- $postValueTitle = filter_var($_POST[$slug], FILTER_SANITIZE_STRING);
- if($pageTitle != $postValueTitle && !empty($postValueTitle)){
- $args = array (
- 'ID' => $id,
- 'post_title' => $postValueTitle
- );
- wp_update_post($args);
- } else if($pageTitle == $postValueTitle) {
-
- } else if(empty($postValueTitle)){
- $settingsUpdateError = true;
- $settingsUpdated = false;
- $titleError = true;
- }
- }
+ $page_title_field_name = 'glm_members_database_title_' . $this->requiredPages[ $a[ 'underscored_name'] ][ $pageName ][ 'static_name' ];
+ $page_id_field_name = 'glm_members_database_id_' . $this->requiredPages[ $a[ 'underscored_name' ] ][ $pageName ][ 'static_name' ];
+
+ $page_option_slug = GLM_MEMBERS_PLUGIN_OPTION_PREFIX.$pageData['underscored_title'];
- foreach($this->prefixSlugs as $slug){
- $id = get_option($slug);
- $pageTitle = $page->post_title;
- $page = get_post($id);
- $pageSlug = $page->post_name;
- $titleSlug = 'glm_members_database_option_' . $pageSlug;
- $pageSlug = 'glm_members_database_id_' . $pageSlug;
- $formID = filter_var($_POST[$pageSlug], FILTER_SANITIZE_STRING);
- $formTitle = filter_var($_POST[$titleSlug], FILTER_SANITIZE_STRING);
- if($id != $formID && get_post_status($formID) != false && is_numeric($formID)){
- update_option($slug, $formID);
- } else if($id == $formID && is_numeric($formID)) {
- update_option($slug, $id);
- } else {
- $settingsUpdateError = true;
- $settingsUpdated = false;
- $idError = true;
- }
+ $current_page_title_value = $this->requiredPages[ $a[ 'underscored_name' ] ][ $pageName][ 'title' ];
+
+ if( isset( $_POST[ $page_title_field_name ] ) && ! empty( $_POST[ $page_title_field_name ] ) ){
+ $new_page_title_value = filter_var($_POST[$page_title_field_name], FILTER_SANITIZE_STRING);
+ } else {
+ $title_error = true;
+ }
+
+ if( isset( $_POST[ $page_id_field_name ] ) && !empty( $_POST[ $page_id_field_name ] ) && is_numeric( $_POST[ $page_id_field_name ] ) ){
+ $new_page_id_value = filter_var( $_POST[ $page_id_field_name ], FILTER_SANITIZE_STRING );
+ } else {
+ $id_error = true;
+ }
+
+ if( $current_page_title_value !== $new_page_title_value ){
+ $args = array (
+ 'ID' => $current_page_id_value,
+ 'post_title' => $new_page_title_value,
+ );
+ wp_update_post( $args );
+ }
+
+ // ensure the new page id exists and the field is not empty
+ if($current_page_id_value !== $new_page_id_value && get_post_status( $new_page_id_value ) ){
+ update_option( $page_option_slug, $new_page_id_value );
+ } else {
+
+ }
+ }
+ }
}
-
+
$this->updateRequiredPages();
-
+
// Required Pages
$requiredPagesUpdateError = false;
- if (isset($_REQUEST[GLM_MEMBERS_PLUGIN_OPTION_MEMBERS_LIST_ID]) ){
- $membersListIdOption = $requiredPages['glm-member-db']['members_list'][''];
- $newMembersListId = $_REQUEST[$membersListIdOption];
+ if ( isset( $_REQUEST[ GLM_MEMBERS_PLUGIN_OPTION_MEMBERS_LIST_ID ] ) ){
+ $membersListIdOption = $requiredPages[ 'glm-member-db' ][ 'members_list' ][''];
+ $newMembersListId = $_REQUEST[ $membersListIdOption ];
+ } else {
+
}
+ echo $_REQUEST[ 'glm_members_database_option_member-detail' ];
+ echo $newMembersListId;
$results = $this->wpdb->get_results( "SELECT ID FROM ".$this->wpdb->posts." WHERE ID = ".$newMembersListId);
- if (get_option($membersListIdOption) == $newMembersListId) {
+ if ( get_option( $membersListIdOption) == $newMembersListId ) {
$requiredPagesUpdateError = false;
- } else if (is_numeric($newMembersListId)) {
- if ($results) {
+ } else if ( is_numeric( $newMembersListId ) ) {
+ if ( $results ) {
$requiredPagesUpdateError = false;
} else {
$requiredPagesUpdateError .= "\n Page ID $newMembersListId does not exist. ";
// Update all general setttings
$generalSettings = $this->updateEntry(1);
- if ($generalSettings['status']) {
+ if ( $generalSettings[ 'status' ]) {
$settingsUpdated = true;
} else {
$settingsUpdateError = true;
default:
// Try to get the first (should be only) entry for general settings.
- $generalSettings = $this->editEntry($id);
+ $generalSettings = $this->editEntry( $id );
if ($generalSettings === false) {
- if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG ) {
glmMembersAdmin::addNotice("<b> /modesl/admin/settings/index.php: Unable to load General Settings.", 'Alert');
}
-
}
break;
}
- if($settingsUpdateError){
+ if( $settingsUpdateError ){
$settingsUpdated = false;
}
// Compile template data
'settingsUpdated' => $settingsUpdated,
'settingsUpdateError' => $settingsUpdateError,
'requiredPages' => $this->requiredPages,
- 'idError' => $idError,
- 'titleError' => $titleError,
+ 'id_error' => $id_error,
+ 'title_error' => $title_error,
'requiredPagesUpdateError' => $requiredPagesUpdateError
);
'view' => 'admin/management/index.html',
'data' => $templateData
);
-
}
-
}
?>
\ No newline at end of file