change status of a table via JS

1.0
Javier Álvarez Medina 14 years ago
parent 3327e5d5a7
commit 63c5ef7ecc

@ -26,7 +26,7 @@ class Admin::TablesController < ApplicationController
def show
@table = Table.select(:id,:name,:privacy,:user_id,:tags).filter(:id => params[:id]).first
raise ActiveRecord::RecordNotFound if @table.user_id != current_user.id && @table.private?
#raise ActiveRecord::RecordNotFound if @table.user_id != current_user.id && @table.private?
end
end

@ -219,7 +219,7 @@ class Api::Json::TablesController < ApplicationController
def load_table
@table = Table.select(:id,:user_id,:name,:privacy).filter(:id => params[:id]).first
raise ActiveRecord::RecordNotFound if @table.user_id != current_user.id && @table.private?
#raise ActiveRecord::RecordNotFound if @table.user_id != current_user.id && @table.private?
end
end

@ -13,8 +13,14 @@
//SUBHEADER EVENTS AND FLOATING WINDOWS
// change table status
//Save operation loader
$('section.subheader').append(
'<div class="performing_op">' +
'<p class="loading">Loading...</p>'+
'</div>');
// change table status
$('div.inner_subheader div.left').append(
'<span class="privacy_window">'+
'<ul>'+
@ -22,28 +28,40 @@
'<li class="private '+((status=="private")?'selected':'')+'"><a href="#"><strong>Private</strong> (visible to you)</a></li>'+
'</ul>'+
'</span>');
$('span.privacy_window ul li a').livequery('click',function(ev){
ev.stopPropagation();
ev.preventDefault();
var parent_li = $(this).parent();
if (parent_li.hasClass('selected')) {
$('span.privacy_window').hide();
} else {
var old_value = $('span.privacy_window ul li.selected a strong').text().toLowerCase();
$('span.privacy_window ul li').removeClass('selected');
parent_li.addClass('selected');
var new_value = $('span.privacy_window ul li.selected a strong').text().toLowerCase();
$('span.privacy_window').hide();
$('p.status a').removeClass('public private').addClass(new_value).text(new_value);
changesRequest('/toggle_privacy','privacy',new_value.toUpperCase(),old_value);
}
});
$('p.status a').livequery('click',function(ev){
ev.stopPropagation();
ev.preventDefault();
var status_position = $('p.status a').position();
var privacy_window = $(this).parent().parent().children('span.privacy_window');
if (privacy_window.is(':visible')) {
privacy_window.hide();
} else {
var status_position = $('p.status a').position();
privacy_window.css('left',status_position.left-72+'px').show();
}
});
// End table status binding
// change save to unsaved table
// $('div.inner_subheader div.right').append(
// '<span class="advanced_options">'+
// '<a href="#" class="advanced">advanced<span></span></a>'+
// '<ul>'+
// '<li><a href="#">Export data...</a></li>'+
// '<li><a href="#">Save table as...</a></li>'+
// '</ul>'+
// '</span>');
@ -73,26 +91,68 @@
$('body').unbind('click');
}
});
});
function changesRequest(param,values) {
function changesRequest(url_change,param,value,old_value) {
//show loader
$('div.performing_op').show();
var params = {};
params[param] = values;
params[param] = value;
$.ajax({
dataType: 'jsonp',
method: "GET",
url: '/api/json/tables/'+table_id+'',
dataType: 'json',
type: "PUT",
url: '/api/json/tables/'+table_id+url_change,
data: params,
success: function(data) {
console.debug(data);
successActionPerform(param);
},
error: function(e) {
console.debug(e);
errorActionPerforming(param,old_value);
}
});
}
function successActionPerform(param) {
switch (param) {
case 'privacy': $('div.performing_op p').removeClass('loading').addClass('success').text('The status has been changed');
var width_text = $('div.performing_op p').width();
$('div.performing_op').css('margin-left','-'+(width_text/2)+'px');
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
default:
}
$('div.performing_op').delay(1000).fadeOut(function(){resetLoader()});
}
function errorActionPerforming(param, old_value) {
switch (param) {
case 'privacy': $('div.performing_op p').removeClass('loading').addClass('error').text('The status has not been changed. Try again later.');
var width_text = $('div.performing_op p').width();
$('div.performing_op').css('margin-left','-'+(width_text/2)+'px');
$('span.privacy_window ul li').removeClass('selected');
$('span.privacy_window ul li.'+old_value).addClass('selected');
$('p.status a').removeClass('public private').addClass(old_value).text(old_value);
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
default:
}
$('div.performing_op').delay(1000).fadeOut(function(){resetLoader()});
}
function resetLoader() {
$('div.performing_op p').removeClass('success').addClass('loading').text('Loading...');
var width_text = $('div.performing_op p').width();
$('div.performing_op').css('margin-left','-'+(width_text/2)+'px');
}

@ -190,11 +190,11 @@
'<p class="count">Now vizzualizing 50 of X,XXX</p>'+
'</div>');
//Save operation loader
$(table).parent().parent().children('section.subheader').append(
'<div class="performing_op">' +
'<p class="loading">Loading...</p>'+
'</div>');
// //Save operation loader
// $(table).parent().parent().children('section.subheader').append(
// '<div class="performing_op">' +
// '<p class="loading">Loading...</p>'+
// '</div>');
@ -255,9 +255,7 @@
'<p>You can <a href="#">add it manually</a> or <a href="#">import a file</a></p>'+
'</div>'
);
methods.resizeTable();
},

@ -57,11 +57,7 @@ div.table_position div.loading.loading_previous {margin:59px 0 0 0; border-botto
div.table_position div.loading p {width:100%; text-align:center; font:bold 13px "Helvetica"; color:#666666;}
div.table_position div.loading p.count {width:100%; padding:5px 0 0 0; text-align:center; font:normal 11px "Helvetica"; color:#B3B3B3;}
div.table_position div.loading img {position:absolute; width:25; height:25px ; margin:0 0 0 -13px; top:12px; left:50%;}
/*performing operation*/
div.performing_op {position:absolute; bottom:0; left:50%; margin:0 0 0 -50px; padding:8px 12px; background:#FFEAA4; border-bottom:1px solid #D0C090; z-index:100; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px;}
div.performing_op p {font:normal 13px Arial; color:#333333;}
div.performing_op p.loading {padding:0 0 0 20px; background:url('/images/admin/icons/watch.png') no-repeat 0 1px;}

@ -16,14 +16,14 @@ section.subheader div.mamufas {float:left; width:100%; background:url('/images/a
section.subheader div.left {position:relative; float:left; width:600px; height:88px; padding:15px 0 0 0; margin:0 0 0 40px;}
section.subheader h2 {float:left; width:auto; font:bold 21px Arial; color:white;}
section.subheader p.status {float:left; width:auto;}
section.subheader p.status a {float:left; padding:2px 7px; margin:4px 0 0 10px; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; font:bold 11px Arial; color:white; text-decoration:none;}
section.subheader p.status a {float:left; padding:2px 7px; margin:4px 0 0 10px; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; font:bold 11px Arial; color:white; text-decoration:none; text-transform:uppercase;}
section.subheader p.status a.public {background:#6FBE6F;}
section.subheader p.status a.private {background:#FF3300;}
section.subheader p.status a.save {background:#FFCC00;}
section.subheader p.status a.selected {background:black; color:white;}
section.subheader p.status a:hover {background:black;}
section.subheader p.status a.save:hover {background:#FFCC00;}
section.subheader span.privacy_window {position:absolute; display:none; width:216px; height:108px; background:url('/images/admin/table/privacy_options_bkg.png') no-repeat center center;}
section.subheader span.privacy_window {position:absolute; display:none; top:18px; width:216px; height:108px; background:url('/images/admin/table/privacy_options_bkg.png') no-repeat center center;}
section.subheader span.privacy_window ul {float:left; width:175px; margin:34px 0 0 20px;}
section.subheader span.privacy_window ul li {width:161px; padding:5px 7px 6px; margin:0 0 2px; border-radius:3px; -webkit-border-radius:3px; -moz-border-radius:3px;}
section.subheader span.privacy_window ul li.last {margin:0;}
@ -52,8 +52,6 @@ section.subheader div.right p.settings a.delete {padding:0 3px 0 0; color:#FF330
section.subheader div.right p.settings a.delete:hover {color:#FF4400;}
section.subheader div.right p.settings a.settings {padding:0 20px 0 3px; color:white; background:url('/images/admin/icons/settings.png') no-repeat right 1px;}
section.subheader div.right p.settings a.settings:hover {color:white;}
section.subheader div.right span.advanced_options {position:absolute; display:none; right:-10px; top:9px; width:122px; z-index:100;}
section.subheader div.right span.advanced_options a.advanced {position:relative; float:right; padding:7px 29px 7px 9px; font:normal 13px Arial; text-shadow:0 1px black;
text-decoration:none; color:#949BAA; z-index:100; border:1px solid black; border-bottom:0; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px;
@ -64,13 +62,19 @@ section.subheader div.right span.advanced_options ul {float:left; width:100px; h
section.subheader div.right span.advanced_options ul li {background:none;}
section.subheader div.right span.advanced_options ul li a {background:none; font:normal 11px "Helvetica"; color:white; text-decoration:none;}
section.subheader div.right span.advanced_options ul li a:hover {text-decoration:underline;}
section.subheader div.right span.paginate {position:absolute; right:0; bottom:5px; width:100%;}
section.subheader div.right span.paginate a {float:right; width:27px; height:23px; text-indent:-9999px;}
section.subheader div.right span.paginate a.previous {margin:0 3px 0 0; background:url('/images/admin/icons/left_button.png') no-repeat 0 0;}
section.subheader div.right span.paginate a.next {background:url('/images/admin/icons/right_button.png') no-repeat 0 0;}
section.subheader div.right span.paginate a:hover {background-position:0 -23px;}
/*performing operation*/
section.subheader div.performing_op {position:absolute; display:none; bottom:0; left:50%; margin:0 0 0 -50px;}
section.subheader div.performing_op p {font:normal 13px Arial; color:#333333; padding:8px 12px; border-bottom:1px solid #D0C090; z-index:100; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; text-align:center;}
section.subheader div.performing_op p.loading {padding:8px 12px 8px 32px; background:url('/images/admin/icons/watch.png') no-repeat 12px 9px #FFEAA4;}
section.subheader div.performing_op p.success {padding:8px 12px; background:#99CC66; border-bottom-color:#A5BB93; color:#111111;}
section.subheader div.performing_op p.error {padding:8px 12px; background:#FF5F5F; border-bottom-color:#D05153; color:white;}
/*MAP*/

Loading…
Cancel
Save