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 @@
//= require jquery_ujs
//= require turbolinks
//= require jquery.turbolinks
//= require bootstrap-sprockets
// www.chartjs.org/docs/
//= require Chart
//= require locastyle
......@@ -22,40 +21,41 @@
var visualised,non_visualised;
$(document).ready(function(){
visualised = document.getElementById("lobject").value;
non_visualised = document.getElementById("lobject_non").value;
var data_learning_objects = dataLearningObjects(visualised,non_visualised);
var charts = ["colections","users","learning_objects","accesses"];
for(i=0;i<charts.length;i++) {
if ( document.getElementById(charts[i]) ) {
var ctx = document.getElementById(charts[i]).getContext("2d");
switch ( charts[i] ){
case "colections":
new Chart(ctx).Pie(data_colections,pie_options);
var colections_chart = new Chart(ctx).Pie(data_colections);
break;
case "users":
new Chart(ctx).Bar(data_users,bar_options);
var users_chart = new Chart(ctx).Bar(data_users);
break;
case "learning_objects":
new Chart(ctx).Pie(data_learning_objects,pie_options);
var learning_objects_chart = new Chart(ctx).Pie(data_learnin_objects);
break;
case "accesses":
new Chart(ctx).Line(data_accesses,line_options);
var accesses_chart = new Chart(ctx).Line(data_accesses);
break;
default: null;
break;
}
if (document.getElementById("lobject") !== null) {
visualised = document.getElementById("lobject").value;
non_visualised = document.getElementById("lobject_non").value;
var data_learning_objects = dataLearningObjects(visualised,non_visualised);
var charts = ["colections","users","learning_objects","accesses"];
for(i=0;i<charts.length;i++) {
if ( document.getElementById(charts[i]) ) {
var ctx = document.getElementById(charts[i]).getContext("2d");
switch ( charts[i] ){
case "colections":
new Chart(ctx).Pie(data_colections,pie_options);
var colections_chart = new Chart(ctx).Pie(data_colections);
break;
case "users":
new Chart(ctx).Bar(data_users,bar_options);
var users_chart = new Chart(ctx).Bar(data_users);
break;
case "learning_objects":
new Chart(ctx).Pie(data_learning_objects,pie_options);
var learning_objects_chart = new Chart(ctx).Pie(data_learnin_objects);
break;
case "accesses":
new Chart(ctx).Line(data_accesses,line_options);
var accesses_chart = new Chart(ctx).Line(data_accesses);
break;
default: null;
break;
}
}
}
}
}
});
Chart.defaults.global = {
......
$ ->
$(document).on 'click', '*[data-institution]', ->
e = $(this)
e.popover({content: "Carregando..."}).popover('show')
$(document).on 'popover:opened', (e) ->
all = undefined
objects = undefined
institution_id = $(this).data('institution')
url = '/institutions/' + institution_id + '/users.json'
$.get '/users/list.json', (d) ->
all = d
$.get url, (d) ->
object = d
institution_id = $('[class=institution]',e.target).data('institution')
if institution_id?
url = '/institutions/' + institution_id + '/users.json'
$.get '/users/list.json', (d) ->
all = d
$.get url, (d) ->
object = d
# generate a lookup table for object's collections id
lookup = {}
i = 0
len = object.length
while i < len
lookup[object[i].id] = object[i]
i++
# generate a lookup table for object's collections id
lookup = {}
i = 0
len = object.length
while i < len
lookup[object[i].id] = object[i]
i++
# mark checked objects
i = 0
len = all.length
html = ''
while i < len
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 + '"'
if lookup[all[i].id] != undefined
html += " checked"
html += '>'
html += '<label for="' + name + '">' + all[i].name + '</label><br/>'
++i
# mark checked objects
i = 0
len = all.length
html = ''
while i < len
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 + '"'
if lookup[all[i].id] != undefined
html += " checked"
html += '>'
html += '<label for="' + name + '">' + all[i].name + '</label><br/>'
++i
$('.popover-content').html(html)
return
$('.ls-popover-content').html(html)
return
return
return
......
......@@ -14,6 +14,3 @@
*= require locastyle
*= 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
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
object_rid = params["object_rid"]
user_rid = params["user_rid"]
complaint_repository.destroy(user_rid, object_rid)
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
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
<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" >
<%= image_tag "icons/report-circle.png", alt: "Denunciar objeto" %>
</button>
<div id="complaints_list_popover" class="popover">
<%= render 'complaints/form' %>
</div>
<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" %>
<h6 style="color: #F05A28">denunciar objeto</h6>
</a>
<%= render 'complaints/form' %>
<%= form_for [:management, @complaint] do |f| %>
<fieldset>
<div class="ls-label " >
<%= 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 class="modal fade" id="complaints_list_modal" tabindex="-1" role="dialog" aria-labelledby="complaints_list_modal_label">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<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>
</div>
</div>
<%= f.hidden_field :object_rid, value: @learning_object.id %>
</fieldset>
<div align="center" >
<%= f.submit "Salvar", class:"submit_button" %>
<%#= link_to "Fechar",{}, class:"close_button" %>
<!--<button id="btn-fechar" class="btn btn-danger" data-dismiss="clickover">Fechar</button>-->
<%= form_for @complaint do |f| %>
<div class="modal-body" style="text-align:justify">
<fieldset>
<div class="ls-label">
<%= 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>
<%= 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>
<%end%>
</div>
......@@ -60,13 +60,7 @@
</a>
</div>
<div class="col-md-3 action">
<a type="button" class="add_to_complaint" data-toggle="popover" title="Denunciar Objeto">
<%= 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>
<%= render 'complaints/complaints_button' %>
</div>
<% else %>
<br/>
......
......@@ -25,7 +25,7 @@
<td><%= institution.address %></td>
<td><%= institution.description %></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>
</tr>
<% end %>
......
......@@ -9,7 +9,7 @@ Rails.application.routes.draw do
namespace :management do
root 'welcome#index'
resource :complaints
resource :complaints, except: ['create']
resources :institutions do
member do
post '/user/:user_id', as: :add_user, action: :add_user
......@@ -46,7 +46,11 @@ Rails.application.routes.draw do
end
root 'welcome#index'
resources :subjects, only: [:index, :show]
resource :complaints, only: ['create']
resources :institutions do
member do
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