From f5c080efd4a75220d475db7efa937426bb5937e2 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 3 Apr 2012 18:25:41 +0800 Subject: [PATCH] Model commit --- app/assets/javascripts/orbitdesktop.js | 2 +- app/controllers/desktop_controller.rb | 10 +++++++++- app/models/desktop.rb | 16 ++++++++++++++++ app/models/group.rb | 14 ++++++++++++++ app/models/section.rb | 16 ++++++++++++++++ app/models/tile.rb | 8 ++++++++ app/models/user/user.rb | 8 +++++++- 7 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 app/models/desktop.rb create mode 100644 app/models/group.rb create mode 100644 app/models/section.rb create mode 100644 app/models/tile.rb diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 24180334..c2182195 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -65,7 +65,7 @@ var orbitDesktop = function(dom){ }) $(window).resize(function(){ var ww = $(window).width(); - $("img#thmbackground").attr({"width":ww}) + $("img#thmbackground").attr({"width":ww}); }); $(o.contentHolder).mousemove(function(event){ /*if(($(window).width()-50)<=event.pageX){ diff --git a/app/controllers/desktop_controller.rb b/app/controllers/desktop_controller.rb index a8dfb275..56b4b58b 100644 --- a/app/controllers/desktop_controller.rb +++ b/app/controllers/desktop_controller.rb @@ -1,6 +1,6 @@ class DesktopController< ApplicationController layout 'desktop' - + before_filter :authenticate_user! def index end @@ -16,4 +16,12 @@ class DesktopController< ApplicationController def sections render :layout => false end + + def save_desktop_theme + + end + + def get_desktop_theme + + end end \ No newline at end of file diff --git a/app/models/desktop.rb b/app/models/desktop.rb new file mode 100644 index 00000000..e88d352b --- /dev/null +++ b/app/models/desktop.rb @@ -0,0 +1,16 @@ +class Desktop + include Mongoid::Document + include Mongoid::Timestamps + + field :theme, default: "default" + + belongs_to :user + has_many :sections, :autosave => true, :dependent => :destroy + + before_create :initialize_section + + def initialize_section + user.self.build_section + end + +end \ No newline at end of file diff --git a/app/models/group.rb b/app/models/group.rb new file mode 100644 index 00000000..13668093 --- /dev/null +++ b/app/models/group.rb @@ -0,0 +1,14 @@ +class Group + include Mongoid::Document + include Mongoid::Timestamps + + belongs_to :section + has_many :tiles, :autosave => true, :dependent => :destroy + before_create :initialize_tile + + def initialize_tile + self.build_tile + end + +end + \ No newline at end of file diff --git a/app/models/section.rb b/app/models/section.rb new file mode 100644 index 00000000..7272efcf --- /dev/null +++ b/app/models/section.rb @@ -0,0 +1,16 @@ +class Section + include Mongoid::Document + include Mongoid::Timestamps + + field :name, default: "Section" + + belongs_to :desktop + has_many :groups, :autosave => true, :dependent => :destroy + + before_create :initialize_group + + def initialize_group + self.build_group + end + +end \ No newline at end of file diff --git a/app/models/tile.rb b/app/models/tile.rb new file mode 100644 index 00000000..010b9376 --- /dev/null +++ b/app/models/tile.rb @@ -0,0 +1,8 @@ +class Tile + include Mongoid::Document + include Mongoid::Timestamps + + belongs_to :group + + +end diff --git a/app/models/user/user.rb b/app/models/user/user.rb index d74a543b..39fec3f0 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -16,11 +16,13 @@ class User has_many :privilege_apps, :inverse_of => :privilege_users, :class_name => "AppAuth" has_many :managing_apps,:class_name => "AppManager" - + has_one :desktop, :autosave => true, :dependent => :destroy belongs_to :role has_and_belongs_to_many :sub_roles accepts_nested_attributes_for :attribute_values, :allow_destroy => true + before_create :initialize_desktop + def avb_apps sub_role_ids_ary=self.sub_roles.collect{|t| t.id} query1 = AppAuth.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: self.id) @@ -53,4 +55,8 @@ class User User.find(id) rescue nil end + def initialize_desktop + self.build_desktop + end + end