2015-07-30 05:22:50 -04:00
|
|
|
// settings.js of user_sql
|
|
|
|
|
2014-10-27 15:23:32 -04:00
|
|
|
// declare namespace
|
2014-11-12 15:45:11 -05:00
|
|
|
var user_sql = user_sql ||
|
|
|
|
{
|
|
|
|
};
|
2014-10-27 15:23:32 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* init admin settings view
|
|
|
|
*/
|
2014-11-12 15:45:11 -05:00
|
|
|
user_sql.adminSettingsUI = function()
|
|
|
|
{
|
|
|
|
|
2016-03-16 12:46:07 -04:00
|
|
|
if($('#sqlDiv').length > 0)
|
2014-11-12 15:45:11 -05:00
|
|
|
{
|
|
|
|
// enable tabs on settings page
|
2016-03-16 12:46:07 -04:00
|
|
|
$('#sqlDiv').tabs();
|
2015-07-30 05:22:50 -04:00
|
|
|
|
|
|
|
// Attach auto-completion to all column fields
|
2016-01-08 02:32:45 -05:00
|
|
|
$('#col_username, #col_password, #col_displayname, #col_active, #col_email, #col_gethome').autocomplete({
|
2015-07-30 05:22:50 -04:00
|
|
|
source: function(request, response)
|
|
|
|
{
|
|
|
|
var post = $('#sqlForm').serializeArray();
|
|
|
|
var domain = $('#sql_domain_chooser option:selected').val();
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'function',
|
|
|
|
value: 'getColumnAutocomplete'
|
|
|
|
});
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'domain',
|
|
|
|
value: domain
|
|
|
|
});
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'request',
|
|
|
|
value: request.term
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajax foobar
|
|
|
|
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json');
|
|
|
|
},
|
|
|
|
minLength: 0,
|
|
|
|
open: function() {
|
|
|
|
$(this).attr('state', 'open');
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
$(this).attr('state', 'closed');
|
|
|
|
}
|
|
|
|
}).focus(function() {
|
|
|
|
if($(this).attr('state') != 'open')
|
|
|
|
{
|
|
|
|
$(this).autocomplete("search");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Attach auto-completion to all table fields
|
|
|
|
$('#sql_table').autocomplete({
|
|
|
|
source: function(request, response)
|
|
|
|
{
|
|
|
|
var post = $('#sqlForm').serializeArray();
|
|
|
|
var domain = $('#sql_domain_chooser option:selected').val();
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'function',
|
|
|
|
value: 'getTableAutocomplete'
|
|
|
|
});
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'domain',
|
|
|
|
value: domain
|
|
|
|
});
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'request',
|
|
|
|
value: request.term
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajax foobar
|
|
|
|
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, response, 'json');
|
|
|
|
},
|
|
|
|
minLength: 0,
|
|
|
|
open: function() {
|
|
|
|
$(this).attr('state', 'open');
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
$(this).attr('state', 'closed');
|
|
|
|
}
|
|
|
|
}).focus(function() {
|
|
|
|
if($(this).attr('state') != 'open')
|
|
|
|
{
|
|
|
|
$(this).autocomplete("search");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify the SQL database settings
|
|
|
|
$('#sqlVerify').click(function(event)
|
|
|
|
{
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var post = $('#sqlForm').serializeArray();
|
|
|
|
var domain = $('#sql_domain_chooser option:selected').val();
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'function',
|
|
|
|
value: 'verifySettings'
|
|
|
|
});
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'domain',
|
|
|
|
value: domain
|
|
|
|
});
|
2014-11-12 15:45:11 -05:00
|
|
|
|
2015-07-30 05:22:50 -04:00
|
|
|
$('#sql_verify_message').show();
|
|
|
|
$('#sql_success_message').hide();
|
|
|
|
$('#sql_error_message').hide();
|
|
|
|
$('#sql_update_message').hide();
|
|
|
|
// Ajax foobar
|
|
|
|
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data)
|
|
|
|
{
|
|
|
|
$('#sql_verify_message').hide();
|
|
|
|
if(data.status == 'success')
|
|
|
|
{
|
|
|
|
$('#sql_success_message').html(data.data.message);
|
|
|
|
$('#sql_success_message').show();
|
|
|
|
window.setTimeout(function()
|
|
|
|
{
|
|
|
|
$('#sql_success_message').hide();
|
|
|
|
}, 10000);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
$('#sql_error_message').html(data.data.message);
|
|
|
|
$('#sql_error_message').show();
|
|
|
|
}
|
|
|
|
}, 'json');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Save the settings for a domain
|
2014-11-12 15:45:11 -05:00
|
|
|
$('#sqlSubmit').click(function(event)
|
|
|
|
{
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var post = $('#sqlForm').serializeArray();
|
2015-07-27 09:02:10 -04:00
|
|
|
var domain = $('#sql_domain_chooser option:selected').val();
|
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'function',
|
|
|
|
value: 'saveSettings'
|
2014-11-12 15:45:11 -05:00
|
|
|
});
|
2015-07-27 09:02:10 -04:00
|
|
|
|
|
|
|
post.push({
|
|
|
|
name: 'domain',
|
|
|
|
value: domain
|
2014-11-12 15:45:11 -05:00
|
|
|
});
|
2015-07-27 09:02:10 -04:00
|
|
|
|
2014-11-12 15:45:11 -05:00
|
|
|
$('#sql_update_message').show();
|
|
|
|
$('#sql_success_message').hide();
|
2015-07-30 05:22:50 -04:00
|
|
|
$('#sql_verify_message').hide();
|
2014-11-12 15:45:11 -05:00
|
|
|
$('#sql_error_message').hide();
|
|
|
|
// Ajax foobar
|
|
|
|
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data)
|
|
|
|
{
|
|
|
|
$('#sql_update_message').hide();
|
|
|
|
if(data.status == 'success')
|
|
|
|
{
|
|
|
|
$('#sql_success_message').html(data.data.message);
|
|
|
|
$('#sql_success_message').show();
|
|
|
|
window.setTimeout(function()
|
|
|
|
{
|
|
|
|
$('#sql_success_message').hide();
|
|
|
|
}, 10000);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
$('#sql_error_message').html(data.data.message);
|
|
|
|
$('#sql_error_message').show();
|
|
|
|
}
|
|
|
|
}, 'json');
|
|
|
|
return false;
|
|
|
|
});
|
2015-07-30 05:22:50 -04:00
|
|
|
|
|
|
|
// Attach event handler to the domain chooser
|
2015-07-27 09:02:10 -04:00
|
|
|
$('#sql_domain_chooser').change(function() {
|
|
|
|
user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val());
|
2014-11-12 15:45:11 -05:00
|
|
|
});
|
2016-01-08 02:32:45 -05:00
|
|
|
|
|
|
|
$('#set_gethome_mode').change(function() {
|
|
|
|
user_sql.setGethomeMode();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#set_enable_gethome').change(function() {
|
|
|
|
user_sql.setGethomeMode();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
user_sql.setGethomeMode = function()
|
|
|
|
{
|
|
|
|
var enabled = $('#set_enable_gethome').prop('checked');
|
|
|
|
if(enabled)
|
|
|
|
{
|
|
|
|
$('#set_gethome_mode').prop('disabled', false);
|
|
|
|
var val = $('#set_gethome_mode option:selected').val();
|
|
|
|
if(val === 'query')
|
|
|
|
{
|
|
|
|
$('#set_gethome').prop('disabled', true);
|
|
|
|
$('#col_gethome').prop('disabled', false);
|
|
|
|
}
|
|
|
|
else if(val === 'static')
|
|
|
|
{
|
|
|
|
$('#set_gethome').prop('disabled', false);
|
|
|
|
$('#col_gethome').prop('disabled', true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#set_gethome').prop('disabled', true);
|
|
|
|
$('#col_gethome').prop('disabled', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#set_gethome_mode').prop('disabled', true);
|
|
|
|
$('#set_gethome').prop('disabled', true);
|
|
|
|
$('#col_gethome').prop('disabled', true);
|
2015-07-27 09:02:10 -04:00
|
|
|
}
|
|
|
|
};
|
2014-10-27 15:23:32 -04:00
|
|
|
|
2015-07-30 05:22:50 -04:00
|
|
|
/**
|
|
|
|
* Load the settings for the selected domain
|
|
|
|
* @param string domain The domain to load
|
|
|
|
*/
|
2015-07-27 09:02:10 -04:00
|
|
|
user_sql.loadDomainSettings = function(domain)
|
|
|
|
{
|
2015-07-30 05:22:50 -04:00
|
|
|
$('#sql_success_message').hide();
|
|
|
|
$('#sql_error_message').hide();
|
|
|
|
$('#sql_verify_message').hide();
|
2015-07-27 09:02:10 -04:00
|
|
|
$('#sql_loading_message').show();
|
|
|
|
var post = [
|
2014-11-12 15:45:11 -05:00
|
|
|
{
|
2015-07-27 09:02:10 -04:00
|
|
|
name: 'appname',
|
|
|
|
value: 'user_sql'
|
|
|
|
},
|
2014-11-12 15:45:11 -05:00
|
|
|
{
|
2015-07-27 09:02:10 -04:00
|
|
|
name: 'function',
|
|
|
|
value: 'loadSettingsForDomain'
|
|
|
|
},
|
2014-11-12 15:45:11 -05:00
|
|
|
{
|
2015-07-27 09:02:10 -04:00
|
|
|
name: 'domain',
|
|
|
|
value: domain
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data)
|
|
|
|
{
|
|
|
|
$('#sql_loading_message').hide();
|
|
|
|
if(data.status == 'success')
|
2014-11-12 15:45:11 -05:00
|
|
|
{
|
2015-07-27 09:02:10 -04:00
|
|
|
for(key in data.settings)
|
2014-11-12 15:45:11 -05:00
|
|
|
{
|
2015-07-27 09:02:10 -04:00
|
|
|
if(key == 'set_strip_domain')
|
|
|
|
{
|
|
|
|
if(data.settings[key] == 'true')
|
|
|
|
$('#' + key).prop('checked', true);
|
|
|
|
else
|
|
|
|
$('#' + key).prop('checked', false);
|
|
|
|
}
|
|
|
|
else if(key == 'set_allow_pwchange')
|
|
|
|
{
|
|
|
|
if(data.settings[key] == 'true')
|
|
|
|
$('#' + key).prop('checked', true);
|
|
|
|
else
|
|
|
|
$('#' + key).prop('checked', false);
|
|
|
|
}
|
|
|
|
else if(key == 'set_active_invert')
|
|
|
|
{
|
|
|
|
if(data.settings[key] == 'true')
|
|
|
|
$('#' + key).prop('checked', true);
|
|
|
|
else
|
|
|
|
$('#' + key).prop('checked', false);
|
|
|
|
}
|
2016-01-08 02:51:14 -05:00
|
|
|
else if(key == 'set_enable_gethome')
|
2016-01-08 02:32:45 -05:00
|
|
|
{
|
|
|
|
if(data.settings[key] == 'true')
|
|
|
|
$('#' + key).prop('checked', true);
|
|
|
|
else
|
|
|
|
$('#' + key).prop('checked', false);
|
|
|
|
}
|
2016-12-30 08:47:48 -05:00
|
|
|
else if(key == 'set_force_default_domain')
|
|
|
|
{
|
|
|
|
if(data.settings[key] == 'true')
|
|
|
|
$('#' + key).prop('checked', true);
|
|
|
|
else
|
|
|
|
$('#' + key).prop('checked', false);
|
|
|
|
}
|
2015-07-27 09:02:10 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#' + key).val(data.settings[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('#sql_error_message').html(data.data.message);
|
|
|
|
$('#sql_error_message').show();
|
|
|
|
}
|
2016-01-08 03:22:22 -05:00
|
|
|
user_sql.setGethomeMode();
|
2015-07-30 05:22:50 -04:00
|
|
|
}, 'json'
|
2015-07-27 09:02:10 -04:00
|
|
|
);
|
2014-11-11 14:32:58 -05:00
|
|
|
};
|
2014-10-27 15:23:32 -04:00
|
|
|
|
2015-07-30 05:22:50 -04:00
|
|
|
// Run our JS if the SQL settings are present
|
2014-11-12 15:45:11 -05:00
|
|
|
$(document).ready(function()
|
|
|
|
{
|
2016-03-16 12:46:07 -04:00
|
|
|
if($('#sqlDiv'))
|
2014-11-12 15:45:11 -05:00
|
|
|
{
|
|
|
|
user_sql.adminSettingsUI();
|
2015-07-27 09:02:10 -04:00
|
|
|
user_sql.loadDomainSettings($('#sql_domain_chooser option:selected').val());
|
2016-01-08 02:32:45 -05:00
|
|
|
user_sql.setGethomeMode();
|
2014-11-12 15:45:11 -05:00
|
|
|
}
|
2014-10-27 15:23:32 -04:00
|
|
|
});
|
|
|
|
|