links added and other stuff
This commit is contained in:
parent
eb455e704a
commit
f0dcdc3985
133
app/controllers/links_controller.rb
Executable file
133
app/controllers/links_controller.rb
Executable file
|
@ -0,0 +1,133 @@
|
|||
require 'tempfile'
|
||||
|
||||
class LinksController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :get_links, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :only => [:index]
|
||||
|
||||
#, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def ops
|
||||
if params["create_new"]
|
||||
redirect_to(new_link_path)
|
||||
return
|
||||
end
|
||||
if !params["ids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:link)
|
||||
else
|
||||
if params["delete_selected"]
|
||||
params["ids"].each do |id|
|
||||
@current_user.links.find_by_id(id).destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to(links_path)
|
||||
end
|
||||
|
||||
#problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html
|
||||
#def destroy
|
||||
# @current_user.contacts.find(params[:id]).destroy
|
||||
# redirect_to(contacts_path)
|
||||
#end
|
||||
|
||||
def new
|
||||
@link = Link.new
|
||||
end
|
||||
|
||||
def edit
|
||||
@link = @current_user.links.find(params[:id])
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def create
|
||||
@link = @current_user.links.build(params[:link])
|
||||
if @link.valid?
|
||||
@link.save
|
||||
flash[:notice] = t(:was_created,:scope=>:link)
|
||||
redirect_to(links_path)
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@link = @current_user.links.find(params[:id])
|
||||
if @link.update_attributes(params[:link])
|
||||
redirect_to(links_path)
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def external
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
raise t(:no_tmp_dir,:scope=>:common) if not File.exists?($defaults["msg_upload_dir"])
|
||||
tmp_file = Tempfile.new($defaults["contact_tmp_filename"],$defaults["msg_upload_dir"])
|
||||
tmp_file.write(params[:upload][:datafile].read)
|
||||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,line)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:error] = {:title => e.to_s,:info => e.record.inspect + e.record.errors.inspect}
|
||||
rescue Exception => e
|
||||
flash[:error] = e.to_s
|
||||
else
|
||||
flash[:notice] = t(:were_imported,:scope=>:contact)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def export
|
||||
contacts = @current_user.contacts
|
||||
s = ""
|
||||
contacts.each do |c|
|
||||
s += c.export + "\r\n"
|
||||
end
|
||||
headers['Content-type'] = "text/csv"
|
||||
headers['Content-Disposition'] = %(attachment; filename="contacts.csv")
|
||||
render :text => s
|
||||
end
|
||||
|
||||
####################################### protected section ################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_ops_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'create_new',:scope=> 'link', :image => 'plus.png'}
|
||||
@buttons << {:text => 'delete_selected',:scope=>'link',:image => 'minus.png'}
|
||||
end
|
||||
|
||||
def prepare_export_import_buttons
|
||||
@ei_buttons = []
|
||||
@ei_buttons << {:text => 'import',:scope=>'link',:image => 'right.png'}
|
||||
@ei_buttons << {:text => 'export',:scope=>'link',:image => 'left.png'}
|
||||
end
|
||||
|
||||
####################################### private section ##################################
|
||||
|
||||
private
|
||||
|
||||
def get_links
|
||||
@links = Link.getPageForUser(@current_user,params[:page],params[:sort_field],params[:sort_dir])
|
||||
end
|
||||
|
||||
end
|
|
@ -115,14 +115,23 @@ class MessagesOpsController < ApplicationController
|
|||
flash[:warning] = t(:no_selected,:scope=>:folder)
|
||||
else
|
||||
dest_folder = @current_user.folders.find(params[:folder][:target])
|
||||
logger.info "DEST: "+dest_folder.inspect
|
||||
params["uids"].each do |uid|
|
||||
logger.info "UID: "+uid
|
||||
logger.info "DEST_FULL: "+dest_folder.full_name
|
||||
@mailbox.move_message(uid,dest_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
logger.info "M: "+message.inspect
|
||||
logger.info "UPDATE_DEST_BEFORE1: "+dest_folder.inspect
|
||||
message.change_folder(dest_folder)
|
||||
logger.info "UPDATE_DEST_BEFORE2: "+dest_folder.inspect
|
||||
end
|
||||
logger.info "UPDATE_DEST_BEFORE: "+dest_folder.inspect
|
||||
@mailbox.expunge
|
||||
dest_folder.update_stats
|
||||
logger.info "UPDATE_DEST: "+dest_folder.inspect
|
||||
@current_folder.update_stats
|
||||
logger.info "UPDATE_CUT: "+@current_folder.inspect
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -269,7 +269,8 @@ def main_navigation(active)
|
|||
s += "<li class=\"#{@compose_tab}\">#{link_to( t(:compose,:scope=>:compose), compose_path )}</li>"
|
||||
s += "<li class=\"#{@folders_tab}\">#{link_to( t(:folders,:scope=>:folder), folders_path )}</li>"
|
||||
s += "<li class=\"#{@contacts_tab}\">#{link_to( t(:contacts,:scope=>:contact), contacts_path )}</li>"
|
||||
s += "<li class=\"last #{@prefs_tab}\">#{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}</li>"
|
||||
s += "<li class=\"#{@prefs_tab}\">#{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}</li>"
|
||||
s += "<li class=\"last #{@links_tab}\">#{link_to( t(:links,:scope=>:link), links_path )}</li>"
|
||||
s += "</ul>"
|
||||
end
|
||||
|
||||
|
|
17
app/helpers/links_helper.rb
Executable file
17
app/helpers/links_helper.rb
Executable file
|
@ -0,0 +1,17 @@
|
|||
module LinksHelper
|
||||
|
||||
def links_table_header
|
||||
html = ""
|
||||
$defaults["links_table_fields"].each do |f|
|
||||
html << "<th>"
|
||||
if params[:sort_field] == f
|
||||
params[:sort_dir].nil? ? dir = 'desc' : dir = nil
|
||||
end
|
||||
|
||||
html << link_to(Link.human_attribute_name(f), {:controller => 'links',:action => 'index',:sort_field => f,:sort_dir => dir}, {:class=>"header"})
|
||||
html << "</th>"
|
||||
end
|
||||
html
|
||||
end
|
||||
|
||||
end
|
|
@ -38,8 +38,11 @@ class Folder < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def update_stats
|
||||
logger.info "MESS_BEFORE: "+messages.inspect
|
||||
unseen = messages.where(:unseen => true).count
|
||||
total = messages.count
|
||||
logger.info "MESS: "+messages.inspect
|
||||
logger.info "MESS: #{unseen} #{total}"
|
||||
update_attributes(:unseen => unseen, :total => total)
|
||||
end
|
||||
|
||||
|
|
19
app/models/link.rb
Normal file
19
app/models/link.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
class Link < ActiveRecord::Base
|
||||
validates_length_of :name, :within => 5..30
|
||||
validates_length_of :url, :within => 5..150
|
||||
validates_length_of :info, :maximum => 50
|
||||
belongs_to :user
|
||||
default_scope :order => 'name asc'
|
||||
|
||||
def self.getPageForUser(user,page,sort_field,sort_dir)
|
||||
|
||||
if sort_field
|
||||
if Link.attribute_method?(sort_field) == true
|
||||
order = sort_field
|
||||
sort_dir == 'desc' ? order += ' desc' : sort_dir
|
||||
end
|
||||
end
|
||||
|
||||
Link.paginate :page => page , :per_page => $defaults["links_per_page"], :conditions=> ['user_id = ?', user.id],:order => order
|
||||
end
|
||||
end
|
|
@ -11,6 +11,7 @@ class User < ActiveRecord::Base
|
|||
has_many :folders, :dependent => :destroy
|
||||
has_many :messages, :dependent => :destroy
|
||||
has_many :contacts, :dependent => :destroy
|
||||
has_many :links, :dependent => :destroy
|
||||
|
||||
def set_cached_password(session,password)
|
||||
if $defaults['session_encryption']
|
||||
|
|
|
@ -13,6 +13,9 @@ msg_image_thumbnail_size: [128x128, 128x96, 192x192, 192x144, 256x256, 256x192]
|
|||
contacts_table_fields: [nick, first_name, last_name, email, info]
|
||||
contacts_per_page: 25
|
||||
|
||||
links_table_fields: [name, url, info]
|
||||
links_per_page: 30
|
||||
|
||||
servers_table_fields: [name, port, use_ssl, use_tls, for_imap, for_smtp, auth]
|
||||
|
||||
msgs_per_page: 20
|
||||
|
|
|
@ -18,7 +18,12 @@ pl:
|
|||
models:
|
||||
contact: Kontakt
|
||||
server: Serwer
|
||||
link: Sznurek
|
||||
attributes:
|
||||
link:
|
||||
name: Nazwa
|
||||
url: Adres
|
||||
info: Informacje
|
||||
contact:
|
||||
nick: Pseudonim
|
||||
first_name: Imię
|
||||
|
@ -74,6 +79,14 @@ pl:
|
|||
were_imported: Kontakty zostały zaimportowane
|
||||
format_error: Nieprawidłowy format kontaktu
|
||||
|
||||
link:
|
||||
link: Sznurek
|
||||
links: Sznurki
|
||||
create_new: Utwórz nowy sznurek
|
||||
no_entries: Brak sznurków
|
||||
total_entries: Liczba sznurków
|
||||
delete_selected: Usuń wybrane
|
||||
|
||||
prefs:
|
||||
prefs: Ustawienia
|
||||
look: Wygląd
|
||||
|
|
|
@ -17,6 +17,15 @@ Mailr::Application.routes.draw do
|
|||
|
||||
resources :contacts
|
||||
|
||||
namespace :links do
|
||||
post "ops"
|
||||
get "export"
|
||||
end
|
||||
#match "/external" => "contacts#external", :as => :contacts_external
|
||||
|
||||
|
||||
resources :links
|
||||
|
||||
namespace :folders do
|
||||
post "create"
|
||||
post "delete"
|
||||
|
|
17
db/migrate/20120109191128_create_links.rb
Normal file
17
db/migrate/20120109191128_create_links.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class CreateLinks < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :links do |t|
|
||||
t.integer :user_id
|
||||
t.integer :lgroup_id
|
||||
t.string :name
|
||||
t.string :url
|
||||
t.string :info
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :links
|
||||
end
|
||||
end
|
|
@ -17,7 +17,7 @@ class IMAPMailbox
|
|||
@folders = {}
|
||||
@connected = false
|
||||
@logger = logger
|
||||
Net::IMAP.debug = debug
|
||||
Net::IMAP.debug = true
|
||||
end
|
||||
|
||||
def connect(server,username,password)
|
||||
|
|
15
test/fixtures/links.yml
vendored
Normal file
15
test/fixtures/links.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
lgroup_id: 1
|
||||
name: MyString
|
||||
url: MyString
|
||||
info: MyString
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
lgroup_id: 1
|
||||
name: MyString
|
||||
url: MyString
|
||||
info: MyString
|
8
test/unit/link_test.rb
Normal file
8
test/unit/link_test.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class LinkTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -406,6 +406,10 @@ th a.header {
|
|||
background: none repeat scroll 0 0 #EFF3E4;
|
||||
}
|
||||
|
||||
.table tr.unseen {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.table td {
|
||||
border-bottom: 1px solid #F0F0EE;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
<% end %>
|
||||
|
||||
<div id="box">
|
||||
<div id="box2">
|
||||
<div class="block block-login">
|
||||
<div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a>
|
||||
</div>
|
||||
<div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a></div>
|
||||
<h2><%= @title %></h2>
|
||||
<div class="content">
|
||||
<div class="flash"><div class="message error"><p><%= @error %></p></div></div>
|
||||
|
|
|
@ -28,6 +28,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|||
</div>
|
||||
<div id="main">
|
||||
<%= render :partial=>'layouts/flash', :object => flash %>
|
||||
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
|
||||
<%= yield %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
7
themes/olive/views/links/_left.html.erb
Executable file
7
themes/olive/views/links/_left.html.erb
Executable file
|
@ -0,0 +1,7 @@
|
|||
|
||||
<div class="params">
|
||||
<%= raw form_field(@link,"name",nil,"Fajny sznurek",@link.name) %>
|
||||
<%= raw form_field(@link,"url",nil,"http://aaa.com",@link.url) %>
|
||||
<%= raw form_field(@link,"info",nil,t(:some_add_info,:scope=>:link),@link.info) %>
|
||||
</div>
|
||||
<%= raw single_action('save','common','save.png') %>
|
5
themes/olive/views/links/_link.html.erb
Executable file
5
themes/olive/views/links/_link.html.erb
Executable file
|
@ -0,0 +1,5 @@
|
|||
<td><%= check_box_tag "ids[]", link.id %></td>
|
||||
<td nowrap="nowrap"><%= link_to link.name,edit_link_path(link) %></td>
|
||||
<td nowrap="nowrap"><%= link_to link.url,"http://"+link.url %></td>
|
||||
<td colspan="2" nowrap="nowrap"><%= link.info %></td>
|
||||
|
25
themes/olive/views/links/_list.html.erb
Executable file
25
themes/olive/views/links/_list.html.erb
Executable file
|
@ -0,0 +1,25 @@
|
|||
<div class="inner">
|
||||
<div class="actions-bar">
|
||||
<span class="other_info"> <%= t(:total_entries,:scope=>:link) %>: <%= @links.total_entries %></span>
|
||||
<%= will_paginate @links %>
|
||||
</div>
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th class="first"><input id="toggleall" class="checkbox toggle" type="checkbox" name="allbox"/></th>
|
||||
<%= raw links_table_header %>
|
||||
<th class="last"></th>
|
||||
</tr>
|
||||
<% trclass = :even %>
|
||||
<% @links.each do |c| %>
|
||||
<tr class="<%= trclass.to_s %>">
|
||||
<%= render :partial => 'link', :object => c %>
|
||||
</tr>
|
||||
<% trclass == :even ? trclass = :odd : trclass = :even %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="actions-bar">
|
||||
<%= will_paginate @links %>
|
||||
</div>
|
||||
</div>
|
3
themes/olive/views/links/_ops.html.erb
Executable file
3
themes/olive/views/links/_ops.html.erb
Executable file
|
@ -0,0 +1,3 @@
|
|||
<div id="ops" class="ops">
|
||||
<%= raw group_action(@buttons) %>
|
||||
</div>
|
1
themes/olive/views/links/_right.html.erb
Executable file
1
themes/olive/views/links/_right.html.erb
Executable file
|
@ -0,0 +1 @@
|
|||
|
30
themes/olive/views/links/edit.html.erb
Executable file
30
themes/olive/views/links/edit.html.erb
Executable file
|
@ -0,0 +1,30 @@
|
|||
<% content_for :sidebar do %>
|
||||
<%= content_for_sidebar %>
|
||||
<% end %>
|
||||
|
||||
<% content_for :title do %>
|
||||
- <%= t(:links,:scope=>:link) %>
|
||||
<% end %>
|
||||
|
||||
<div class="block" id="block-tables">
|
||||
<div class="secondary-navigation">
|
||||
<%= raw main_navigation(:links) %>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="inner">
|
||||
<div class="actions-bar wat-cf">
|
||||
<div class="header_info"><%= t(:modifying,:scope=>:link) %></div>
|
||||
</div>
|
||||
<%= form_for(@link) do |f| %>
|
||||
<div class="columns wat-cf">
|
||||
<div class="column left">
|
||||
<%= render :partial => 'left' %>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<%= render :partial => 'right' %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
26
themes/olive/views/links/index.html.erb
Executable file
26
themes/olive/views/links/index.html.erb
Executable file
|
@ -0,0 +1,26 @@
|
|||
<% content_for :sidebar do %>
|
||||
<%= content_for_sidebar %>
|
||||
<% end %>
|
||||
|
||||
<% content_for :title do %>
|
||||
- <%= t(:links,:scope=>:link) %>
|
||||
<% end %>
|
||||
|
||||
<div class="block">
|
||||
<div class="navigation-tabs clearfix">
|
||||
<%= raw main_navigation(:links_tab) %>
|
||||
</div>
|
||||
<div class="content">
|
||||
<%= form_tag(links_ops_path,{:name=>'links'})%>
|
||||
<% if @links.size.zero? %>
|
||||
<h3><%= t(:no_entries,:scope=>:link) %></h3>
|
||||
<%= raw single_action('create_new','link','plus.png') %>
|
||||
</form>
|
||||
<% else %>
|
||||
<%= render :partial => 'ops' %>
|
||||
<%= render :partial => 'list' %>
|
||||
</form>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
30
themes/olive/views/links/new.html.erb
Executable file
30
themes/olive/views/links/new.html.erb
Executable file
|
@ -0,0 +1,30 @@
|
|||
<% content_for :sidebar do %>
|
||||
<%= content_for_sidebar %>
|
||||
<% end %>
|
||||
|
||||
<% content_for :title do %>
|
||||
- <%= t(:links,:scope=>:link) %>
|
||||
<% end %>
|
||||
|
||||
<div class="block" id="block-tables">
|
||||
<div class="secondary-navigation">
|
||||
<%= raw main_navigation(:links) %>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="inner">
|
||||
<div class="actions-bar wat-cf">
|
||||
<div class="header_info"><%= t(:creating_new,:scope=>:link) %> </div>
|
||||
</div>
|
||||
<%= form_for(@link) do |f| %>
|
||||
<div class="columns wat-cf">
|
||||
<div class="column left">
|
||||
<%= render :partial => 'links/left' %>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<%= render :partial => 'links/right' %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -6,8 +6,6 @@
|
|||
- <%= t(:compose,:scope=>:compose) %>
|
||||
<% end %>
|
||||
|
||||
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
|
||||
|
||||
<div class="block">
|
||||
<div class="navigation-tabs clearfix">
|
||||
<%= raw main_navigation(:compose_tab) %>
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
- <%= t(:messages,:scope=>:message) %>
|
||||
<% end %>
|
||||
|
||||
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
|
||||
|
||||
<div class="block">
|
||||
<div class="navigation-tabs clearfix">
|
||||
<%= raw main_navigation(:messages_tab) %>
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
- <%= subject_formatter(@message,:show) %>
|
||||
<% end %>
|
||||
|
||||
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
|
||||
|
||||
<div class="block">
|
||||
<div class="navigation-tabs clearfix">
|
||||
<%= raw main_navigation(:show) %>
|
||||
|
|
Loading…
Reference in a new issue