Skip to content
Snippets Groups Projects
Commit 26e83a09 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

fix complaints and fix popover in management

parent cb53aa0b
No related branches found
No related tags found
No related merge requests found
$ ->
$('.add_to_complaint').popover
html: true
placement: "left"
title: ->
$('#complaints_list_popover_title').html()
content: ->
$('#complaints_list_popover').html()
return
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks //= require turbolinks
//= require jquery.turbolinks //= require jquery.turbolinks
//= require bootstrap-sprockets
// www.chartjs.org/docs/ // www.chartjs.org/docs/
//= require Chart //= require Chart
//= require locastyle //= require locastyle
...@@ -22,40 +21,41 @@ ...@@ -22,40 +21,41 @@
var visualised,non_visualised; var visualised,non_visualised;
$(document).ready(function(){ $(document).ready(function(){
if (document.getElementById("lobject") !== null) {
visualised = document.getElementById("lobject").value; visualised = document.getElementById("lobject").value;
non_visualised = document.getElementById("lobject_non").value; non_visualised = document.getElementById("lobject_non").value;
var data_learning_objects = dataLearningObjects(visualised,non_visualised); var data_learning_objects = dataLearningObjects(visualised,non_visualised);
var charts = ["colections","users","learning_objects","accesses"]; var charts = ["colections","users","learning_objects","accesses"];
for(i=0;i<charts.length;i++) { for(i=0;i<charts.length;i++) {
if ( document.getElementById(charts[i]) ) { if ( document.getElementById(charts[i]) ) {
var ctx = document.getElementById(charts[i]).getContext("2d"); var ctx = document.getElementById(charts[i]).getContext("2d");
switch ( charts[i] ){ switch ( charts[i] ){
case "colections": case "colections":
new Chart(ctx).Pie(data_colections,pie_options); new Chart(ctx).Pie(data_colections,pie_options);
var colections_chart = new Chart(ctx).Pie(data_colections); var colections_chart = new Chart(ctx).Pie(data_colections);
break; break;
case "users": case "users":
new Chart(ctx).Bar(data_users,bar_options); new Chart(ctx).Bar(data_users,bar_options);
var users_chart = new Chart(ctx).Bar(data_users); var users_chart = new Chart(ctx).Bar(data_users);
break; break;
case "learning_objects": case "learning_objects":
new Chart(ctx).Pie(data_learning_objects,pie_options); new Chart(ctx).Pie(data_learning_objects,pie_options);
var learning_objects_chart = new Chart(ctx).Pie(data_learnin_objects); var learning_objects_chart = new Chart(ctx).Pie(data_learnin_objects);
break; break;
case "accesses": case "accesses":
new Chart(ctx).Line(data_accesses,line_options); new Chart(ctx).Line(data_accesses,line_options);
var accesses_chart = new Chart(ctx).Line(data_accesses); var accesses_chart = new Chart(ctx).Line(data_accesses);
break; break;
default: null; default: null;
break; break;
} }
}
}
} }
}
}); });
Chart.defaults.global = { Chart.defaults.global = {
......
$ -> $ ->
$(document).on 'click', '*[data-institution]', -> $(document).on 'popover:opened', (e) ->
e = $(this)
e.popover({content: "Carregando..."}).popover('show')
all = undefined all = undefined
objects = undefined objects = undefined
institution_id = $(this).data('institution') institution_id = $('[class=institution]',e.target).data('institution')
url = '/institutions/' + institution_id + '/users.json' if institution_id?
$.get '/users/list.json', (d) -> url = '/institutions/' + institution_id + '/users.json'
all = d $.get '/users/list.json', (d) ->
$.get url, (d) -> all = d
object = d $.get url, (d) ->
object = d
# generate a lookup table for object's collections id # generate a lookup table for object's collections id
lookup = {} lookup = {}
i = 0 i = 0
len = object.length len = object.length
while i < len while i < len
lookup[object[i].id] = object[i] lookup[object[i].id] = object[i]
i++ i++
# mark checked objects # mark checked objects
i = 0 i = 0
len = all.length len = all.length
html = '' html = ''
while i < len while i < len
name = 'user_' + all[i].rid.split(':').slice(-1)[0] name = 'user_' + all[i].rid.split(':').slice(-1)[0]
html += '<input type="checkbox" class="institutional-user-element" data-uid="' + all[i].id + '" data-institution-id="' + institution_id + '" id="' + name + '"' html += '<input type="checkbox" class="institutional-user-element" data-uid="' + all[i].id + '" data-institution-id="' + institution_id + '" id="' + name + '"'
if lookup[all[i].id] != undefined if lookup[all[i].id] != undefined
html += " checked" html += " checked"
html += '>' html += '>'
html += '<label for="' + name + '">' + all[i].name + '</label><br/>' html += '<label for="' + name + '">' + all[i].name + '</label><br/>'
++i ++i
$('.popover-content').html(html) $('.ls-popover-content').html(html)
return return
return return
return return
......
...@@ -14,6 +14,3 @@ ...@@ -14,6 +14,3 @@
*= require locastyle *= require locastyle
*= require_self *= require_self
*/ */
@import "bootstrap-sprockets";
@import "bootstrap";
class ComplaintsController < ApplicationController
include RepositoriesProxy
def create
@complaint = Complaint.new(complaint_params)
@complaint.user = current_user
@complaint.object = params[:complaint][:object_rid]
respond_to do |format|
if complaint_repository.report @complaint
format.html { redirect_to :back, notice: 'Denúncia realizada com sucesso.' }
else
format.html { redirect_to :back, alert: 'Objeto já foi denunciado por você.' }
end
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def complaint_params
params.require(:complaint).permit(:object, :message, :description)
end
end
...@@ -13,37 +13,13 @@ class Management::ComplaintsController < ManagementController ...@@ -13,37 +13,13 @@ class Management::ComplaintsController < ManagementController
end end
end end
def create
@complaint = Complaint.new(complaint_params)
@complaint.user = current_user
@complaint.object = params[:complaint][:object_rid]
respond_to do |format|
if complaint_repository.report @complaint
format.html { redirect_to :back, notice: 'Denúncia realizada com sucesso.' }
else
format.html { redirect_to :back, alert: 'Objeto já foi denunciado por você.' }
end
end
end
def destroy def destroy
object_rid = params["object_rid"] object_rid = params["object_rid"]
user_rid = params["user_rid"] user_rid = params["user_rid"]
complaint_repository.destroy(user_rid, object_rid) complaint_repository.destroy(user_rid, object_rid)
respond_to do |format| respond_to do |format|
format.html { redirect_to :back, notice: 'Complaint was successfully destroyed.' } format.html { redirect_to :back, notice: 'Denúncia excluída com sucesso.' }
end end
end end
private
# Never trust parameters from the scary internet, only allow the white list through.
def complaint_params
params.require(:complaint).permit(:object, :message, :description)
end
end end
<button type="button" class="btn btn-default btn-xs add_to_complaint " data-toggle="button" data-trigger="click" aria-pressed="false" autocomplete="off" title="Denunciar Objeto" border-style: "none" > <a type="button" class="add_to_complaint" data-toggle="modal" data-target="#complaints_list_modal" title="Denunciar Objeto">
<%= image_tag "icons/report-circle.png", alt: "Denunciar objeto" %> <%= image_tag "icons/report-circle.png", alt: "Denunciar objeto" %>
</button> <h6 style="color: #F05A28">denunciar objeto</h6>
</a>
<div id="complaints_list_popover" class="popover"> <%= render 'complaints/form' %>
<%= render 'complaints/form' %>
</div>
<div class="modal fade" id="complaints_list_modal" tabindex="-1" role="dialog" aria-labelledby="complaints_list_modal_label">
<%= form_for [:management, @complaint] do |f| %> <div class="modal-dialog" role="document">
<fieldset> <div class="modal-content">
<div class="modal-header">
<div class="ls-label " > <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Denunciar objeto</h4>
<%= f.collection_radio_buttons :message, @messages, :message, :message do |m| %>
<div class="radio" >
<%= f.radio_button :message, m.text %>
<%= f.label :message, m.text %>
</div>
<% end %>
<br><br>
<div align="center">
<%= f.text_area :description, placeholder: "mais informações", rows: "10", cols: "30" %>
</div> </div>
<%= form_for @complaint do |f| %>
</div> <div class="modal-body" style="text-align:justify">
<fieldset>
<%= f.hidden_field :object_rid, value: @learning_object.id %> <div class="ls-label">
</fieldset> <%= f.collection_radio_buttons :message, @messages, :message, :message do |m| %>
<div class="radio">
<%= f.radio_button :message, m.text %>
<%= f.label :message, m.text %>
<div align="center" > </div>
<%= f.submit "Salvar", class:"submit_button" %> <% end %>
<%#= link_to "Fechar",{}, class:"close_button" %> <br>
<!--<button id="btn-fechar" class="btn btn-danger" data-dismiss="clickover">Fechar</button>--> <%= f.text_area :description, placeholder: "mais informações", rows: "10", style: "width:100%" %>
</div>
<%= f.hidden_field :object_rid, value: @learning_object.id %>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<%= f.submit "Denunciar", class:"btn btn-danger submit_button" %>
</div>
<% end %>
</div>
</div> </div>
<%end%> </div>
...@@ -60,13 +60,7 @@ ...@@ -60,13 +60,7 @@
</a> </a>
</div> </div>
<div class="col-md-3 action"> <div class="col-md-3 action">
<a type="button" class="add_to_complaint" data-toggle="popover" title="Denunciar Objeto"> <%= render 'complaints/complaints_button' %>
<%= image_tag "icons/report-circle.png", alt: "Denunciar objeto" %>
<h6 style="color: #F05A28">denunciar objeto</h6>
</a>
<div id="complaints_list_popover" class="popover">
<%= render 'complaints/form' %>
</div>
</div> </div>
<% else %> <% else %>
<br/> <br/>
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<td><%= institution.address %></td> <td><%= institution.address %></td>
<td><%= institution.description %></td> <td><%= institution.description %></td>
<!-- <td class="ls-txt-right ls-regroup"><%= link_to 'Editar', edit_management_institution_path(institution.id) %></td> --> <!-- <td class="ls-txt-right ls-regroup"><%= link_to 'Editar', edit_management_institution_path(institution.id) %></td> -->
<td><%= link_to 'Usuários', 'javascript:void(0);', 'data-institution':ERB::Util.url_encode(institution.id) %></td> <td><%= link_to 'Usuários', 'javascript:void(0);', class: 'ls-btn-primary', 'data-institution': ERB::Util.url_encode(institution.id), 'data-ls-module': 'popover', 'data-content': '<span class="institution" data-institution="'+institution.id+'"></span>Carregando...', 'data-placement': 'bottom' %></td>
<td><%= link_to 'Excluir', management_institution_path(institution.id), method: :delete, data: { confirm: 'Você tem certeza?' } %></td> <td><%= link_to 'Excluir', management_institution_path(institution.id), method: :delete, data: { confirm: 'Você tem certeza?' } %></td>
</tr> </tr>
<% end %> <% end %>
......
...@@ -9,7 +9,7 @@ Rails.application.routes.draw do ...@@ -9,7 +9,7 @@ Rails.application.routes.draw do
namespace :management do namespace :management do
root 'welcome#index' root 'welcome#index'
resource :complaints resource :complaints, except: ['create']
resources :institutions do resources :institutions do
member do member do
post '/user/:user_id', as: :add_user, action: :add_user post '/user/:user_id', as: :add_user, action: :add_user
...@@ -46,7 +46,11 @@ Rails.application.routes.draw do ...@@ -46,7 +46,11 @@ Rails.application.routes.draw do
end end
root 'welcome#index' root 'welcome#index'
resources :subjects, only: [:index, :show] resources :subjects, only: [:index, :show]
resource :complaints, only: ['create']
resources :institutions do resources :institutions do
member do member do
get :users get :users
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment