summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-04 14:31:42 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-04 14:31:42 +0100
commitda3ae3cb90697c66beda10fb5d6cb6186055ed3f (patch)
tree7fe3f270694aeeb804021048167731da698ea662
parent5a58c0c41de983a72cdacd06c5be80f120d1e080 (diff)
parent87634e025711be508501cce8c05f23085dad8f9d (diff)
Merge branch 'phone_numbers_sortable' into develop
-rw-r--r--app/assets/javascripts/phone_number.js.coffee6
-rw-r--r--app/assets/stylesheets/application.css1
-rw-r--r--app/assets/stylesheets/phone_numbers.css.scss5
-rw-r--r--app/controllers/phone_numbers_controller.rb45
-rw-r--r--app/views/phone_numbers/_index_core.html.haml9
-rw-r--r--app/views/sip_accounts/show.html.haml8
-rw-r--r--app/views/softkeys/_index_core.html.haml5
-rw-r--r--config/routes.rb83
8 files changed, 62 insertions, 100 deletions
diff --git a/app/assets/javascripts/phone_number.js.coffee b/app/assets/javascripts/phone_number.js.coffee
new file mode 100644
index 0000000..ee983ee
--- /dev/null
+++ b/app/assets/javascripts/phone_number.js.coffee
@@ -0,0 +1,6 @@
+jQuery ->
+ $('#phone_numbers').sortable
+ axis: 'y'
+ handle: '.handle'
+ update: ->
+ $.post($(this).data('update-url'), $(this).sortable('serialize')) \ No newline at end of file
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 128a391..3e1cc66 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -14,4 +14,5 @@
*= require gemeinschaft-generic
*= require call_routes
*= require softkeys
+ *= require phone_numbers
*/
diff --git a/app/assets/stylesheets/phone_numbers.css.scss b/app/assets/stylesheets/phone_numbers.css.scss
new file mode 100644
index 0000000..141a1f7
--- /dev/null
+++ b/app/assets/stylesheets/phone_numbers.css.scss
@@ -0,0 +1,5 @@
+#phone_numbers .handle {
+ font-size: 12px;
+ color: #777;
+ cursor: move;
+} \ No newline at end of file
diff --git a/app/controllers/phone_numbers_controller.rb b/app/controllers/phone_numbers_controller.rb
index c562954..67c4922 100644
--- a/app/controllers/phone_numbers_controller.rb
+++ b/app/controllers/phone_numbers_controller.rb
@@ -1,22 +1,22 @@
class PhoneNumbersController < ApplicationController
- load_resource :phone_book_entry
- load_resource :sip_account
- load_resource :conference
- load_resource :fax_account
- load_resource :phone_number_range
- load_resource :callthrough
- load_resource :whitelist
- load_resource :access_authorization
- load_resource :hunt_group
- load_resource :hunt_group_member
- load_resource :automatic_call_distributor
- load_and_authorize_resource :phone_number, :through => [:phone_book_entry, :sip_account, :conference,
+ load_resource :phone_book_entry, :except => [:sort]
+ load_resource :sip_account, :except => [:sort]
+ load_resource :conference, :except => [:sort]
+ load_resource :fax_account, :except => [:sort]
+ load_resource :phone_number_range, :except => [:sort]
+ load_resource :callthrough, :except => [:sort]
+ load_resource :whitelist, :except => [:sort]
+ load_resource :access_authorization, :except => [:sort]
+ load_resource :hunt_group, :except => [:sort]
+ load_resource :hunt_group_member, :except => [:sort]
+ load_resource :automatic_call_distributor, :except => [:sort]
+ load_and_authorize_resource :phone_number, :except => [:sort], :through => [:phone_book_entry, :sip_account, :conference,
:fax_account, :phone_number_range, :callthrough,
:whitelist, :access_authorization, :hunt_group,
:hunt_group_member, :automatic_call_distributor]
- before_filter :set_and_authorize_parent
- before_filter :spread_breadcrumbs
+ before_filter :set_and_authorize_parent, :except => [:sort]
+ before_filter :spread_breadcrumbs, :except => [:sort]
def index
end
@@ -67,16 +67,6 @@ class PhoneNumbersController < ApplicationController
redirect_to m.(), :notice => t('phone_numbers.controller.successfuly_destroyed')
end
- def move_higher
- @phone_number.move_higher
- redirect_to :back
- end
-
- def move_lower
- @phone_number.move_lower
- redirect_to :back
- end
-
def call
sip_account = nil
current_user.sip_accounts.each do |user_sip_account|
@@ -94,6 +84,13 @@ class PhoneNumbersController < ApplicationController
redirect_to(:back)
end
+ def sort
+ params[:phone_number].each_with_index do |id, index|
+ PhoneNumber.update_all({position: index+1}, {id: id})
+ end
+ render nothing: true
+ end
+
private
def set_and_authorize_parent
@parent = @phone_book_entry || @sip_account || @conference || @fax_account ||
diff --git a/app/views/phone_numbers/_index_core.html.haml b/app/views/phone_numbers/_index_core.html.haml
index 80a1608..85982da 100644
--- a/app/views/phone_numbers/_index_core.html.haml
+++ b/app/views/phone_numbers/_index_core.html.haml
@@ -1,13 +1,18 @@
%table.table.table-striped
%thead
%tr
+ %th
- if phone_numbers.count > 1 && phone_numbers.first.phone_numberable_type == 'PhoneBookEntry'
%th= t('phone_numbers.index.name')
%th= t('phone_numbers.index.number')
- %tbody
+ %tbody{ :id => "phone_numbers", :'data-update-url' => sort_phone_numbers_url}
- for phone_number in phone_numbers.order(:position)
- %tr
+ = content_tag_for :tr, phone_number do
+ %td
+ - if phone_numbers.count > 1
+ %span.handle
+ %i.icon-resize-vertical
- if phone_number.phone_numberable_type == 'PhoneBookEntry'
%td= phone_number.name
%td= phone_number
diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml
index f48d927..72e10df 100644
--- a/app/views/sip_accounts/show.html.haml
+++ b/app/views/sip_accounts/show.html.haml
@@ -65,16 +65,16 @@
= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @sip_account.sip_accountable, :child => @sip_account }
-- if @sip_account.phone_numbers.any? || can?(:create, @sip_account.phone_numbers.build)
+- if @sip_account.phone_numbers.count > 0 || can?(:create, @sip_account.phone_numbers.build)
%h2= t('phone_numbers.index.page_title')
- - if @sip_account.phone_numbers.any?
+ - if @sip_account.phone_numbers.count > 0
= render "phone_numbers/index_core", :phone_numbers => @sip_account.phone_numbers
%br
= render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => PhoneNumber }
-- if @sip_account.softkeys.any? || can?(:create, @sip_account.softkeys.build)
+- if @sip_account.softkeys.count > 0 || can?(:create, @sip_account.softkeys.build)
%h2= t("softkeys.index.page_title")
- - if @sip_account.softkeys.any?
+ - if @sip_account.softkeys.count > 0
= render "softkeys/index_core", :softkeys => @sip_account.softkeys
%br
= render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Softkey } \ No newline at end of file
diff --git a/app/views/softkeys/_index_core.html.haml b/app/views/softkeys/_index_core.html.haml
index 70c96bc..e2cb16c 100644
--- a/app/views/softkeys/_index_core.html.haml
+++ b/app/views/softkeys/_index_core.html.haml
@@ -12,8 +12,9 @@
- cache(['softkeys_table_tr', I18n.locale, current_user, softkey]) do
= content_tag_for :tr, softkey do
%td
- %span.handle
- %i.icon-resize-vertical
+ - if softkeys.count > 1
+ %span.handle
+ %i.icon-resize-vertical
%td= softkey.function
%td= softkey.number
%td= softkey.label
diff --git a/config/routes.rb b/config/routes.rb
index 1ad621e..fbb32f6 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -33,95 +33,54 @@ Gemeinschaft42c::Application.routes.draw do
resources :rows
end
+ resources :phone_numbers, :only => [:sort] do
+ collection { post :sort }
+ end
+
resources :acd_agents, :only => [] do
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
resources :automatic_call_distributors, :only => [] do
resources :acd_agents
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
resources :hunt_group_members, :only => [] do
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
resources :hunt_groups, :only => [] do
resources :hunt_group_members
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
if GsParameter.get('CALLTHROUGH_HAS_WHITELISTS') == true
resources :whitelists, :only => [] do
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
end
resources :access_authorizations, :only => [] do
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
resources :fax_documents
resources :fax_accounts, :only => [] do
resources :fax_documents
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
resources :gemeinschaft_setups, :only => [:new, :create]
resources :phone_number_ranges, :only => [] do
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
resources :conferences, :only => [] do
resources :conference_invitees
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
end
resources :phone_numbers, :only => [] do
@@ -260,12 +219,7 @@ Gemeinschaft42c::Application.routes.draw do
resources :callthroughs, :only => [] do
resources :access_authorizations
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
if GsParameter.get('CALLTHROUGH_HAS_WHITELISTS') == true
resources :whitelists
end
@@ -277,12 +231,7 @@ Gemeinschaft42c::Application.routes.draw do
resources :sip_accounts, :only => [] do
resources :phones_sip_accounts
- resources :phone_numbers do
- member do
- put 'move_higher'
- put 'move_lower'
- end
- end
+ resources :phone_numbers
resources :softkeys
resources :call_histories do
collection do
@@ -313,8 +262,6 @@ Gemeinschaft42c::Application.routes.draw do
resources :phone_book_entries, :only => [ :index, :show ] do
resources :phone_numbers do
member do
- put 'move_higher'
- put 'move_lower'
put 'call'
end
end