2018-07-13 18:39:55 +02:00
|
|
|
/*
|
2018-10-09 21:30:00 +02:00
|
|
|
* Copyright (c) Codiad, distributed
|
|
|
|
* as-is and without warranty under the MIT License. See
|
|
|
|
* [root]/license.txt for more. This information must remain intact.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function(global, $) {
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
|
|
|
codiad.settings.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
codiad.settings = {
|
|
|
|
|
|
|
|
controller: 'components/settings/controller.php',
|
|
|
|
|
|
|
|
init: function() {
|
2018-07-26 21:39:40 +02:00
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
var _this = this;
|
2018-07-26 21:39:40 +02:00
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
/*
|
|
|
|
* Storage Event:
|
|
|
|
* Note: Event fires only if change was made in different window and not in this one
|
|
|
|
* Details: http://dev.w3.org/html5/webstorage/#dom-localstorage
|
|
|
|
*
|
|
|
|
* Workaround for Storage-Event:
|
|
|
|
*/
|
|
|
|
$( 'body' ).append( '<iframe src="components/settings/dialog.php?action=iframe"></iframe>' );
|
2018-07-26 21:39:40 +02:00
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
//Load Settings
|
2018-12-21 17:43:51 +01:00
|
|
|
this.load();
|
2018-10-09 21:30:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
get_option: async function( option ) {
|
|
|
|
|
|
|
|
let result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
result = await $.ajax({
|
|
|
|
|
|
|
|
url: this.controller + '?action=get_option',
|
|
|
|
type: "POST",
|
|
|
|
dataType: 'html',
|
|
|
|
data: {
|
|
|
|
option: option
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.log(error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-04-11 01:31:28 +02:00
|
|
|
get_options: async function() {
|
|
|
|
|
|
|
|
let result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
result = await $.ajax({
|
|
|
|
|
|
|
|
url: this.controller + '?action=get_options',
|
|
|
|
type: "POST",
|
|
|
|
dataType: 'html',
|
|
|
|
data: {
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.log(error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Save Settings
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
save: function( settings ) {
|
|
|
|
|
|
|
|
var systemRegex = /^codiad/;
|
|
|
|
var pluginRegex = /^codiad.plugin/;
|
|
|
|
|
2019-02-07 19:55:17 +01:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: this.controller + '?action=save',
|
|
|
|
data: {settings: JSON.stringify( settings )},
|
|
|
|
success: function( data ) {
|
|
|
|
data = data.replace(/},/gi, ",").split(",");
|
|
|
|
length = data.length;
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2019-02-07 19:55:17 +01:00
|
|
|
for( i = 0;i < length; i++ ) {
|
|
|
|
|
|
|
|
parsed = codiad.jsend.parse( data );
|
|
|
|
}
|
|
|
|
codiad.modal.unload();
|
|
|
|
},
|
2018-10-09 21:30:00 +02:00
|
|
|
});
|
2019-01-15 16:33:59 +01:00
|
|
|
|
|
|
|
/* Notify listeners */
|
|
|
|
amplify.publish( 'settings.save', {} );
|
2018-10-09 21:30:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Load Settings
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
load: function() {
|
|
|
|
|
|
|
|
codiad.editor.getSettings();
|
2019-01-15 16:33:59 +01:00
|
|
|
amplify.publish( 'settings.loaded', null );
|
2018-10-09 21:30:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Show Settings Dialog
|
|
|
|
//
|
|
|
|
// Parameter
|
|
|
|
//
|
|
|
|
// data_file - {String} - Location of settings file based on BASE_URL
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
show: function( data_file ) {
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
codiad.modal.load( 800, 'components/settings/dialog.php?action=settings' );
|
|
|
|
codiad.modal.hideOverlay();
|
|
|
|
codiad.modal.load_process.done( function() {
|
|
|
|
|
|
|
|
if ( typeof( data_file ) == 'string' ) {
|
|
|
|
|
|
|
|
codiad.settings._showTab( data_file );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_this._loadTabValues( 'components/settings/settings.editor.php' );
|
|
|
|
}
|
|
|
|
/* Notify listeners */
|
|
|
|
amplify.publish( 'settings.dialog.show', {} );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
update_option: function( option, value ) {
|
|
|
|
|
2019-01-15 16:33:59 +01:00
|
|
|
if( option == undefined || value == undefined ) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
jQuery.ajax({
|
|
|
|
|
|
|
|
url: this.controller + '?action=update_option',
|
|
|
|
type: "POST",
|
|
|
|
dataType: 'html',
|
|
|
|
data: {
|
|
|
|
option: option,
|
|
|
|
value: value
|
|
|
|
},
|
2019-04-08 02:58:53 +02:00
|
|
|
success: function( data ) {
|
|
|
|
|
2019-04-11 01:31:28 +02:00
|
|
|
console.log( `Update Option ( ${option} ): ` + data )
|
2019-04-08 02:58:53 +02:00
|
|
|
},
|
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
|
|
|
console.log('jqXHR:');
|
|
|
|
console.log(jqXHR);
|
|
|
|
console.log('textStatus:');
|
|
|
|
console.log(textStatus);
|
|
|
|
console.log('errorThrown:');
|
|
|
|
console.log(errorThrown);
|
|
|
|
},
|
2018-10-09 21:30:00 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// {Private} Show Specific Tab
|
|
|
|
//
|
|
|
|
// Parameter
|
|
|
|
//
|
|
|
|
// data_file - {String} - Location of settings file based on BASE_URL
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
_showTab: function( data_file ) {
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
if ( typeof( data_file ) != 'string' ) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$( '.settings-view .config-menu .active' ).removeClass( 'active' );
|
|
|
|
$( '.settings-view .config-menu li[data-file="' + data_file + '"]' ).addClass( 'active' );
|
|
|
|
$( '.settings-view .panels .active' ).hide().removeClass( 'active' );
|
|
|
|
//Load panel
|
|
|
|
if( $( '.settings-view .panel[data-file="' + data_file + '"]' ).length === 0 ) {
|
|
|
|
|
|
|
|
$( '.settings-view .panels' ).append( '<div class="panel active" data-file="' + data_file + '"></div>' );
|
|
|
|
$( '.settings-view .panel[data-file="' + data_file + '"]' ).load( data_file, function() {
|
|
|
|
|
|
|
|
//TODO Show and hide loading information
|
|
|
|
/* Notify listeners */
|
|
|
|
var name = $( '.settings-view .config-menu li[data-file="' + data_file + '"]' ).attr( 'data-name' );
|
|
|
|
amplify.publish( 'settings.dialog.tab_loaded', name );
|
|
|
|
_this._loadTabValues( data_file );
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$( '.settings-view .panel[data-file="' + data_file + '"]' ).show().addClass( 'active' );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// {Private} Load Settings of Specific Tab
|
|
|
|
//
|
|
|
|
// Parameter
|
|
|
|
//
|
|
|
|
// data_file - {String} - Location of settings file based on BASE_URL
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
_loadTabValues: function( data_file ) {
|
|
|
|
|
|
|
|
//Load settings
|
|
|
|
$( '.settings-view .panel[data-file="' + data_file + '"] .setting').each( async function( i, item ) {
|
|
|
|
|
2019-01-15 16:33:59 +01:00
|
|
|
let key = await $( item ).attr( 'data-setting' );
|
|
|
|
let value = await codiad.settings.get_option( key );
|
|
|
|
|
2019-01-15 17:01:55 +01:00
|
|
|
//console.log( key, value, i, $( item ).attr( 'data-setting' ) );
|
2019-01-15 16:33:59 +01:00
|
|
|
|
|
|
|
if ( value != null && value != undefined ) {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
|
|
|
$( item ).val( value );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-13 18:39:55 +02:00
|
|
|
})(this, jQuery);
|