register_modules/app/views/admin/admin_modules/index.html.erb

188 lines
5.0 KiB
Plaintext
Raw Normal View History

2014-12-30 11:52:45 +00:00
<%= javascript_include_tag "plugin/jquery.form.min" %>
<span id="index_table">
<%= render 'index'%>
</span>
<div id="approveModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Module Approval</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="approveModuleBtn">Approve</button>
</div>
</div>
2015-01-08 11:00:32 +00:00
<div id="editModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Edit Module</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="editModuleBtn">Save</button>
</div>
</div>
2014-12-30 11:52:45 +00:00
<div id="actionsModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3></h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="submitModalBtn"></button>
</div>
</div>
<script type="text/javascript">
2015-01-08 11:46:45 +00:00
var updateTableData = function(){
2015-01-08 12:03:07 +00:00
var data = {},
params = getUrlVars();
$.each(params,function(i,v){
data[v] = params[v];
})
2015-01-08 11:46:45 +00:00
$.ajax({
"url" : "/admin/admin_modules",
"dataType" : "html",
2015-01-08 12:03:07 +00:00
"data" : data,
2015-01-08 11:46:45 +00:00
"type" : "get"
}).done(function(data){
$("#index_table").html(data);
bindHandlers();
2014-12-30 11:52:45 +00:00
})
2015-01-08 11:46:45 +00:00
}
2015-01-08 11:00:32 +00:00
var bindHandlers = function(){
var actionsModal = $("#actionsModal");
var btn_type = null;
var module_id = null;
$(".action-btns").on("click",function(){
btn_type = $(this).attr("for");
module_id = $(this).data("id");
2014-12-30 11:52:45 +00:00
$.ajax({
2015-01-08 11:00:32 +00:00
"url" : $(this).attr("href"),
"type" : "get",
"dataType" : "html"
}).done(function(data){
actionsModal.find(".modal-body").html(data);
actionsModal.modal("show");
changeModalTitle(btn_type);
2014-12-30 11:52:45 +00:00
})
2015-01-08 11:00:32 +00:00
return false;
})
2014-12-30 11:52:45 +00:00
2015-01-08 11:00:32 +00:00
$("#submitModalBtn").on("click",function(){
var websites = [],
url = null;
actionsModal.find("input[type=checkbox]:checked").each(function(){
websites.push($(this).val());
})
switch(btn_type){
case "installation":
url = "/admin/admin_modules/install";
break;
case "uninstallation":
url = "/admin/admin_modules/uninstall";
break;
case "revoke_access":
url = "/admin/admin_modules/revoke";
break;
case "grant_access":
url = "/admin/admin_modules/grant";
break;
}
if(websites.length > 0 && confirm("Are you sure?")){
$.ajax({
"url" : url,
"data" : {"websites" : websites,"module" : module_id},
"dataType" : "json",
"type" : "post"
}).done(function(){
actionsModal.modal("hide");
})
}
})
var changeModalTitle = function(type){
var title = "",
btn_title = "";
switch(type){
case "installation":
title = "Select the sites to install this module.";
btn_title = "Install";
break;
case "uninstallation":
title = "Select the sites to unistall this module.";
btn_title = "Uninstall";
break;
case "revoke_access":
title = "Select the sites to revoke the access.";
btn_title = "Revoke";
break;
case "grant_access":
title = "Select the sites to grant the access.";
btn_title = "Grant";
break;
}
actionsModal.find(".modal-header h3").text(title);
$("#submitModalBtn").text(btn_title);
2014-12-30 11:52:45 +00:00
}
2015-01-08 11:46:45 +00:00
$(".edit-btn").on("click",function(){
var el = $(this);
$.ajax({
"url" : el.attr("href"),
"type" : "get",
"dataType" : "html"
}).done(function(form){
$("#editModal .modal-body").html(form);
$("#editModal").modal("show");
})
return false;
})
$(".approve-btn").on("click",function(){
var el = $(this);
$.ajax({
"url" : el.attr("href"),
"type" : "get",
"dataType" : "html"
}).done(function(form){
$("#approveModal .modal-body").html(form);
2015-01-08 12:03:07 +00:00
$("#approveModal").modal("show");
2015-01-08 11:46:45 +00:00
})
return false;
})
2014-12-30 11:52:45 +00:00
}
2015-01-08 12:03:07 +00:00
$("#editModal #editModuleBtn").on("click",function(){
$("#approveSiteForm").ajaxSubmit({
success : function(){
updateTableData();
$("#editModal").modal("hide");
}
})
})
$("#approveModal #approveModuleBtn").on("click",function(){
$("#approveSiteForm").ajaxSubmit({
success : function(){
updateTableData();
$("#approveModal").modal("hide");
}
})
})
2015-01-08 11:46:45 +00:00
bindHandlers();
2014-12-30 11:52:45 +00:00
</script>