Skip to content

Node.js based forum software built for the modern web

moved admin css to its own file for LESS compilation, and adding in options to update social keys for login

Julian Lam111b9dcf0ad8
diff --git a/public/templates/admin/facebook.tpl b/public/templates/admin/facebook.tpl
index f229fd7231..476edda238 100644
--- a/public/templates/admin/facebook.tpl
+++ b/public/templates/admin/facebook.tpl
@@ -3,11 +3,19 @@
<form>
<div class="alert alert-notify">
- <p>Create a <strong>Facebook Application</strong> and then paste your application details here.</p><br />
- <input type="text" class="" placeholder="App Key"><br />
- <input type="text" class="" placeholder="App Secret"><br />
+ <p>
+ Create a <strong>Facebook Application</strong> via the
+ <a href="https://developers.facebook.com/">Facebook Developers Page</a> and
+ then paste your application details here.
+ </p>
+ <br />
+ <input type="text" data-field="social:facebook:app_id" title="Application ID" class="input-medium" placeholder="App Key"><br />
+ <input type="text" data-field="social:facebook:secret" title="Application Secret" class="input-large" placeholder="App Secret"><br />
</div>
</form>
-<button class="btn btn-large btn-primary" type="submit">Save</button>
-<button class="btn btn-large" type="submit" disabled>Delete</button>
\ No newline at end of file
+<button class="btn btn-large btn-primary" id="save">Save</button>
+
+<script>
+ nodebb_admin.prepare();
+</script>
\ No newline at end of file
diff --git a/public/templates/admin/footer.tpl b/public/templates/admin/footer.tpl
index f5fc244c4b..0605179681 100644
--- a/public/templates/admin/footer.tpl
+++ b/public/templates/admin/footer.tpl
@@ -6,26 +6,135 @@
</div>
<script type="text/javascript">
-(function() {
- jQuery('document').ready(function() {
- // On menu click, change "active" state
- var menuEl = document.querySelector('.sidebar-nav'),
- liEls = menuEl.querySelectorAll('li')
- parentEl = null;
-
- menuEl.addEventListener('click', function(e) {
- parentEl = e.target.parentNode;
- if (parentEl.nodeName === 'LI') {
- for(var x=0,numLis=liEls.length;x<numLis;x++) {
- if (liEls[x] !== parentEl) jQuery(liEls[x]).removeClass('active');
- else jQuery(parentEl).addClass('active');
- }
+ var nodebb_admin = {
+ config: undefined,
+ prepare: function() {
+ // Come back in 500ms if the config isn't ready yet
+ if (nodebb_admin.config === undefined) {
+ console.log('Config not ready...');
+ setTimeout(function() {
+ nodebb_admin.prepare();
+ }, 500);
+ return;
}
- }, false);
- });
-
-}())
+ // Populate the fields on the page from the config
+ var fields = document.querySelectorAll('#content [data-field]'),
+ numFields = fields.length,
+ saveBtn = document.getElementById('save'),
+ x, key, inputType;
+ for(x=0;x<numFields;x++) {
+ key = fields[x].getAttribute('data-field');
+ inputType = fields[x].getAttribute('type');
+ if (nodebb_admin.config[key]) {
+ switch(inputType) {
+ case 'text':
+ case 'textarea':
+ case 'number':
+ fields[x].value = nodebb_admin.config[key];
+ break;
+
+ case 'checkbox':
+ fields[x].checked = nodebb_admin.config[key] ? true : false;
+ break;
+ }
+ } /*else {
+ // Save defaults, if they're not found in the config
+ var defaultFields = [
+ 'use_port', 'port', 'upload_url', 'mailer:host',
+ 'mailer:port', 'privileges:manage_content',
+ 'privileges:manage_topic'
+ ],
+ defaultVal;
+ if (defaultFields.indexOf(key) !== -1) {
+ console.log('saving default value: ', key);
+ switch(inputType) {
+ case 'text':
+ case 'textarea':
+ case 'number':
+ defaultVal = fields[x].value;
+ break;
+
+ case 'checkbox':
+ defaultVal = fields[x].checked ? '1' : '0';
+ break;
+ }
+ socket.emit('api:config.set', {
+ key: key,
+ value: defaultVal
+ });
+ nodebb_admin.config[key] = defaultVal;
+ }
+ }*/
+ }
+
+ saveBtn.addEventListener('click', function(e) {
+ var key, value;
+ e.preventDefault();
+
+ for(x=0;x<numFields;x++) {
+ key = fields[x].getAttribute('data-field');
+ inputType = fields[x].getAttribute('type');
+ switch(inputType) {
+ case 'text':
+ case 'textarea':
+ case 'number':
+ value = fields[x].value;
+ break;
+
+ case 'checkbox':
+ value = fields[x].checked ? '1' : '0';
+ break;
+ }
+ socket.emit('api:config.set', { key: key, value: value });
+ }
+ });
+ }
+ };
+
+ (function() {
+ jQuery('document').ready(function() {
+ // On menu click, change "active" state
+ var menuEl = document.querySelector('.sidebar-nav'),
+ liEls = menuEl.querySelectorAll('li')
+ parentEl = null;
+
+ menuEl.addEventListener('click', function(e) {
+ parentEl = e.target.parentNode;
+ if (parentEl.nodeName === 'LI') {
+ for(var x=0,numLis=liEls.length;x<numLis;x++) {
+ if (liEls[x] !== parentEl) jQuery(liEls[x]).removeClass('active');
+ else jQuery(parentEl).addClass('active');
+ }
+ }
+ }, false);
+ });
+
+ socket.once('api:config.get', function(config) {
+ nodebb_admin.config = config;
+ });
+ socket.emit('api:config.get');
+
+ socket.on('api:config.set', function(data) {
+ if (data.status === 'ok') {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Changes Saved',
+ message: 'Your changes to the NodeBB configuration have been saved',
+ type: 'success'
+ });
+ } else {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Changes Not Saved',
+ message: 'NodeBB encountered a problem saving your changes',
+ type: 'error'
+ });
+ }
+ });
+ }())
</script>
</body>
diff --git a/public/templates/admin/gplus.tpl b/public/templates/admin/gplus.tpl
index 343b82cfdd..b8f56a117a 100644
--- a/public/templates/admin/gplus.tpl
+++ b/public/templates/admin/gplus.tpl
@@ -1,13 +1,21 @@
-<h1>Google Plus Social Authentication</h1>
+<h1>Google Accounts Social Authentication</h1>
<hr />
<form>
<div class="alert alert-notify">
- <p>Create a <strong>Google+ Application</strong> and then paste your application details here.</p><br />
- <input type="text" class="" placeholder="App ID"><br />
- <input type="text" class="" placeholder="App Secret"><br />
+ <p>
+ Create a <strong>Google Application</strong> via the
+ <a href="https://code.google.com/apis/console/">API Console</a> and then paste
+ your application details here.
+ </p>
+ <br />
+ <input type="text" data-field="social:google:id" title="Client ID" class="input-xxlarge" placeholder="Client ID"><br />
+ <input type="text" data-field="social:google:secret" title="Client Secret" class="input-large" placeholder="Client Secret"><br />
</div>
</form>
-<button class="btn btn-large btn-primary" type="submit">Save</button>
-<button class="btn btn-large" type="submit" disabled>Delete</button>
\ No newline at end of file
+<button class="btn btn-large btn-primary" id="save">Save</button>
+
+<script>
+ nodebb_admin.prepare();
+</script>
\ No newline at end of file
diff --git a/public/templates/admin/header.tpl b/public/templates/admin/header.tpl
index a987384bb4..f6adffeb78 100644
--- a/public/templates/admin/header.tpl
+++ b/public/templates/admin/header.tpl
@@ -15,44 +15,7 @@
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="/css/style.css" />
- <style type="text/css">
- .entry-row {
- border-radius: 10px;
- margin-bottom: 10px;
- padding: 10px;
- cursor: move;
- width: 555px;
- }
- .admin-categories form {
- margin: 0 0 0px;
- }
-
- .admin-categories input {
- height: 20px;
- padding: 5px;
- margin-left: 10px;
- width: 150px;
- border: 0;
- border-radius: 5px;
- margin-top: -8px;
- }
- .admin-categories select {
- border: 0;
- margin-left: 10px;
- padding: 5px;
- margin-top: -8px;
- }
- .admin-categories button {
- margin-top: -7px;
- }
- .admin-categories .icon{
- width: 30px;
- height: 30px;
- text-align: center;
- line-height: 35px;
- display: inline-block;
- }
- </style>
+ <link rel="stylesheet" type="text/css" href="/css/admin.css" />
</head>
<body>
@@ -81,6 +44,8 @@
</div>
</div>
</div>
+
+ <div id="alert_window"></div>
<div class="container-fluid">
<div class="row-fluid">
diff --git a/public/templates/admin/twitter.tpl b/public/templates/admin/twitter.tpl
index 527e1ba115..b3099997ea 100644
--- a/public/templates/admin/twitter.tpl
+++ b/public/templates/admin/twitter.tpl
@@ -3,12 +3,19 @@
<form>
<div class="alert alert-notify">
- <p>Create a <strong>Twitter Application</strong> and then paste your application details here.</p><br />
- <input type="text" class="" placeholder="App Key"><br />
- <input type="text" class="" placeholder="App Secret"><br />
+ <p>
+ Create a <strong>Twitter Application</strong> via the
+ <a href="https://dev.twitter.com/">Twitter Developers Page</a> and then
+ paste your application details here.
+ </p>
+ <br />
+ <input type="text" data-field="social:twitter:key" title="Consumer Key" class="input-large" placeholder="Consumer Key"><br />
+ <input type="text" data-field="social:twitter:secret" title="Consumer Secret" class="input-xlarge" placeholder="Consumer Secret">
</div>
</form>
+<button class="btn btn-large btn-primary" id="save">Save</button>
-<button class="btn btn-large btn-primary" type="submit">Save</button>
-<button class="btn btn-large" type="submit" disabled>Delete</button>
\ No newline at end of file
+<script>
+ nodebb_admin.prepare();
+</script>
diff --git a/src/websockets.js b/src/websockets.js
index 05bdfb0a2d..540945eff3 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -293,14 +293,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
}
});
- socket.on('api:config.redisTest', function() {
- meta.testRedis(function(success) {
- socket.emit('api:config.redisTest', {
- status: success ? 'ok' : 'error'
- });
- });
- });
-
socket.on('api:config.get', function(data) {
meta.config.get(function(config) {
socket.emit('api:config.get', config);
@@ -308,6 +300,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:config.set', function(data) {
+ console.log('saving', data);
meta.config.set(data.key, data.value, function(err) {
if (!err) socket.emit('api:config.set', { status: 'ok' });
});