fixing alert removal by alert_id and adding alerts when thread is locked or pinned

v1.18.x
Julian Lam 12 years ago
parent 8bccc8466e
commit f0eeec8932

@ -33,6 +33,8 @@ var socket,
// use unique alert_id to have multiple alerts visible at a time, use the same alert_id to fade out the current instance
// type : error, success, info, warning/notify
// title = bolded title text
// message = alert message content
// timeout default = permanent
// location : notification_window (default) or content
app.alert = function(params) {
@ -41,7 +43,7 @@ var socket,
strong = document.createElement('strong'),
p = document.createElement('p');
var alert_id = 'alert_button_' + ((alert_id) ? alert_id : new Date().getTime());
var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime());
jQuery('#'+alert_id).fadeOut(500, function() {
this.remove();

@ -10,7 +10,7 @@
<ul class="topic-container">
<!-- BEGIN topics -->
<a href="../../topic/{topics.slug}"><li class="topic-row">
<h4><i class="{topics.icon}"></i> {topics.title}</h4>
<h4><i class="{topics.pin-icon}"></i><i class="{topics.lock-icon}"></i> {topics.title}</h4>
<p>Posted {topics.relativeTime} ago by <span class="username">{topics.username}</span>. {topics.post_count} posts.</p>
</li></a>
<!-- END topics -->

@ -163,25 +163,25 @@
socket.on('event:topic_locked', function(data) {
if (data.tid === tid && data.status === 'ok') {
set_locked_state(true);
set_locked_state(true, 1);
}
});
socket.on('event:topic_unlocked', function(data) {
if (data.tid === tid && data.status === 'ok') {
set_locked_state(false);
set_locked_state(false, 1);
}
});
socket.on('event:topic_pinned', function(data) {
if (data.tid === tid && data.status === 'ok') {
set_pinned_state(true);
set_pinned_state(true, 1);
}
});
socket.on('event:topic_unpinned', function(data) {
if (data.tid === tid && data.status === 'ok') {
set_pinned_state(false);
set_pinned_state(false, 1);
}
});
@ -241,7 +241,7 @@
});
}
function set_locked_state(locked) {
function set_locked_state(locked, alert) {
var threadReplyBtn = document.getElementById('post_reply'),
postReplyBtns = document.querySelectorAll('#post-container .post_reply'),
quoteBtns = document.querySelectorAll('#post-container .quote'),
@ -250,6 +250,7 @@
numReplyBtns = postReplyBtns.length,
lockThreadEl = document.getElementById('lock_thread'),
x;
if (locked === true) {
lockThreadEl.innerHTML = '<i class="icon-unlock"></i> Unlock Thread';
threadReplyBtn.disabled = true;
@ -261,6 +262,16 @@
deleteBtns[x].style.display = 'none';
}
if (alert) {
app.alert({
'alert_id': 'thread_lock',
type: 'success',
title: 'Thread Locked',
message: 'Thread has been successfully locked',
timeout: 5000
});
}
thread_state.locked = '1';
} else {
lockThreadEl.innerHTML = '<i class="icon-lock"></i> Lock Thread';
@ -273,6 +284,16 @@
deleteBtns[x].style.display = 'inline-block';
}
if (alert) {
app.alert({
'alert_id': 'thread_lock',
type: 'success',
title: 'Thread Unlocked',
message: 'Thread has been successfully unlocked',
timeout: 5000
});
}
thread_state.locked = '0';
}
}
@ -303,15 +324,33 @@
}
}
function set_pinned_state(pinned) {
function set_pinned_state(pinned, alert) {
var pinEl = document.getElementById('pin_thread');
if (pinned) {
pinEl.innerHTML = '<i class="icon-pushpin"></i> Unpin Thread';
if (alert) {
app.alert({
'alert_id': 'thread_pin',
type: 'success',
title: 'Thread Pinned',
message: 'Thread has been successfully pinned',
timeout: 5000
});
}
thread_state.pinned = '1';
} else {
pinEl.innerHTML = '<i class="icon-pushpin"></i> Pin Thread';
if (alert) {
app.alert({
'alert_id': 'thread_pin',
type: 'success',
title: 'Thread Unpinned',
message: 'Thread has been successfully unpinned',
timeout: 5000
});
}
thread_state.pinned = '0';
}

@ -44,6 +44,7 @@ var RDB = require('./redis.js'),
'category_slug':thread_data.category_slug,
'locked': parseInt(thread_data.locked) || 0,
'deleted': parseInt(thread_data.deleted) || 0,
'pinned': parseInt(thread_data.pinned) || 0,
'topic_id': tid,
'expose_tools': viewer_data.reputation >= config.privilege_thresholds.manage_thread ? 1 : 0,
'posts': posts
@ -80,6 +81,7 @@ var RDB = require('./redis.js'),
.get('tid:' + tid + ':category_name')
.get('tid:' + tid + ':category_slug')
.get('tid:' + tid + ':deleted')
.get('tid:' + tid + ':pinned')
.exec(function(err, replies) {
post_data = {
pid: pids,
@ -91,10 +93,11 @@ var RDB = require('./redis.js'),
thread_data = {
topic_name: replies[4],
locked: replies[5],
locked: replies[5] || 0,
category_name: replies[6],
category_slug: replies[7],
deleted: replies[8] || 0
deleted: replies[8] || 0,
pinned: replies[9] || 0
};
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){

@ -27,16 +27,18 @@ var RDB = require('./redis.js'),
slug = [],
postcount = [],
locked = [],
deleted = [];
deleted = [],
pinned = [];
for (var i=0, ii=tids.length; i<ii; i++) {
title.push('tid:' + tids[i] + ':title');
uid.push('tid:' + tids[i] + ':uid');
timestamp.push('tid:' + tids[i] + ':timestamp');
slug.push('tid:' + tids[i] + ':slug');
postcount.push('tid:' + tids[i] + ':postcount'),
locked.push('tid:' + tids[i] + ':locked'),
postcount.push('tid:' + tids[i] + ':postcount');
locked.push('tid:' + tids[i] + ':locked');
deleted.push('tid:' + tids[i] + ':deleted');
pinned.push('tid:' + tids[i] + ':pinned');
}
var multi = RDB.multi()
@ -51,6 +53,7 @@ var RDB = require('./redis.js'),
.mget(postcount)
.mget(locked)
.mget(deleted)
.mget(pinned)
}
@ -66,6 +69,7 @@ var RDB = require('./redis.js'),
postcount = replies[5];
locked = replies[6];
deleted = replies[7];
pinned = replies[8];
user.get_usernames_by_uids(uid, function(userNames) {
@ -79,8 +83,9 @@ var RDB = require('./redis.js'),
'relativeTime': utils.relativeTime(timestamp[i]),
'slug' : slug[i],
'post_count' : postcount[i],
'icon': locked[i] === '1' ? 'icon-lock' : 'hide',
'deleted': deleted[i]
'lock-icon': locked[i] === '1' ? 'icon-lock' : 'hide',
'deleted': deleted[i],
'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'hide'
});
}

Loading…
Cancel
Save