Skip to content

Commit

Permalink
adding the settings functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
meyer429 committed Feb 23, 2012
1 parent 83764f2 commit 636d9f2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 41 deletions.
15 changes: 0 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ GEM
multi_json (~> 1.0)
addressable (2.2.4)
ansi (1.4.1)
archive-tar-minitar (0.5.2)
arel (2.2.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
columnize (0.3.4)
diff-lcs (1.1.3)
encryptor (1.1.3)
erubis (2.7.0)
Expand All @@ -61,8 +59,6 @@ GEM
json (1.6.4)
juggernaut (2.1.0)
redis
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
Expand Down Expand Up @@ -162,19 +158,9 @@ GEM
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.7.0)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubyntlm (0.1.1)
sprockets (2.0.3)
hike (~> 1.2)
Expand Down Expand Up @@ -206,5 +192,4 @@ DEPENDENCIES
rails3-generators
rspec (~> 2.7.0)
rspec-rails
ruby-debug19
turn
6 changes: 4 additions & 2 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def save_setting
options = {
:history => ahistory,
:skin => params["select_skin"],
:buddy_id => @session["buddy_id"]
:buddy_id => @session["buddy_id"],
:show_offline => params["show_offline"],
:idle_time => params["idle_time"]
}
Setting.save_settings(options)
Setting.save_settings(options, params["status"])
redirect_to :controller => 'buddies', :action => 'index'
end

Expand Down
12 changes: 8 additions & 4 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
class Setting < ActiveRecord::Base
belongs_to :buddy, :dependent => :destroy

def self.save_settings options
def self.save_settings options, nickname
unless options.empty?
if Setting.existsSetting(options[:buddy_id])
setting = Setting.get_settings(options[:buddy_id])
setting.history = options[:history]
setting.skin = options[:skin]
#these have not yet been implemented
setting.idle_time = 10
setting.buddy.nickname = nickname
setting.show_offline = (options[:show_offline] == "on")
setting.idle_time = options[:idle_time]
setting.msg_style = "Bubble"
setting.use_picture = 1
else
setting = Setting.new(options)
end
setting.save
setting.save
setting.buddy.save
return setting
end
end

def self.get_settings buddy_id
return Setting.where(:buddy_id => buddy_id)[0]
return Setting.where(:buddy_id => buddy_id)[0] || Setting.create(:buddy_id => buddy_id)
end

def self.existsSetting buddy_id
Expand Down
3 changes: 2 additions & 1 deletion app/views/buddies/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.buddyStatus{ :class => buddy["status"]}
.buddyName.elipsis{"data-filter-text" => buddy["name"].downcase}
=buddy["name"]
.buddyStatusMessage.elipsis Working very hard...
.buddyStatusMessage.elipsis
=buddy["nickname"]
.buddyListItemArrow
28 changes: 16 additions & 12 deletions app/views/layouts/application.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

%html
%head
%title Chat

<meta name="viewport" content="width=device-width, initial-scale=1">
%title Chat
= stylesheet_link_tag "custom"
= stylesheet_link_tag "single"
= stylesheet_link_tag "http://code.jquery.com/mobile/1.0/jquery.mobile.structure-1.0.min.css"
Expand All @@ -14,10 +15,13 @@
= javascript_include_tag "jquery-ui-1.8.16.custom.min.js"
= javascript_include_tag "comm"
= javascript_include_tag "chat"



= csrf_meta_tags

%script
= "settings_idle = " + @settings["idle_time"].to_s() + ";"
!= "settings = " + @settings.to_json({:except => [:buddy_id, :created_at, :use_picture, :id, :updated_at]}) + ";"

%body
%div{:id => "buddies", "data-role" => "page"}
#header-main
Expand All @@ -26,14 +30,14 @@
#status_circle{:class => @buddy.status}
#name
=@buddy.name
%select{ :name => "buddy-status", :id => "buddy-status", "data-role" => "none"}
%option{ :value => "Online"}
%select{ :name => "buddy-status", :id => "buddy-status", "data-role" => "none" }
%option{ :value => "Online", ((@buddy.status == "Online")? 'selected': 'notselected') => 'true'}
Online
%option{ :value => "Away"}
%option{ :value => "Away", ((@buddy.status == "Away")? 'selected':'notselected') => 'true'}
Away
%option{ :value => "Busy"}
%option{ :value => "Busy", ((@buddy.status == "Busy")? 'selected':'notselected') => 'true'}
Busy
%option{ :value => "Offline"}
%option{ :value => "Offline", ((@buddy.status == "Offline")? 'selected':'notselected') => 'true'}
Offline
%a{:href => "#buddies", :onclick => 'hide_notification()', :class => "buddiesLogoLink"}
%img#Go_logo{:src => "images/go_logo.png"}/
Expand Down Expand Up @@ -80,13 +84,13 @@
#name
=@buddy.name
%select{ :name => "buddy-status", :id => "buddy-status", "data-role" => "none"}
%option{ :value => "Online"}
%option{ :value => "Online", ((@buddy.status == "Online")? 'selected': 'notselected') => 'true'}
Online
%option{ :value => "Away"}
%option{ :value => "Away", ((@buddy.status == "Away")? 'selected':'notselected') => 'true'}
Away
%option{ :value => "Busy"}
%option{ :value => "Busy", ((@buddy.status == "Busy")? 'selected':'notselected') => 'true'}
Busy
%option{ :value => "Offline"}
%option{ :value => "Offline", ((@buddy.status == "Offline")? 'selected':'notselected') => 'true'}
Offline
%a{:href => "#buddies", :onclick => 'hide_notification()', :class => "buddiesLogoLink"}
%img#Go_logo{:src => "images/go_logo.png"}/
Expand Down
8 changes: 4 additions & 4 deletions app/views/settings/_settings.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=form_tag('save_settings', :id => 'Settings_form') do
=form_tag('/save_settings', :id => 'Settings_form') do
.settingsContainer.acordeon
.settingsListHeader.acordeonHeader
Settings
Expand All @@ -8,21 +8,21 @@
.settingsLeft
Set your status mesage
.settingsRight
%input.settings{:type => 'text', :style => "width: 100%;", "data-role" => "none"}
%input.settings{:type => 'text', :style => "width: 100%;text-align: left;", "data-role" => "none", :name => "status", :value => @buddy["nickname"]}

.settings.acordeonListItem
.settingsLeft
Lets others know im idle after
.settingsRight
%input.settings{:type => 'text', :style => "width: 34px;", "data-role" => "none"}
%input.settings{:type => 'text', :style => "width: 34px;", "data-role" => "none", :name => "idle_time", :value => @settings["idle_time"]}
mins of inactivity

.settings.acordeonListItem
.settingsLeft
Show Offline contacts :
.settingsRight
.CheckboxSwitch.green{:onclick => "toggleSwitch(this);"}
%input.CheckboxSwitch{:type => "checkbox", "data-role" => "none"}
%input.CheckboxSwitch{:type => "checkbox", "data-role" => "none", :name => "show_offline", ((!@settings["show_offline"].nil? &&@settings["show_offline"])? 'checked': 'unchecked' ) => "" }
.checkboxSwitchContainer
.switchOn ON
.switch
Expand Down
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120207193823) do
ActiveRecord::Schema.define(:version => 20120222122604) do

create_table "buddies", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -79,6 +79,8 @@
t.integer "idle_time"
t.string "msg_style"
t.integer "use_picture"
t.string "status_message", :default => ""
t.boolean "show_offline", :default => false
end

create_table "skins", :force => true do |t|
Expand Down
26 changes: 24 additions & 2 deletions public/javascripts/comm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ var channel_selected = undefined;
var hidden_messages_size = 0;
var timer = 0;
var invite = false;

var idleTimeOut = null;

$("#buddies").live('pageinit', function(event){
init();
acordeonInit();
resetIdle();
});

$(document).bind( "pagechange", function( e, data ) {
Expand Down Expand Up @@ -43,7 +44,7 @@ function init()
channel_subscribe(element.attr('name'));
init_chat(element.attr('name'),false,undefined);
});
$("#buddy-status").change(function(){
$("#buddy-status").live('change',function(){
$.ajax({
url: '/chat/set_status',
type: 'POST',
Expand Down Expand Up @@ -444,6 +445,7 @@ function setStatus(sender, message)
} else if(sender == data_session.buddy_id){
jQuery('#header-main #status_circle').removeClass('Online Offline Busy Away');
jQuery('#header-main #status_circle').addClass(message);
$('#buddy-status [value=' + message + ']').attr('selected',true);
}
}

Expand Down Expand Up @@ -569,3 +571,23 @@ function acordeonInit(){
});},0);
});
}
function toggleSwitch(element){
var input = jQuery(element).find('input')[0];
input.checked = !(input.checked);
}

$(document).live({
click: resetIdle,
keypress: resetIdle
});

function resetIdle(){
if (idleTimeOut){
clearTimeout(idleTimeOut);
}
idleTimeOut = setTimeout(setIdle, (settings.idle_time * 60 * 1000));
}

function setIdle(){
$('#buddy-status [value=Away]').attr('selected',true).parent().change();
}

0 comments on commit 636d9f2

Please sign in to comment.