added ability to change topic permission

This commit is contained in:
Connor Turland 2014-02-24 17:03:13 -08:00
parent 2e252c2647
commit f990ee1c8c
3 changed files with 97 additions and 47 deletions

View file

@ -188,7 +188,10 @@ function populateShowCard(node) {
if (authorizeToEdit(node)) {
var perm = document.createElement('div');
perm.className = 'permission canEdit';
var string = 'permission canEdit';
if (userid == node.data.$userid) string += ' yourTopic';
perm.className = string;
perm.innerHTML = html;
showCard.appendChild(perm);
} else {
@ -234,6 +237,34 @@ function populateShowCard(node) {
});
// ability to change permission
var selectingPermission = false;
if (userid == node.data.$userid ) {
$('.showcard .yourTopic .mapPerm').click(function() {
if (!selectingPermission) {
selectingPermission = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
if ( $(this).hasClass('co') ) {
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('pu') ) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('pr') ) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>');
}
$('.permissionSelect li').click(function(event) {
selectingPermission = false;
var permission = $(this).attr('class');
updateTopicPermission(node, permission);
event.stopPropagation();
});
} else {
selectingPermission = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.permissionSelect').remove();
}
});
}
// when you're typing a description, resize the scroll box to have space
$('.best_in_place_desc textarea').bind('keyup', function() {
var s = $('.showcard').find('.scroll');
@ -267,51 +298,5 @@ function populateShowCard(node) {
$(showCard).find('.go-link').attr('href', link);
node.setData("link", link);
});
$(showCard).find(".permActivator").bind('mouseover',
function () {
clearTimeout(MetamapsModel.topicPermTimer2);
that = this;
MetamapsModel.topicPermTimer1 = setTimeout(function() {
if (! MetamapsModel.topicPermSliding) {
MetamapsModel.topicPermSliding = true;
$(that).animate({
width: '203px',
height: '37px'
}, 300, function() {
MetamapsModel.topicPermSliding = false;
});
}
}, 300);
});
$(showCard).find(".permActivator").bind('mouseout',
function () {
clearTimeout(MetamapsModel.topicPermTimer1);
that = this;
MetamapsModel.topicPermTimer2 = setTimeout(function() {
if (! MetamapsModel.topicPermSliding) {
MetamapsModel.topicPermSliding = true;
$(that).animate({
height: '16px',
width: '16px'
}, 300, function() {
MetamapsModel.topicPermSliding = false;
});
}
},800);
}
);
//bind best_in_place ajax callbacks
$(showCard).find('.best_in_place_permission').bind("ajax:success", function() {
var permission = $(this).html();
var el = $(this).parents('.cardSettings').find('.mapPerm');
el.attr('title', permission);
if (permission == "commons") el.html("co");
else if (permission == "public") el.html("pu");
else if (permission == "private") el.html("pr");
node.setData("permission", permission);
});
}

View file

@ -700,6 +700,24 @@ function updateMetacode(node, metacode) {
});
}
function updateTopicPermission(node, permission) {
var mdata = { "topic": { "permission": permission } };
$.ajax({
type: "PUT",
dataType: 'json',
url: "/topics/" + node.id,
data: mdata,
success: function(data) {
$('.showcard .mapPerm').removeClass('co pu pr minimize').addClass( permission.substring(0,2) );
$('.permissionSelect').remove();
node.setData("permission", permission);
},
error: function(){
alert('failed to update permission');
}
});
}
function MconsoleReset() {
var tX = Mconsole.canvas.translateOffsetX;

View file

@ -195,6 +195,53 @@ padding-left: 24px;
.linkItem.mapPerm.pr {
background-image: url(MMCCicon_private.png);
}
.showcard .yourTopic .mapPerm:hover {
background-image: url(/assets/MMCCicon_maximize_arrow_black.png);
background-size: 31px 25px;
background-position-x: 8px;
cursor:pointer;
}
.showcard .yourTopic .mapPerm.minimize {
background-image: url(MMCCicon_minimize_arrow_black.png) !important;
background-size: 31px 25px;
background-position-x: 8px;
cursor: pointer;
}
.mapPerm .permissionSelect {
list-style: none;
width: 40px;
height: 80px;
position: relative;
top: 40px;
}
.mapPerm .permissionSelect li {
width: 40px;
height: 40px;
background-repeat: no-repeat;
background-position: center center;
background-size: 27px 27px;
background-color:white;
}
.mapPerm .permissionSelect .commons {
background-image: url(MMCCicon_commons.png);
}
.mapPerm .permissionSelect .public {
background-image: url(MMCCicon_public.png);
}
.mapPerm .permissionSelect .private {
background-image: url(MMCCicon_private.png);
}
.mapPerm .permissionSelect .commons:hover {
background-image: url(MMCCicon_commons_black.png);
}
.mapPerm .permissionSelect .public:hover {
background-image: url(MMCCicon_public_black.png);
}
.mapPerm .permissionSelect .private:hover {
background-image: url(MMCCicon_private_black.png);
}
.linkItem.topicPopout {
background-image: url(MMCCicon_pop-out_black.png);
}