removing more logic from templates + simpler coffeescript

This commit is contained in:
pixeldesu 2015-07-17 21:45:45 +02:00
parent 8232aa2a21
commit e1d38ebb89
3 changed files with 10 additions and 7 deletions

View File

@ -9,10 +9,10 @@
if data.success if data.success
($ "div#entries").prepend(data.render) # TODO: slideDown or something ($ "div#entries").prepend(data.render) # TODO: slideDown or something
# GitHub issue #26: # GitHub issue #26:
if document.getElementById('ib-delete-all') == undefined if document.getElementById('ib-delete-all')?
del_all_btn = ($ "button#ib-delete-all-author")
else
del_all_btn = ($ "button#ib-delete-all") del_all_btn = ($ "button#ib-delete-all")
else
del_all_btn = ($ "button#ib-delete-all-author")
del_all_btn.removeAttr 'disabled' del_all_btn.removeAttr 'disabled'
del_all_btn[0].dataset.ibCount = (Number del_all_btn[0].dataset.ibCount) + 1 del_all_btn[0].dataset.ibCount = (Number del_all_btn[0].dataset.ibCount) + 1
error: (jqxhr, status, error) -> error: (jqxhr, status, error) ->
@ -163,10 +163,10 @@ $(document).on "click", "button[name=ib-destroy]", ->
success: (data, status, jqxhr) -> success: (data, status, jqxhr) ->
if data.success if data.success
$("div.inbox-box[data-id=#{iid}]").slideUp() $("div.inbox-box[data-id=#{iid}]").slideUp()
if document.getElementById('ib-delete-all') == undefined if document.getElementById('ib-delete-all')?
del_all_btn = ($ "button#ib-delete-all-author")
else
del_all_btn = ($ "button#ib-delete-all") del_all_btn = ($ "button#ib-delete-all")
else
del_all_btn = ($ "button#ib-delete-all-author")
del_all_btn.removeAttr 'disabled' del_all_btn.removeAttr 'disabled'
del_all_btn[0].dataset.ibCount = (Number del_all_btn[0].dataset.ibCount) - 1 del_all_btn[0].dataset.ibCount = (Number del_all_btn[0].dataset.ibCount) - 1
showNotification data.message, data.success showNotification data.message, data.success

View File

@ -26,10 +26,13 @@ class InboxController < ApplicationController
end end
rescue rescue
flash.now[:error] = "No user with the name @#{params[:author]} found, showing default entries instead!" flash.now[:error] = "No user with the name @#{params[:author]} found, showing default entries instead!"
@not_found = true
@inbox @inbox
@inbox_count @inbox_count
end end
end end
@disabled = true if @inbox.empty? or @not_found
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js

View File

@ -25,5 +25,5 @@
.panel-heading .panel-heading
%h3.panel-title= t 'views.inbox.sidebar.actions.title' %h3.panel-title= t 'views.inbox.sidebar.actions.title'
.panel-body .panel-body
%button.btn.btn-block.btn-danger{type: :button, id: @author ? 'ib-delete-all-author' : 'ib-delete-all', disabled: (Inbox.where(user: current_user).empty? ? 'disabled' : nil), data: { ib_count: @inbox_count }}= t 'views.inbox.sidebar.actions.button' %button.btn.btn-block.btn-danger{type: :button, id: @author ? 'ib-delete-all-author' : 'ib-delete-all', disabled: (@disabled ? 'disabled' : nil), data: { ib_count: @inbox_count }}= t 'views.inbox.sidebar.actions.button'