File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/javascript/admin.lists.js
// ----- Global variables ----- //
var StaticListTreeOptions = {
dropOn: ".GridPanel",
placeholder: 'listsSortableTreePlaceholder',
tabSize: 20,
maxDepth: 3,
maxDepthError: 'ui-tree-deptherror',
maxDepthErrorText: ' ',
maxItems: [7000],
maxItemsError: 'ui-tree-limiterror',
maxItemsErrorText: 'You have reached the maximum number of items for this level!',
handle: '.sort-handle, .sort-handle img'
};
var ajaxFormOptions = {
success: showResponse,
beforeSend: beforeSendPost,
dataType: 'xml'
};
function beforeSendPost() {
if(this.data.indexOf('matchtype=and') == -1 && this.data.indexOf('matchtype=or') == -1 ) {
var matchType = $('.matchselect').val();
matchType = matchType.toLowerCase();
this.data = this.data.replace('matchtype=', 'matchtype=' + matchType);
}
if($('#list_static:checked').exists()){
// validate that they inserted correct links and text
if($('#staticListlinksList .staticFieldText[value=""]').exists() || $('#staticListlinksList .staticFieldText[value="' + defaultStaticLinkText + '"]').exists()){
alert('You did not enter text for one or more links.');
return false;
}
if($('#staticListlinksList .staticFieldURL[value=""]').exists() || $('#staticListlinksList .staticFieldURL[value="' + defaultStaticLinkUrl + '"]').exists()){
alert('You did not enter a URL for one or more links.');
return false;
}
this.data = this.data + '&' + $('#staticListlinksList').tree("serialize");
}else if($('#list_dynamic:checked').exists() && $('#list_content:checked').exists()) {
if(!$('.SelectedRow input:checked').exists()) {
alert('You need to choose at least one content type first.');
return false;
}
}
}
/**
* showResponse
* This function is the callback function used after a successful return from the ajax form submission
*/
function showResponse(xml, statusText) {
if($('status', xml).text() == 1){
$('#listid').val($('listid', xml).text());
if ($('redirect', xml).text() == 1) {
location.href = "index.php?section=lists&action=view";
} else {
// we have to html encode the listname since we're building the message string client-side
var listname = $('<div></div>').text($('listname', xml).text()).html();
var msg = iwp.lang.get('ListSaveSuccessfully').replace('%s', listname);
$('#MainMessage').successMessage(msg);
}
}else if($('status', xml).text() == 0){
$('html').scrollTo( 'body', 500 );
var errors = $('message', xml).text();
setTimeout("$(\"#MainMessage\").errorMessage(\""+iwp.lang.get('ErrorSavingList')+" \"," +errors+ ");", 5);
setTimeout("EmptyFields(" +$('errorfields', xml).text()+ ");", 5);
}
}
/**
* CheckTemplateOptions
* This function checks the template option radio fields and determines whether or not additional options need to be shown
*/
function CheckTemplateOptions(){
var selectedOption = $('input:checked[name=template_type]').attr('id');
if(selectedOption == 'template_default'){
$('#templateBlockList').hide();
}else{
$('#templateBlockList').show();
}
}
/**
* CheckFieldsToShow
* Checks which of the 'List Type' (dyanmic, static, rss) radio fields are selected and hides/shows the field divs based on this value
*/
function CheckFieldsToShow(){
var option = $('input:checked[name=list_type]').attr('id');
$('.dynamic_fields').hide();
$('#static_fields').hide();
$('#filter_options').hide();
$('#rss_fields').hide();
$('#list_options').hide();
$('#limitnumber').show();
$('#itemnumbertype').show();
if(option == 'list_dynamic'){
$('.dynamic_fields').show();
$('.dynamic_help').hide();
$('#filter_options').show();
$('#list_options').show();
return;
}
if(option == 'list_static'){
$('#static_fields').show();
$('.dynamic_help').show();
$('#limitnumber').hide();
$('#itemnumbertype').hide();
return;
}
if(option == 'list_rss'){
$('#rss_fields').show();
$('.dynamic_help').show();
return;
}
}
/**
* CheckListConsists
* This checks to see what type of data is selected (content,comments,categories or users) to populate the drop down lists appropriately and display any additional fields.
*
* @param boolean ignoreNewField This flags whether or not a new filter should be added or not. When editing, usually we don't want a blank one added, but we do when creating or switching datatype
*/
function CheckListConsists(ignoreNewField){
if(typeof(ignoreNewField) == 'undefined'){
var ignoreNewField = false;
}
var option = $('input:checked[name=list_consists]').attr('id');
if(option == currentContentDataType) {
// they clicked on the same field they were already on
return;
}
$('#category_options').hide();
$('#contentTypeListDiv').hide();
currentContentDataType = option;
if(option == 'list_categories'){
$('#category_options').show();
$('#filter_list').html('');
if(!ignoreNewField){
AddFilter();
}
PopulateList('.filter_select_field', CategoryFields);
PopulateList('#orderbyfield', CategoryFields);
$('#orderbyfield').selectOptions(DefaultSelectedCategoryField, true);
if(!ignoreNewField){
$('#orderbydirection').selectOptions(DefaultCategoryOrder, true);
}
return;
}
if(option == 'list_users'){
$('#filter_list').html('');
if(!ignoreNewField){
AddFilter();
}
PopulateList('.filter_select_field', UserFields);
PopulateList('#orderbyfield', UserFields);
$('#orderbyfield').selectOptions(DefaultSelectedUserField, true);
if(!ignoreNewField){
$('#orderbydirection').selectOptions(DefaultUserOrder, true);
}
return;
}
if(option == 'list_content'){
$('#filter_list').html('');
if(!ignoreNewField){
AddFilter();
}
PopulateList('.filter_select_field', ContentFields);
PopulateList('#orderbyfield', ContentFields);
// remove the start date field from a filters (keeping it as a sortable field)
// the visibility code already adds a condition for start date
// and the date picker field has not bee implemented for filters
$('.filter_select_field option[value=startdate]').remove();
$('#contentTypeListDiv').show();
$('#orderbyfield').selectOptions(DefaultSelectedContentField, true);
if(!ignoreNewField){
$('#orderbydirection').selectOptions(DefaultContentOrder, true);
}
return;
}
}
/**
* Populate List
* Takes two paramaters, first is the id of a list box, the second is an option list to put into the list
*/
function PopulateList(list, options){
$(list).removeOption(/./);
$(list).addOption(options, false);
}
/**
* AddFilter
* This function adds a new filter row where the user can select the field and filter options
*/
function AddFilter(appendId){
if(typeof(appendId) == 'undefined'){
var appendId = 0;
}
var newFilter = $('#filterOptionBase').html();
var filterid = filterCounter;
newFilter = newFilter.replace(/_id/g, filterCounter);
if(appendId == 0){
$('#filter_list').append('<div id="list_filter_' +filterCounter + '">' + newFilter + '</div>');
}else{
$('#list_filter_'+appendId).after('<div id="list_filter_' +filterCounter + '">' + newFilter + '</div>');
}
if($('#filter_list div').size() > 1){
$('#filter_list .remove_filter_class').show();
}
if($('#filter_list div').size() < 2){
$('#filter_list .remove_filter_class').hide();
}
$('#field_select'+filterCounter).attr('name', 'filter_field['+filterCounter+']');
filterCounter++;
return filterid;
}
/**
* RemoveFilter
* This function removes a filter based on an input number
*
* @param number optionNumber This is the ID number of the row to be removed
*/
function RemoveFilter(optionNumber, updateContentTypeList, skipLastFilterCheck){
if (typeof skipLastFilterCheck == 'undefined') {
var skipLastFilterCheck = false;
}
if(!skipLastFilterCheck && $('#filter_list div').size() < 2){
alert(iwp.lang.get('NotRemoveLastFilter'));
return;
}
if(!iwp.util.isDefined(updateContentTypeList)){
var updateContentTypeList = false;
if($('#field_select' + optionNumber).selectedValues() == 'contenttype'){
updateContentTypeList = true;
}
}
$('#list_filter_'+optionNumber).remove();
if($('#filter_list div').size() < 1){
$('#filter_list .remove_filter_class').hide();
}
if(updateContentTypeList){
UpdateContentTypeListFromFilters();
}
}
function UpdateMatchType(text){
$('.matchselect').selectOptions(text.toLowerCase(),true);
$('#matchtype_hidden').val(text.toLowerCase());
}
/**
* CheckFilterField
* This function checks the drop down box for a specified filter option to check what other options should be displayed
*/
function CheckFilterField(filterid){
var fieldValue = '';
var tmp = '';
var split = '';
var contentName = '';
if(currentContentDataType == 'list_categories'){
contentName = 'category';
}else{
contentName = currentContentDataType.replace('list_', '');
}
fieldValue = $('#field_select' + filterid).selectedValues()[0];
if($('#filter_action'+filterid).exists()){
$('#filter_action'+filterid).remove();
}
if($('#filter_value'+filterid).exists()){
$('#filter_value'+filterid).remove();
}
$('#field_select'+filterid).after('<select id="filter_action'+filterid+'" name="filter_action['+filterid+']" class="Field150 filter_action"></select>');
if(ValueField[contentName][fieldValue] == 'textbox') {
$('#filter_action'+filterid).after('<input id="filter_value'+filterid+'" name="filter_value['+filterid+']" class="Field150 filter_value" type="text" />');
} else if(ValueField[contentName][fieldValue].substr(0,13) == 'remote_select') {
split = ValueField[contentName][fieldValue].split(":");
$('#filter_action'+filterid).after('<select id="filter_value'+filterid+'" name="filter_value['+filterid+']" class="Field150 filter_value"></select>');
if($('#field_select'+filterid).selectedValues() == 'contenttype' && countObject(objContentTypeList) > 0){
var addOptionData = {};
for (i in objContentTypeList){
addOptionData[i] = objContentTypeList[i];
}
$('#filter_value'+filterid).addOption(addOptionData,false);
}else{
$.getJSON('remote.php?'+split[1],
function(data){
$('#filter_value'+filterid).addOption(data,false);
if($('#field_select'+filterid).selectedValues() == 'contenttype'){
objContentTypeList = data;
}
}
);
}
if($('#field_select'+filterid).selectedValues() == 'contenttype') {
$('#filter_value'+filterid).bind('change', function(){
UpdateContentTypeListFromFilters();
});
$('#field_select'+filterid).bind('change', function(){
if($(this).selectedValues() != 'contenttype'){
$(this).unbind('change');
}
UpdateContentTypeListFromFilters();
});
}
}else if(ValueField[contentName][fieldValue] == 'datepicker'){
$('#filter_action'+filterid).after('<input id="filter_value'+filterid+'" name="filter_value['+filterid+']" class="Field150 filter_value date-pick-'+filterid+'" type="text" />');
$('.date-pick-'+filterid).datePicker({ clickInput:true,startDate: '01/01/1900', endDate: '01/01/8000' }).val(new Date().asString()).trigger('change');
}
addOptions = {};
var name = '';
for(i=0;i<TypeList[contentName][fieldValue].length;i++){
name = TypeList[contentName][fieldValue][i];
addOptions[name] = ActionLangList[name];
}
if(addOptions.length > 1){
$('#filter_action'+filterid).addOption({'0': iwp.lang.get('ListPleaseSelect')}, false);
}
$('#filter_action'+filterid).addOption(addOptions, false);
}
/**
* This function takes the list of content types that have filters and ensures the right ones are checked on the main tab
*/
function UpdateContentTypeListFromFilters(){
var listIds = [];
$('#filter_list div').each(function() {
var thisId = $(this).attr('id');
thisId = thisId.replace('list_filter_', '');
if($(this).children('.filter_select_field').val() == 'contenttype'){
if($(this).children('.filter_value').val() > 0){
listIds.push($(this).children('.filter_value').val());
}
}
});
$('#contentTypeList input:checked').each(function(){
$(this).attr('checked', false);
$(this).parent().removeClass('SelectedRow');
});
$('#contentTypeList input:checkbox').each(function(){
var tmpId = $(this).attr('id');
tmpId = tmpId.replace('ISelector_id__', '');
if(in_array($(this).val(), listIds)){
$('#ISelector_'+tmpId).trigger('click');
}
});
}
function TogglestaticListLinkWindow(id){
if($('#staticListNewWindow-'+id).val() == 'no'){
$('#staticListNewWindow-'+id).val('yes');
$('#linkNewWindow_'+id).attr('src', 'images/windownew.png');
}else{
$('#staticListNewWindow-'+id).val('no');
$('#linkNewWindow_'+id).attr('src', 'images/windowsame.png');
}
}
function DeleteStaticListLink(id){
if($('#staticListlinksList li').size() < 2){
alert(iwp.lang.get('ListNotRemoveLastLink'));
return;
}
if(!confirm(iwp.lang.get('ConfirmDeleteStaticLink'))){
return;
}
$('#staticListText-'+id).remove();
$('#staticListUrl-'+id).remove();
$('#linkNewWindow_'+id).remove();
animate_color('staticListOrder_'+id+ ' table tr td', 'red');
setTimeout("$('#staticListOrder_"+id+"').remove();$('#staticListlinksList').tree( 'destroy' );$('#staticListlinksList').tree(StaticListTreeOptions); if($('#staticListlinksList li').size() < 2){ $('#staticListlinksList .remove_link_class').hide(); }", 150);
// $('#MainMessage').warningMessage('The link has been removed but you will need to save the list for the changes to take effect.');
}
function AddstaticListLinkAfter(afterId,text,url,newwindow,itemid, parentid, updateLinkSortOrder){
AddstaticListLink(text,url,newwindow,itemid, parentid, updateLinkSortOrder, afterId);
}
function AddstaticListLink(text,url,newwindow,itemid, parentid, updateLinkSortOrder, afterId){
if(typeof(text) == 'undefined'){
text = defaultStaticLinkText;
}
if(typeof(itemid) == 'undefined'){
updateLinkSortOrder = true;
}
if(typeof(itemid) == 'undefined'){
itemid = -1;
var dbId = 0;
}else{
var dbId = itemid;
itemid = -1;
}
if(typeof(parentid) == 'undefined'){
parentid = -1;
}
if(typeof(url) == 'undefined'){
url = defaultStaticLinkUrl;
}
if(typeof(newwindow) == 'undefined'){
newwindow = "no";
}
linkRowCounter++;
var newLinkRow = linkRow;
if(itemid > 0){
var RowID = itemid;
}else{
var RowID = linkRowCounter;
}
newLinkRow = newLinkRow.replace(/%%rowid%%/g ,RowID);
$('#staticListlinksListDiv').show();
$('#staticListlinksList').show();
$('#currentLinksHeader').show();
if(parentid < 1){
if(iwp.util.isDefined(afterId)){
$(newLinkRow).insertAfter('#staticListOrder_' + afterId);
}else{
$('#staticListlinksList').append(newLinkRow);
}
}else{
if(!$('.rowid_'+parentid+' > ul').exists()){
$('.rowid_'+parentid).append('<ul></ul>');
}
if(iwp.util.isDefined(afterId)){
$(newLinkRow).insertAfter('#staticListOrder_' + afterId);
}else{
$('.rowid_'+parentid+' > ul').append(newLinkRow);
}
}
$('#staticListText-'+RowID).val(text);
if(dbId > 0){
$('#staticListOrder_'+RowID).addClass('rowid_' + dbId);
}
$('#staticListUrl-'+RowID).val(url);
$('#linkNewWindow_'+RowID).selectOptions(newwindow);
$('#staticListText-'+RowID+', #staticListUrl-'+RowID).bind('mouseover',
function () {
if(!$(this).hasClass("inPlaceFieldFocus")) {
$(this).addClass("inPlaceFieldHover");
}
}
);
$('#staticListText-'+RowID+', #staticListUrl-'+RowID).bind('mouseout',
function () {
$(this).removeClass("inPlaceFieldHover");
}
);
$('#staticListText-'+RowID).bind('blur',
function () {
$(this).removeClass("inPlaceFieldFocus");
if(this.value == ''){
this.value = defaultStaticLinkText;
}
}
);
$('#staticListUrl-'+RowID).bind('blur',
function () {
$(this).removeClass("inPlaceFieldFocus");
if(this.value == '' || this.value == 'http://'){
this.value = defaultStaticLinkUrl;
}
}
);
$('#staticListText-'+RowID).bind('focus',
function () {
$(this).removeClass("inPlaceFieldHover");
$(this).addClass("inPlaceFieldFocus");
if(this.value == defaultStaticLinkText){
this.value = '';
}
}
);
$('#staticListUrl-'+RowID).bind('focus',
function () {
$(this).removeClass("inPlaceFieldHover");
$(this).addClass("inPlaceFieldFocus");
if(this.value == defaultStaticLinkUrl){
this.value = 'http://';
}
}
);
$('#staticListlinksList').tree( "destroy" );
$('#staticListlinksList').tree(StaticListTreeOptions);
new IWPUrlBrowser($('#staticListUrlBrowser-'+ RowID), $('#staticListUrl-'+ RowID), $('#staticListText-'+ RowID));
if($('#staticListlinksList li').size() < 2){
$('#staticListlinksList .remove_link_class').hide();
}else{
$('#staticListlinksList .remove_link_class').show();
}
}
/**
* This function takes the list of content types that are selected on the main tab, and determines the filters for them on the advanced tab
*/
function UpdateContentTypeFiltersFromList(){
var listIds = [];
var currentFilterContentTypeIds = [];
$('#contentTypeList input:checked').each(function(){
listIds.push($(this).attr('value'));
});
if($('#filter_list div').size() > 0){
$('#filter_list div').each(function(){
if($(this).children('.filter_select_field').selectedValues() == 'contenttype'){
currentFilterContentTypeIds.push($(this).children('.filter_value').attr('value'));
var thisId = $(this).attr('id');
thisId = thisId.replace('list_filter_', '');
RemoveFilter(thisId, false, true);
}else if($(this).children('.filter_select_field').selectedValues() == '0'){
var thisId = $(this).attr('id');
thisId = thisId.replace('list_filter_', '');
RemoveFilter(thisId, false, true);
}
});
}
if(listIds.length == 0){
// length will be 0 if it's a list of categories
AddFilter();
return;
}
var rowNum = 0;
var currId = '';
for(rowCount=0;rowCount<listIds.length;rowCount++){
rowNum = AddFilter();
$('#field_select'+rowNum).selectOptions('contenttype', true);
CheckFilterField(rowNum);
currId = listIds[rowCount].toString();
if(!$('#filter_value'+rowNum).containsOption(/./)){
window.setTimeout("$('#filter_value"+rowNum+"').selectOptions('"+currId+"', true);", 200);
}else{
$('#filter_value'+rowNum).selectOptions(currId, true);
}
}
AddFilter();
}
function countObject(obj){
var cnt = 0;
for( var i in obj ) {
cnt++;
}
return cnt;
}