Skip to content

Commit

Permalink
various fixes, use haml to draw some templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Youch committed Mar 21, 2011
1 parent 2d095c0 commit be99c95
Show file tree
Hide file tree
Showing 23 changed files with 332 additions and 405 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -4,6 +4,7 @@ source 'http://rubygems.org'
gem "rails", '3.0.5'

gem 'mysql'
gem 'haml', '>= 3.0.25'
gem 'mime-types', :require => 'mime/types'
gem 'radius'
gem 'RedCloth', :require => 'redcloth'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -76,6 +76,7 @@ GEM
gherkin (2.3.4)
json (~> 1.4.6)
gruff (0.3.6)
haml (3.0.25)
hpricot (0.8.4)
httparty (0.7.4)
crack (= 0.1.8)
Expand Down Expand Up @@ -176,6 +177,7 @@ DEPENDENCIES
factory_girl_rails
fakeweb
gruff
haml (>= 3.0.25)
hpricot
jquery-rails
libxml-ruby
Expand Down
18 changes: 7 additions & 11 deletions app/helpers/cms_helper.rb
Expand Up @@ -91,15 +91,11 @@ def webiva_search_widget # :nodoc:
def render_webiva_menu(menu,selected)
return '' unless menu
menu.items.map do |item|
<<-EOF
<li #{"class='selected'" if selected == item.identifier }>
<a href='#{url_for(item.url)}'>
<div class='menu_image menu_image_#{item.identifier}'><div></div></div>
<div class='menu_item_text'>#{h(item.name.t)}</div>
</a>
</li>
EOF
end.join("\n")
img = content_tag :div, content_tag(:div, ''), :class => "menu_image menu_image_#{item.identifier}"
txt = content_tag :div, item.name.t, :class => 'menu_item_text'
link = content_tag :a, img + txt, :href => url_for(item.url)
content_tag :li, link, :class => selected == item.identifier ? 'selected' : nil
end.join("\n").html_safe
end

def render_webiva_breadcrumbs(page_info)
Expand Down Expand Up @@ -875,13 +871,13 @@ def wizard_steps(wizard_step,wizard_max_step,opts={})
# Load a remote script over http or https as necessary
def remote_script(script)
prefix = request.ssl? ? 'https://' : 'http://'
"<script src='#{prefix}#{vh script}'></script>"
"<script src='#{prefix}#{vh script}'></script>".html_safe
end

# Load a remote stylesheet over http or https as necessary
def remote_stylesheet(stylesheet)
prefix = request.ssl? ? 'https://' : 'http://'
"<link href='#{prefix}#{vh stylesheet}' rel='stylesheet' type='text/css' />"
"<link href='#{prefix}#{vh stylesheet}' rel='stylesheet' type='text/css' />".html_safe

end

Expand Down
2 changes: 1 addition & 1 deletion app/models/domain_log_entry.rb
Expand Up @@ -14,7 +14,7 @@ class DomainLogEntry < DomainModel
scope :content_only, where('domain_log_entries.content_node_id IS NOT NULL')
def self.recent(from=nil); self.where('domain_log_entries.occurred_at > ?', from || 1.minute.ago); end
def self.between(from, to); self.where('domain_log_entries.occurred_at' => from..to); end
def self.valid_sessions; where('domain_log_sessions.`ignore` = 0 AND domain_log_sessions.domain_log_source_id IS NOT NULL').joins(:domain_log_sessions); end
def self.valid_sessions; where('domain_log_sessions.`ignore` = 0 AND domain_log_sessions.domain_log_source_id IS NOT NULL').joins(:domain_log_session); end
def self.session_stats; self.select('domain_log_session_id, count(*) as page_count, max(occurred_at) as last_entry_at, SUM(`value`) as session_value').group('domain_log_session_id'); end
def self.hits_n_visits(group_by=nil)
base_select = "count(*) AS hits, count( DISTINCT domain_log_session_id ) AS visits, SUM(IF(domain_log_entries.user_level=3,1, 0)) AS subscribers, SUM(IF(domain_log_entries.user_level=4,1, 0)) AS leads, SUM(IF(domain_log_entries.user_level=5,1, 0)) AS conversions, SUM(`value`) as total_value"
Expand Down
4 changes: 4 additions & 0 deletions app/models/domain_model.rb
Expand Up @@ -259,6 +259,10 @@ def full_identifier

class << self
alias_method :connection_active_record, :connection # :nodoc:

def connection
self.active_domain_id.blank? ? SystemModel.connection : connection_active_record
end
end

# create a seperate connection handler per domain
Expand Down
7 changes: 5 additions & 2 deletions app/models/site_template.rb
Expand Up @@ -25,6 +25,9 @@ class SiteTemplate < DomainModel

serialize :options

before_create :inital_setup
after_save :update_features_options

def self.site_template_options
self.select_options(:conditions => ['template_type = "site" and parent_id IS NULL'])
end
Expand Down Expand Up @@ -643,7 +646,7 @@ def update_options(opts)
self.options[:options] = opts
end

def before_create
def inital_setup
self.head ||= ''
self.options ||= {}
self.options = { :options => self.options[:options] || [],
Expand All @@ -654,7 +657,7 @@ def before_create
}
end

def after_save
def update_features_options
self.site_template_rendered_parts.clear

if self.domain_file_id != @old_domain_file_id
Expand Down
32 changes: 32 additions & 0 deletions app/views/application/_header.html.haml
@@ -0,0 +1,32 @@
%title= (@cms_page_info ? @cms_page_info[:page_title] : @title) || "CMS"
%META{:CONTENT => "text/html; charset=UTF-8", "HTTP-EQUIV" => "Content-Type"}
%META{:CONTENT => "NOINDEX, NOFOLLOW, NOCACHE", :NAME => "ROBOTS"}
= stylesheet_link_tag 'common'
= remote_stylesheet 'fonts.googleapis.com/css?family=Droid+Sans'
= theme_stylesheet_link_tag "admin_design", :media => 'all'
= theme_stylesheet_link_tag "admin_framework", :media => 'all'
:javascript
var AUTH_TOKEN = " form_authenticity_token.to_s ";
= remote_script 'ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js'
= remote_script 'ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js'
:javascript
$j = jQuery.noConflict();
= javascript_include_tag 'jaction'
= remote_script 'www.google.com/jsapi'
- unless @no_legacy_cs
= javascript_include_tag :legacy
= javascript_include_tag 'application'
= javascript_include_tag 'active_table'
= javascript_include_tag 'shortcut'
= javascript_include_tag 'exporter'
!= @header if @header
!= @extra_header if @extra_header
- if @js_header
- @js_header.uniq.each do |js|
- if js.to_s.include?('http://')
%script{:src => js, :type => "text/javascript"}
- else
= javascript_include_tag js
- if @css_header
- @css_header.uniq.each do |css|
= stylesheet_link_tag css
51 changes: 0 additions & 51 deletions app/views/application/_header.rhtml

This file was deleted.

126 changes: 126 additions & 0 deletions app/views/dashboard/index.html.haml
@@ -0,0 +1,126 @@
:javascript
Widget = {

update: function(id,params) {
new Ajax.Request("#{url_for :action => 'widget'}/" + id, { parameters: params } );
}

}
CMSDashboard = {
editing: false,


updateWidgets:function() {
this.editing ? this.editWidgets() : this.stopEditingWidgets();
},

editWidgets: function() {
$$('.dashboard_widget_title').invoke('addClassName','dashboard_widget_titlebar_move');
$$('.dashboard_widget_column_add').invoke('show');
$$('.dashboard_widget_tools').invoke('show');
$$('.dashboard_widget_title_edit').invoke('show');
$$('.dashboard_widget_hidden').invoke('show');

this.createSortables();
this.editing = true;
},

stopEditingWidgets: function() {
$$('.dashboard_widget_title').invoke('removeClassName','dashboard_widget_titlebar_move');
$$('.dashboard_widget_column_add').invoke('hide');
$$('.dashboard_widget_tools').invoke('hide');
$$('.dashboard_widget_title_edit').invoke('hide');
$$('.dashboard_widget_hidden').invoke('hide');
this.destroySortables();
this.editing = false;
},

toggleEdit: function() {
this.editing ? this.stopEditingWidgets() : this.editWidgets();
},

destroySortables: function() {
var zones = $$('.dashboard_widget_column');
zones.each(function(zone) { Sortable.destroy(zone); });
},

createSortables:function() {
var zones = $$('.dashboard_widget_column');
var zone_idxs = zones.pluck('id');

zones.each(function(zone) {
Sortable.create(zone.id, {
dropOnEmpty:true,
handle:'dashboard_widget_titlebar',
tag:'div',
only:'dashboard_widget',
containment: zone_idxs,
constraint:false,
onUpdate: CMSDashboard.updatePositions
});
});
},

positionTimer: null,

updatePositions: function() {
if(CMSDashboard.positionTimer) clearTimeout(CMSDashboard.positionTimer);
CMSDashboard.positionTimer = setTimeout(CMSDashboard.submitPositions,20);
},

submitPositions: function() {
CMSDashboard.positionTimer = null;
var zones = $$('.dashboard_widget_column');
var params = zones.map(function(zone) { return Sortable.serialize(zone) }).join("&");
new Ajax.Request('#{url_for(:action => 'positions')}',{ parameters: params });
},

addWidget: function(column) {
SCMS.remoteOverlay("#{url_for(:action => 'edit')}", { column: column });
},

submitWidgetForm: function(params) {
SCMS.updateOverlay("#{url_for(:action => 'edit')}", params);
},

editWidget: function(widget_id) {
SCMS.remoteOverlay("#{url_for(:action => 'edit')}", { widget_id: widget_id });
},

deleteWidget: function(widget_id) {
if(confirm("Are you sure you want to permanently delete your widget?")) {
new Ajax.Request('#{url_for(:action => 'remove')}', { parameters: { widget_id: widget_id } });
}

},

hideWidget: function(widget_id) {
if(confirm("Are you sure you want to hide this site widget (you will be able to added back again later)?")) {
new Ajax.Request('#{url_for(:action => 'remove')}', { parameters: { widget_id: widget_id }});
}
},

showWidget: function(widget_id) {
new Ajax.Request('#{url_for(:action => 'show')}', { parameters: { widget_id: widget_id }});
}


};


= action_panel :more => myself.has_role?(:editor_site_management) do |p|
= p.link 'Edit Widgets', { :icon => 'add.png', :url => 'javascript:void(0);', :id => 'edit_widgets' }, :onclick => 'CMSDashboard.editWidgets();', :"j-action" => 'swap', :swap => '#stop_editing_widgets,#edit_widgets'
= p.link 'Stop Editing Widgets', { :icon => 'remove.png', :hidden => true, :url => 'javascript:void(0);', :id => 'stop_editing_widgets' }, :onclick => 'CMSDashboard.stopEditingWidgets();', :"j-action" => 'swap', :swap => '#edit_widgets,#stop_editing_widgets'
- if myself.has_role?(:editor_site_management)
- more_action_panel do |p|
= p.link 'Edit Site Widgets',:action => :site_widgets
%hr/
%table{:cellpadding => "0", :cellspacing => "0", :width => "100%"}
%tr
- width = (100.0 / @widget_columns.length).floor;
- @widget_columns.each_with_index do |column,idx|
%td{:style => "width:#{width}%;", :valign => "top"}
.dashboard_widget_column_add{:onclick => "CMSDashboard.addWidget(#{idx});", :style => "display:none;"} Add Widget Here
.dashboard_widget_column{:id => "column_#{idx}"}
- column.each do |widget|
= render :partial => 'widget', :locals => {:widget => widget }

0 comments on commit be99c95

Please sign in to comment.