2018-11-08 07:23:08 +01:00
|
|
|
var postActions = function() {
|
|
|
|
var $container = He.get('moving');
|
2018-11-10 04:10:46 +01:00
|
|
|
var MultiMove = function(el, id, singleUser) {
|
2018-11-08 07:23:08 +01:00
|
|
|
var lbl = el.options[el.selectedIndex].textContent;
|
|
|
|
var collAlias = el.options[el.selectedIndex].value;
|
|
|
|
var $lbl = He.$('label[for=move-'+id+']')[0];
|
|
|
|
$lbl.textContent = "moving to "+lbl+"...";
|
|
|
|
var params;
|
|
|
|
if (collAlias == '|anonymous|') {
|
|
|
|
params = [id];
|
|
|
|
} else {
|
|
|
|
params = [{
|
|
|
|
id: id
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
var callback = function(code, resp) {
|
|
|
|
if (code == 200) {
|
|
|
|
for (var i=0; i<resp.data.length; i++) {
|
|
|
|
if (resp.data[i].code == 200) {
|
|
|
|
$lbl.innerHTML = "moved to <strong>"+lbl+"</strong>";
|
2018-11-10 04:10:46 +01:00
|
|
|
var pre = "/"+collAlias;
|
|
|
|
if (typeof singleUser !== 'undefined' && singleUser) {
|
|
|
|
pre = "";
|
|
|
|
}
|
|
|
|
var newPostURL = pre+"/"+resp.data[i].post.slug;
|
2018-11-08 07:23:08 +01:00
|
|
|
try {
|
|
|
|
// Posts page
|
|
|
|
He.$('#post-'+resp.data[i].post.id+' > h3 > a')[0].href = newPostURL;
|
|
|
|
} catch (e) {
|
|
|
|
// Blog index
|
|
|
|
var $article = He.get('post-'+resp.data[i].post.id);
|
|
|
|
$article.className = 'norm moved';
|
|
|
|
if (collAlias == '|anonymous|') {
|
2018-11-10 04:10:46 +01:00
|
|
|
var draftPre = "";
|
|
|
|
if (typeof singleUser !== 'undefined' && singleUser) {
|
|
|
|
draftPre = "d/";
|
|
|
|
}
|
|
|
|
$article.innerHTML = '<p><a href="/'+draftPre+resp.data[i].post.id+'">Unpublished post</a>.</p>';
|
2018-11-08 07:23:08 +01:00
|
|
|
} else {
|
|
|
|
$article.innerHTML = '<p>Moved to <a style="font-weight:bold" href="'+newPostURL+'">'+lbl+'</a>.</p>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$lbl.innerHTML = "unable to move: "+resp.data[i].error_msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (collAlias == '|anonymous|') {
|
|
|
|
He.postJSON("/api/posts/disperse", params, callback);
|
|
|
|
} else {
|
|
|
|
He.postJSON("/api/collections/"+collAlias+"/collect", params, callback);
|
|
|
|
}
|
|
|
|
};
|
2018-11-10 04:10:46 +01:00
|
|
|
var Move = function(el, id, collAlias, singleUser) {
|
2018-11-08 07:23:08 +01:00
|
|
|
var lbl = el.textContent;
|
|
|
|
try {
|
|
|
|
var m = lbl.match(/move to (.*)/);
|
|
|
|
lbl = m[1];
|
|
|
|
} catch (e) {
|
|
|
|
if (collAlias == '|anonymous|') {
|
|
|
|
lbl = "draft";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
el.textContent = "moving to "+lbl+"...";
|
|
|
|
if (collAlias == '|anonymous|') {
|
|
|
|
params = [id];
|
|
|
|
} else {
|
|
|
|
params = [{
|
|
|
|
id: id
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
var callback = function(code, resp) {
|
|
|
|
if (code == 200) {
|
|
|
|
for (var i=0; i<resp.data.length; i++) {
|
|
|
|
if (resp.data[i].code == 200) {
|
|
|
|
el.innerHTML = "moved to <strong>"+lbl+"</strong>";
|
|
|
|
el.onclick = null;
|
2018-11-10 04:10:46 +01:00
|
|
|
var pre = "/"+collAlias;
|
|
|
|
if (typeof singleUser !== 'undefined' && singleUser) {
|
|
|
|
pre = "";
|
|
|
|
}
|
|
|
|
var newPostURL = pre+"/"+resp.data[i].post.slug;
|
2018-11-08 07:23:08 +01:00
|
|
|
el.href = newPostURL;
|
|
|
|
el.title = "View on "+lbl;
|
|
|
|
try {
|
|
|
|
// Posts page
|
|
|
|
He.$('#post-'+resp.data[i].post.id+' > h3 > a')[0].href = newPostURL;
|
|
|
|
} catch (e) {
|
|
|
|
// Blog index
|
|
|
|
var $article = He.get('post-'+resp.data[i].post.id);
|
|
|
|
$article.className = 'norm moved';
|
|
|
|
if (collAlias == '|anonymous|') {
|
2018-11-10 04:10:46 +01:00
|
|
|
var draftPre = "";
|
|
|
|
if (typeof singleUser !== 'undefined' && singleUser) {
|
|
|
|
draftPre = "d/";
|
|
|
|
}
|
|
|
|
$article.innerHTML = '<p><a href="/'+draftPre+resp.data[i].post.id+'">Unpublished post</a>.</p>';
|
2018-11-08 07:23:08 +01:00
|
|
|
} else {
|
|
|
|
$article.innerHTML = '<p>Moved to <a style="font-weight:bold" href="'+newPostURL+'">'+lbl+'</a>.</p>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
el.innerHTML = "unable to move: "+resp.data[i].error_msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (collAlias == '|anonymous|') {
|
|
|
|
He.postJSON("/api/posts/disperse", params, callback);
|
|
|
|
} else {
|
|
|
|
He.postJSON("/api/collections/"+collAlias+"/collect", params, callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
move: Move,
|
|
|
|
multiMove: MultiMove,
|
|
|
|
};
|
|
|
|
}();
|