fixed user model and map models up

This commit is contained in:
Connor Turland 2014-08-12 11:09:53 -04:00
parent 9d6cf2c3c8
commit e1fb72c2df
12 changed files with 54 additions and 37 deletions

View file

@ -1,7 +1,7 @@
Metamaps.Backbone = {};
Metamaps.Backbone.Map = Backbone.Model.extend({
urlRoot: '/maps',
blacklist: ['created_at', 'updated_at', 'topics', 'synapses', 'mappings', 'mappers'],
blacklist: ['created_at', 'updated_at', 'user_name', 'topic_count', 'synapse_count', 'topics', 'synapses', 'mappings', 'mappers'],
toJSON: function (options) {
return _.omit(this.attributes, this.blacklist);
},
@ -57,11 +57,11 @@ Metamaps.Backbone.Map = Backbone.Model.extend({
id: this.id,
name: this.get('name'),
desc: this.get('desc'),
username: this.getUser().get('name'),
mkPermission: this.get("permission") ? this.get("permission").substring(0, 2) : "commons",
username: this.get('user_name'),
mkPermission: this.get("permission") ? this.get("permission").substring(0, 2) : "co",
editPermission: this.authorizeToEdit(Metamaps.Active.Mapper) ? 'canEdit' : 'cannotEdit',
topicCount: this.getTopics().length,
synapseCount: this.getSynapses().length,
topicCount: this.get('topic_count'),
synapseCount: this.get('synapse_count'),
createdAt: this.get('created_at')
};
return obj;

View file

@ -75,10 +75,6 @@ Metamaps.GlobalUI = {
});
$('#lightbox_screen, #lightbox_close').click(self.closeLightbox);
// hide notices after 10 seconds
$('.notice.metamaps').delay(10000).fadeOut('fast');
$('.alert.metamaps').delay(10000).fadeOut('fast');
// initialize global backbone models and collections
if (Metamaps.Active.Mapper) Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper);

View file

@ -201,15 +201,10 @@ input[type="submit"]:hover {
.forgotPassword {
display: block;
width: 250px;
position: absolute;
left: 50%;
top: 0;
margin: 100px 0 0 -145px;
background: url(bg.png);
background-color: #E0E0E0;
padding: 20px;
border-radius: 5px;
color: black;
border: 1px solid #000;
box-shadow: 6px 6px 8px rgba(0, 0, 0, 0.4);
}
.centerGreyForm input[type="text"],

View file

@ -32,6 +32,22 @@ end
return contributors
end
def topic_count
self.topics.length
end
def synapse_count
self.synapses.length
end
def user_name
self.user.name
end
def as_json(options={})
super(:methods =>[:user_name, :topic_count, :synapse_count])
end
##### PERMISSIONS ######

View file

@ -38,6 +38,13 @@ has_many :mappings
trans << '( +clone -flop ) -compose multiply -composite '
trans << ') -alpha off -compose copy_opacity -composite '
end
def as_json(options={})
{ :name =>self.name,
:email => self.email,
:image => self.image.url
}
end
if ActiveRecord::Base.connection.table_exists? 'users'
codes = ActiveRecord::Base.connection.execute("SELECT code FROM users").map {|user| user["code"] }

View file

@ -5,7 +5,7 @@
<% if authenticated? %>
<% account = current_user %>
<h3 class="accountHeader">Hello <%= account.name.split[0...1][0] %>!</h3>
<h3 class="accountHeader"><%= account.name.split[0...1][0] %></h3>
<ul>
<li class="accountIcon accountSettings"><%= link_to "Account", edit_user_url(account),
:data => { :bypass => 'true'} %></li>
@ -38,8 +38,9 @@
<% end %>
<div class="links">
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %>
<%= link_to "Forgot your password?", new_password_path(resource_name),
:data => { :bypass => 'true'} %>
<% end -%>
<a href="/request">Request Invite</a>
<a href="/request" data-bypass="true">Request Invite</a>
</div>
<% end %>

View file

@ -4,7 +4,8 @@
# User edit form
#%>
<% content_for :title, @user.name + "'s Settings | Metamaps" %>
<% content_for :title, @user.name + "'s Settings | Metamaps" %>
<div id="yield">
<%= formula_form_for @user, url: user_url do |form| %>
<h3>Edit Account</h3>
<label for="user_image">Profile Picture</label>
@ -15,4 +16,5 @@
<%= form.input :password, label: "Password", class: "password", :autocomplete => :off %>
<%= form.submit "Update", class: "update" %>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Change Password | Metamaps" %>
<h1 class="index">Change Password</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put, :class => "forgotPassword centerGreyForm" }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
@ -17,5 +16,5 @@
<div><%= f.submit "Change my password" %></div>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Password Reset | Metamaps" %>
<h1 class="index">Password Reset</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post, :class => "forgotPassword centerGreyForm" }) do |f| %>
<%= devise_error_messages! %>
@ -13,5 +12,6 @@
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Sign Up | Metamaps" %>
<h1 class="index">Sign Up</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :post, :class => "new_user centerGreyForm" }) do |f| %>
<%= devise_error_messages! %>
@ -24,7 +23,7 @@
<div><%= f.submit "Sign up" %></div>
<div><br />Don't have an access code?<br /><a href="/request">Request an Invite</a></div>
<div><br />Don't have an access code?<br /><a href="/request" data-bypass="true">Request an Invite</a></div>
<% end %>
</div>

View file

@ -1,7 +1,6 @@
<% content_for :title, "Sign In | Metamaps" %>
<h1 class="index">Sign In</h1>
<div id="yield">
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :method => :post, :class => "new_user centerGreyForm" }) do |f| %>
<h3>Sign in</h3>
@ -19,10 +18,11 @@
<br />
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<%= link_to "Forgot your password?", new_password_path(resource_name),
:data => { :bypass => 'true'} %><br />
<% end -%>
<br />
<div>Don't have an account?<br /><a href="/request">Request an Invite</a></div>
<div>Don't have an account?<br /><a href="/request" data-bypass="true">Request an Invite</a></div>
<% end %>
</div>

View file

@ -100,10 +100,12 @@ define(function(require, exports, module) {
f.loadYield = function () {
Metamaps.Loading.loader.hide();
var yield = document.getElementById('yield').innerHTML;
f.yield.surf.setContent(yield);
f.yield.surf.deploy(f.yield.surf._currTarget);
f.yield.show();
var yield = document.getElementById('yield') ? document.getElementById('yield').innerHTML : false;
if (yield) {
f.yield.surf.setContent(yield);
f.yield.surf.deploy(f.yield.surf._currTarget);
f.yield.show();
}
};