Commit 74e9cd6c authored by danielgrippi's avatar danielgrippi Committed by Dennis Collinson

DG MS; added checkboxes for services in the new publisher (currently not...

DG MS; added checkboxes for services in the new publisher (currently not working) / user presenter contains services	
parent 680e7f66
class ServicePresenter < BasePresenter
def initialize(service)
@service = service
end
def as_json
{
:provider => @service.provider
}
end
def to_json(options = {})
as_json.to_json(options)
end
end
\ No newline at end of file
class UserPresenter
attr_accessor :user
def initialize(user)
self.user = user
end
......@@ -10,17 +10,22 @@ class UserPresenter
{ :notifications_count => notifications_count,
:unread_messages_count => unread_messages_count,
:admin => admin,
:aspects => aspects
:aspects => aspects,
:services => services
}
).to_json(options)
end
def services
ServicePresenter.as_collection(user.services)
end
def aspects
AspectPresenter.as_collection(user.aspects)
end
def notifications_count
@notification_count ||= user.unread_notifications.count
@notification_count ||= user.unread_notifications.count
end
def unread_messages_count
......@@ -30,4 +35,4 @@ class UserPresenter
def admin
user.admin?
end
end
\ No newline at end of file
end
......@@ -2,7 +2,8 @@ app.forms.Post = app.forms.Base.extend({
templateName : "post-form",
subviews : {
".aspect_selector" : "aspectsDropdown"
".aspect_selector" : "aspectsDropdown",
".service_selector" : "servicesSelector"
},
formAttrs : {
......@@ -11,6 +12,7 @@ app.forms.Post = app.forms.Base.extend({
},
initialize : function(){
this.aspectsDropdown = new app.views.AspectsDropdown()
this.aspectsDropdown = new app.views.AspectsDropdown();
this.servicesSelector = new app.views.ServicesSelector();
}
});
\ No newline at end of file
......@@ -2,6 +2,7 @@
<div class='span12'>
<form class="new-post well">
<label>text<textarea class="text"/></label>
<div class="service_selector"/>
<div class="aspect_selector"/>
<br/>
......
{{#each current_user.services}}
<input type="checkbox" name="services" class="service" value="{{provider}}" />
{{provider}}
<br />
{{/each}}
<br />
......@@ -16,7 +16,7 @@ app.views.AspectsDropdown = app.views.Base.extend({
'custom' : setCustom
}
visibilityCallbacks[link.data("visibility") || "all-aspects"].call(this)
visibilityCallbacks[link.data("visibility")].call(this)
function setPublic (){
this.setAspectIds("public")
......@@ -41,4 +41,4 @@ app.views.AspectsDropdown = app.views.Base.extend({
setAspectIds : function(val){
this.$("input.aspect_ids").val(val)
}
})
\ No newline at end of file
})
app.views.ServicesSelector = app.views.Base.extend({
templateName : "services-selector"
});
\ No newline at end of file
describe("app.views.ServicesSelector", function(){
beforeEach(function(){
loginAs(factory.user({
services : [
{ provider : "fakeBook" }
]
}));
this.view = new app.views.ServicesSelector();
});
describe("rendering", function(){
beforeEach(function(){
this.view.render();
});
it("displays all services", function(){
var checkboxes = $(this.view.el).find('input[type="checkbox"]');
expect(checkboxes.val()).toBe("fakeBook");
});
});
});
\ No newline at end of file
require 'spec_helper'
describe ServicePresenter do
describe '#as_json' do
it 'includes the provider name of the json' do
presenter = ServicePresenter.new(stub(:provider => "fakebook"))
presenter.as_json[:provider].should == 'fakebook'
end
end
end
\ No newline at end of file
......@@ -18,4 +18,12 @@ describe UserPresenter do
@presenter.aspects.first[:name].should == aspect.name
end
end
describe '#services' do
it 'provides an array of jsonifed services' do
fakebook = stub(:provider => 'fakebook')
bob.stub(:services).and_return([fakebook])
@presenter.services.should include(:provider => 'fakebook')
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment