summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/switchboard_entries_controller.rb13
-rw-r--r--app/controllers/switchboards_controller.rb5
-rw-r--r--app/models/switchboard.rb21
-rw-r--r--app/models/switchboard_entry.rb2
-rw-r--r--app/serializers/switchboard_entry_serializer.rb2
-rw-r--r--app/serializers/switchboard_serializer.rb7
-rw-r--r--app/views/switchboards/_form_core.html.haml3
-rw-r--r--app/views/switchboards/app.js8
-rw-r--r--app/views/switchboards/show.html.erb40
9 files changed, 79 insertions, 22 deletions
diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb
index 32ca9bb..3f82976 100644
--- a/app/controllers/switchboard_entries_controller.rb
+++ b/app/controllers/switchboard_entries_controller.rb
@@ -3,8 +3,17 @@ class SwitchboardEntriesController < ApplicationController
authorize_resource :switchboard_entry, :through => :switchboard, :except => [:sort]
def index
- @switchboard_entries = @switchboard.switchboard_entries
- spread_breadcrumbs
+ if @switchboard
+ @switchboard_entries = @switchboard.switchboard_entries
+ spread_breadcrumbs
+ else
+ @switchboard_entries = SwitchboardEntry.where(:id => params[:ids])
+ end
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @switchboard_entries }
+ end
end
def show
diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb
index 8ceb96d..d3424ad 100644
--- a/app/controllers/switchboards_controller.rb
+++ b/app/controllers/switchboards_controller.rb
@@ -31,6 +31,9 @@ class SwitchboardsController < ApplicationController
def new
@switchboard = @user.switchboards.build
+ @switchboard.show_avatars = true
+ @switchboard.entry_width = 2
+ @switchboard.reload_interval = 2000
spread_breadcrumbs
end
@@ -68,7 +71,7 @@ class SwitchboardsController < ApplicationController
private
def switchboard_params
- params.require(:switchboard).permit(:name)
+ params.require(:switchboard).permit(:name, :reload_interval, :show_avatars, :entry_width)
end
def spread_breadcrumbs
diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb
index 74e2767..360de70 100644
--- a/app/models/switchboard.rb
+++ b/app/models/switchboard.rb
@@ -6,11 +6,32 @@ class Switchboard < ActiveRecord::Base
:presence => true,
:uniqueness => {:scope => :user_id}
+ validates :reload_interval,
+ :numericality => { :only_integer => true,
+ :greater_than => 250,
+ :allow_nil => true
+ }
+
+ validates :entry_width,
+ :numericality => { :only_integer => true,
+ :greater_than => 0,
+ :less_than => 5
+ }
+
belongs_to :user, :touch => true
has_many :switchboard_entries, :dependent => :destroy
has_many :sip_accounts, :through => :switchboard_entries
+ before_validation :convert_0_to_nil
+
def to_s
self.name.to_s
end
+
+ private
+ def convert_0_to_nil
+ if self.reload_interval == 0
+ self.reload_interval = nil
+ end
+ end
end
diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb
index 76d002f..faeba8c 100644
--- a/app/models/switchboard_entry.rb
+++ b/app/models/switchboard_entry.rb
@@ -5,6 +5,8 @@ class SwitchboardEntry < ActiveRecord::Base
belongs_to :switchboard, :touch => true
belongs_to :sip_account, :touch => true
+ has_many :phone_numbers, :through => :sip_account
+
validates :switchboard,
:presence => true
diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb
index dace1c5..0b5f4c1 100644
--- a/app/serializers/switchboard_entry_serializer.rb
+++ b/app/serializers/switchboard_entry_serializer.rb
@@ -1,3 +1,5 @@
class SwitchboardEntrySerializer < ActiveModel::Serializer
attributes :id, :name
+
+ has_many :phone_numbers, embed: :ids
end
diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb
index c460add..2912a56 100644
--- a/app/serializers/switchboard_serializer.rb
+++ b/app/serializers/switchboard_serializer.rb
@@ -1,6 +1,7 @@
class SwitchboardSerializer < ActiveModel::Serializer
- embed :ids, :include => true
-
attributes :id, :name
- has_many :switchboard_entries, :key => :switchboard_entry_ids, :root => :switchboardEntrys
+
+ embed :ids
+
+ has_many :switchboard_entries, :key => :switchboard_entrys
end
diff --git a/app/views/switchboards/_form_core.html.haml b/app/views/switchboards/_form_core.html.haml
index 61b5934..59a2442 100644
--- a/app/views/switchboards/_form_core.html.haml
+++ b/app/views/switchboards/_form_core.html.haml
@@ -1,2 +1,5 @@
.inputs
= f.input :name, :label => t('switchboards.form.name.label'), :hint => conditional_hint('switchboards.form.name.hint'), :autofocus => true
+ = f.input :reload_interval, :label => t('switchboards.form.reload_interval.label'), :hint => conditional_hint('switchboards.form.reload_interval.hint')
+ = f.input :show_avatars, :label => t('switchboards.form.show_avatars.label'), :hint => conditional_hint('switchboards.form.show_avatars.hint')
+ = f.input :entry_width, :label => t('switchboards.form.entry_width.label'), :hint => conditional_hint('switchboards.form.entry_width.hint')
diff --git a/app/views/switchboards/app.js b/app/views/switchboards/app.js
deleted file mode 100644
index a4aa100..0000000
--- a/app/views/switchboards/app.js
+++ /dev/null
@@ -1,8 +0,0 @@
-window.App = Ember.Application.create({
- rootElement: '#xxxyyy',
-
- ready: function() {
- App.view.appendTo('#xxxyyy');
- }
-});
-
diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb
index a4bdae0..87bb551 100644
--- a/app/views/switchboards/show.html.erb
+++ b/app/views/switchboards/show.html.erb
@@ -2,23 +2,47 @@
<script>
var switchboard_id = <%= @switchboard.id %>;
+ var show_avatars = <%= @switchboard.show_avatars.to_s %>;
+ var reload_interval = <%= @switchboard.reload_interval.nil? ? 0 : @switchboard.reload_interval %>;
</script>
<div class='row'>
<div class='span12'>
- <div id='container'></div>
-
- <script type="text/x-handlebars">
- <p>{{appName}}</p>
- <p>{{title}}</p>
+ <div id='emberjs-container'></div>
+ <script type="text/x-handlebars" data-template-name="application">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="switchboard">
- <h1>{{name}}</h1>
- <p>switchboard view marker</p>
- <p>Length: {{switchboardEntrys.length}}</p>
+ <h2>{{name}}</h2>
+
+ {{#if switchboardEntrys.length}}
+ <ul class="thumbnails">
+ {{#each switchboardEntry in switchboardEntrys}}
+ <li class="span2">
+ <div class="thumbnail">
+ <a class="thumbnail" href="/tenants/2/users/2">
+ <img alt="User-male-16x" class="img-rounded" src="/assets/icons/user-male-16x.png" style="width: 100px;">
+ </a>
+ <p>
+ <small>
+ {{switchboardEntry.name}}
+ <br>
+ <span class="label">
+ 33
+ </span>
+ <br>
+ <span class="label label-inverse">
+ <i class="icon-ban-circle icon-white"></i>
+ </span>
+ </small>
+ </p>
+ </div>
+ </li>
+ {{/each}}
+ </ul>
+ {{/if}}
</script>
</div>