Skip to content

Commit

Permalink
merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
saberma committed Jun 30, 2011
2 parents 3b91a8d + 1f41ba1 commit e214b58
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 24 deletions.
8 changes: 8 additions & 0 deletions app/coffeescripts/controllers/emails.coffee
Expand Up @@ -21,7 +21,15 @@ App.Controllers.Emails = Backbone.Controller.extend
$('#add-subscription-btn').show()
false

$('#email_include_html').change ->
$('#html_form').toggle()
false

$(document).ready ->

if $('#email_include_html').attr('checked')
$('#html_form').show()

if $('.order-subscription').size() == 0
$('#order-notification-list').hide()
$('#add-subscription-btn').show()
Expand Down
1 change: 1 addition & 0 deletions app/controllers/emails_controller.rb
Expand Up @@ -24,6 +24,7 @@ def follow
unless subscribe.save
flash[:error] = subscribe.errors.full_messages[0]
render template: "shared/error_msg"
return
end
else
subscribe.user_id = sub
Expand Down
2 changes: 1 addition & 1 deletion app/models/subscribe.rb
Expand Up @@ -2,7 +2,7 @@ class Subscribe < ActiveRecord::Base
belongs_to :shop
belongs_to :user

validates :address, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }, allow_nil: true
validates :address, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }, allow_nil: true,uniqueness: true

def email_address
address || user.email
Expand Down
7 changes: 4 additions & 3 deletions app/views/emails/_subscription.html.haml
Expand Up @@ -2,8 +2,9 @@
%td{colspan: 2}
%span.note 发送邮件给:
%strong=subscribtion_title(s)
%td.r
%a
send test notification
-#
%td.r
%a
send test notification
%td.r{:style => "width:25px"}
=link_to image_tag('admin/icons/trash.gif'), unfollow_path(s), remote: true, method: :delete, confirm: '您确定要删除?', title: '删除它', class: :del
46 changes: 26 additions & 20 deletions app/views/emails/edit.html.haml
@@ -1,22 +1,23 @@
%h2#title Editing template Order Confirmation
-use_javascripts 'controllers/emails'
%h2#title==编辑#{KeyValues::Mail::Type.find_by_code(email.mail_type).name}模板
#action-links
%ul
=render partial:"shared/noscript"
=render partial:"shared/upgrade_ie"
#action-links{:style => "margin-bottom: 10px"}
%ul
%li.no-icon
%a{:href => "/admin/notifications"} Go back
%a{:href => "/admin/notifications"}=w('back')
%br/
%h3==#{KeyValues::Mail::Type.find_by_code(email.mail_type).name}模板
%p=KeyValues::Mail::Type.find_by_code(email.mail_type).des
.form-group
.form-group-content
%h3 Plain text email template
%h3 纯文本模板
%p
In the template below you can only use text and
在下面的模板中,只允许使用纯文本格式,
= succeed "." do
%a{:href => "http://wiki.shopify.com/Email_Variable_Reference", :target => "wiki", :title => "Open Wiki in a new window"} email variables
%a{:href => "http://wiki.shopify.com/Email_Variable_Reference", :target => "wiki", :title => "Open Wiki in a new window"} 可用于邮件模板中的参数
=form_for email do |f|
%dl
%dt=f.label :title
Expand All @@ -27,29 +28,34 @@
%li#status-message
%li#status-errorlist{:style => "font-weight: bold"}
=f.text_area :body,rows:30,cols:90,class:'compile-ok',id:'source'
.preview
%a{:href => "#", :onclick => "previewEmailTemplate(); return false;"} Preview plain text email
/ .preview
%h3 Enable HTML template
-#
.preview
%a{:href => "#", :onclick => "previewEmailTemplate(); return false;"} Preview plain text email
%h3 启用HTML模板
%p
HTML emails give you more formatting options in your templates, but you have to know HTML. Shopify emails both the plain text and HTML email templates and the recipient's mail client will select which one to render.
HTML 邮件模板给你提供更多的格式选择,但是,你需要了解HTML的一些知识。您可以选择通过哪一种方式来渲染邮件。
%br/
%input{:name => "email[include_html]", :type => "hidden", :value => "0"}/
%input#email_include_html{:name => "email[include_html]", :type => "checkbox", :value => "1"}/
%label{:for => "email_include_html"} Enable HTML template
=f.check_box :include_html
%label{:for => "email_include_html"} 使用HTML 模板
#html_form{:style => "display:none"}
%dl
%dt
%label{:for => "email_body"} Modify your HTML email template
%label{:for => "email_body"} 修改您的HTML邮件模板
%dd
%ul#status-log.nobull.field-with-errors{:style => "display:none; margin: 3px 3px 10px 3px;"}
%li#status-message
%li#status-errorlist{:style => "font-weight: bold"}
%textarea#source.compile-ok{:cols => "90", :name => "email[body_html]", :rows => "30"}
.preview
%a{:href => "#", :onclick => "previewHtmlEmailTemplate(); return false;"} Preview HTML email
/ .preview
-#
.preview
%a{:href => "#", :onclick => "previewHtmlEmailTemplate(); return false;"} Preview HTML email
%p.btns
=f.submit w('save')
or
%a{:href => "#", :onclick => "new Ajax.Request('/admin/notifications/deliver_copy', { parameters: $H(Form.serialize('edit-form', true)).merge({_method: 'post'}) }); return false;"} Send test email to liwh87@gmail.com
=f.submit w('save'),class: 'btn'
=w('or')
%a{:href => "/admin/notifications"}=w('back')
-#
or
%a{:href => "#", :onclick => "new Ajax.Request('/admin/notifications/deliver_copy', { parameters: $H(Form.serialize('edit-form', true)).merge({_method: 'post'}) }); return false;"} Send test email to liwh87@gmail.com

:javascript
new App.Controllers.Emails()
1 change: 1 addition & 0 deletions config/locales/cn.yml
Expand Up @@ -295,6 +295,7 @@ cn:
web:
save: 保存
cancel: 取消
back: 返回
list: 列表
edit: 编辑
new: 新增
Expand Down
26 changes: 26 additions & 0 deletions spec/controllers/emails_controller_spec.rb
@@ -1,5 +1,31 @@
#encoding: utf-8
require 'spec_helper'

describe EmailsController do
include Devise::TestHelpers

let(:user){ Factory(:user)}
let(:shop){ user.shop}
let(:subscribes){ shop.subscribes}

before :each do
sign_in(user)
end

context '#follow' do
it "should create subscribe success" do
expect do
xhr :post, :follow,subscribe: "email", address: "ee@gmail.com"
end.should change(Subscribe, :count).by(1)
end
end

context '#unfollow' do
it "should remove a subscribe " do
expect do
xhr :delete, :unfollow, id: subscribes.first.id
end.should change(Subscribe,:count).by(-1)
end
end

end
26 changes: 26 additions & 0 deletions spec/models/subscribe_spec.rb
@@ -1,4 +1,30 @@
#encoding: utf-8
require 'spec_helper'

describe Subscribe do

let(:user){ Factory(:user) }
let(:shop) { user.shop}

context 'when subsribe associate with user ' do
it "should save success" do
subscribe = shop.subscribes.create user: user
subscribe.user.id.should eql user.id
end
end

context 'when subsribe type with email ' do

it "should save success" do
subscribe = shop.subscribes.create address: 'liwh87@gmail.com'
subscribe.errors.should be_empty
subscribe.address.should eql 'liwh87@gmail.com'
end

it "should save failure" do
subscribe = shop.subscribes.create address: 'liwh87@'
subscribe.errors.should_not be_empty
end
end

end

0 comments on commit e214b58

Please sign in to comment.