fix for edit module and stuff

This commit is contained in:
Harry Bomrah 2015-01-08 19:00:32 +08:00
parent ddb0432cdf
commit 70644e2739
2 changed files with 103 additions and 72 deletions

View File

@ -16,21 +16,21 @@
<% else %> <% else %>
<% @registered_modules.each do |rm| %> <% @registered_modules.each do |rm| %>
<tr> <tr>
<td><%= rm.name %></td> <td width="20%"><%= rm.name %></td>
<% if rm.category.nil? %> <% if rm.category.nil? %>
<td>No category assigned.</td> <td width="20%">No category assigned.</td>
<% else %> <% else %>
<td><%= rm.category.title %></td> <td width="20%"><%= rm.category.title %></td>
<% end %> <% end %>
<% user = User.find(rm.create_user_id) %> <% user = User.find(rm.create_user_id) %>
<td><%= user.name rescue user.user_name %></td> <td width="20%"><%= user.name rescue user.user_name %></td>
<% if rm.approved %> <% if rm.approved %>
<td> <td>
<a class="btn btn-small btn-info action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/install_site_list?id=<%= rm.id.to_s %>" for="installation">Install</a> <a class="btn btn-small btn-info action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/install_site_list?id=<%= rm.id.to_s %>" for="installation">Install</a>
<a class="btn btn-small btn-danger action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/uninstall_site_list?id=<%= rm.id.to_s %>" for="uninstallation">Uninstall</a> <a class="btn btn-small btn-danger action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/uninstall_site_list?id=<%= rm.id.to_s %>" for="uninstallation">Uninstall</a>
<a class="btn btn-small btn-warning action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/revokelist?id=<%= rm.id.to_s %>" for="revoke_access">Revoke Access</a> <a class="btn btn-small btn-warning action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/revokelist?id=<%= rm.id.to_s %>" for="revoke_access">Revoke Access</a>
<a class="btn btn-small btn-success action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/grantlist?id=<%= rm.id.to_s %>" for="grant_access">Grant Access</a> <a class="btn btn-small btn-success action-btns" data-id="<%= rm.id.to_s %>" href="/admin/admin_modules/grantlist?id=<%= rm.id.to_s %>" for="grant_access">Grant Access</a>
<a class="btn btn-small" href="/admin/admin_modules/approve?module_id=<%= rm.id.to_s %>" data-toggle="modal" data-target="#approveModal">Edit</a> <a class="btn btn-small" href="/admin/admin_modules/approve?module_id=<%= rm.id.to_s %>" data-toggle="modal" data-target="#editModal">Edit</a>
</td> </td>
<% else %> <% else %>
<td> <td>

View File

@ -15,6 +15,19 @@
<button class="btn btn-primary" id="approveModuleBtn">Approve</button> <button class="btn btn-primary" id="approveModuleBtn">Approve</button>
</div> </div>
</div> </div>
<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>
<div id="actionsModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div id="actionsModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
@ -39,83 +52,101 @@
}).done(function(data){ }).done(function(data){
$("#index_table").html(data); $("#index_table").html(data);
$("#approveModal").modal("hide"); $("#approveModal").modal("hide");
bindHandlers();
}) })
} }
}) })
}) })
var actionsModal = $("#actionsModal"); $("#editModuleBtn").on("click",function(){
var btn_type = null; $("#approveSiteForm").ajaxSubmit({
var module_id = null; success : function(){
$(".action-btns").on("click",function(){ $.ajax({
btn_type = $(this).attr("for"); "url" : "/admin/admin_modules",
module_id = $(this).data("id"); "dataType" : "html",
$.ajax({ "type" : "get"
"url" : $(this).attr("href"), }).done(function(data){
"type" : "get", $("#index_table").html(data);
"dataType" : "html" $("#editModal").modal("hide");
}).done(function(data){ bindHandlers();
actionsModal.find(".modal-body").html(data); })
actionsModal.modal("show"); }
changeModalTitle(btn_type);
}) })
return false;
}) })
var bindHandlers = function(){
$("#submitModalBtn").on("click",function(){ var actionsModal = $("#actionsModal");
var websites = [], var btn_type = null;
url = null; var module_id = null;
actionsModal.find("input[type=checkbox]:checked").each(function(){ $(".action-btns").on("click",function(){
websites.push($(this).val()); btn_type = $(this).attr("for");
}) module_id = $(this).data("id");
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({ $.ajax({
"url" : url, "url" : $(this).attr("href"),
"data" : {"websites" : websites,"module" : module_id}, "type" : "get",
"dataType" : "json", "dataType" : "html"
"type" : "post" }).done(function(data){
}).done(function(){ actionsModal.find(".modal-body").html(data);
actionsModal.modal("hide"); actionsModal.modal("show");
changeModalTitle(btn_type);
}) })
} return false;
}) })
var changeModalTitle = function(type){ $("#submitModalBtn").on("click",function(){
var title = "", var websites = [],
btn_title = ""; url = null;
switch(type){ actionsModal.find("input[type=checkbox]:checked").each(function(){
case "installation": websites.push($(this).val());
title = "Select the sites to install this module."; })
btn_title = "Install"; switch(btn_type){
break; case "installation":
case "uninstallation": url = "/admin/admin_modules/install";
title = "Select the sites to unistall this module."; break;
btn_title = "Uninstall"; case "uninstallation":
break; url = "/admin/admin_modules/uninstall";
case "revoke_access": break;
title = "Select the sites to revoke the access."; case "revoke_access":
btn_title = "Revoke"; url = "/admin/admin_modules/revoke";
break; break;
case "grant_access": case "grant_access":
title = "Select the sites to grant the access."; url = "/admin/admin_modules/grant";
btn_title = "Grant"; break;
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);
} }
actionsModal.find(".modal-header h3").text(title);
$("#submitModalBtn").text(btn_title);
} }
</script> </script>