Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 40.73 KB | None | 0 0
  1. From 0523a3a6f2c30a305de8f4746b34edc9caf0d6ba Mon Sep 17 00:00:00 2001
  2. From: svmk <svmk-tmsk@yandex.ru>
  3. Date: Sat, 16 Apr 2011 19:48:02 +0700
  4. Subject: [PATCH] Added DAC of conversation.
  5.  In database ConversationVisibility added three variables: owner, editor, deleted.
  6.  
  7. The owner can manage the members of the conversations.
  8. The editor can send messages.
  9. If the deleted flag is set, the user does not have a conversation.
  10. This code has been tested on a Opera Browser. Html code uses css3.
  11. ---
  12.  app/controllers/conversations_controller.rb        |  172 ++++++++++++++++++-
  13.  app/controllers/messages_controller.rb             |    6 +
  14.  app/helpers/application_helper.rb                  |   11 ++
  15.  app/views/conversations/_access_denied.haml        |   15 ++
  16.  app/views/conversations/_show.haml                 |   60 ++++++-
  17.  app/views/conversations/access_denied.haml         |    5 +
  18.  app/views/conversations/create_contact.haml        |    1 +
  19.  app/views/conversations/delete_contact.haml        |    1 +
  20.  app/views/conversations/index.haml                 |   16 +-
  21.  app/views/conversations/new_contact.haml           |  177 ++++++++++++++++++++
  22.  app/views/conversations/show.haml                  |    2 +-
  23.  config/locales/diaspora/en.yml                     |    1 +
  24.  config/locales/diaspora/ru.yml                     |    1 +
  25.  config/routes.rb                                   |    8 +-
  26.  ...6095653_add_owner_to_conversation_visibility.rb |   19 ++
  27.  db/schema.rb                                       |    5 +-
  28.  public/images/user/add_button.png                  |  Bin 0 -> 242 bytes
  29.  public/images/user/add_contact.png                 |  Bin 0 -> 234 bytes
  30.  public/stylesheets/sass/application.sass           |  145 ++++++++++++++++-
  31.  19 files changed, 621 insertions(+), 24 deletions(-)
  32.  create mode 100644 app/views/conversations/_access_denied.haml
  33.  create mode 100644 app/views/conversations/access_denied.haml
  34.  create mode 100644 app/views/conversations/create_contact.haml
  35.  create mode 100644 app/views/conversations/delete_contact.haml
  36.  create mode 100644 app/views/conversations/new_contact.haml
  37.  create mode 100644 db/migrate/20110326095653_add_owner_to_conversation_visibility.rb
  38.  create mode 100644 public/images/user/add_button.png
  39.  create mode 100644 public/images/user/add_contact.png
  40.  
  41. diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb
  42. index 2a4008d..633dde1 100644
  43. --- a/app/controllers/conversations_controller.rb
  44. +++ b/app/controllers/conversations_controller.rb
  45. @@ -1,4 +1,4 @@
  46. -class ConversationsController < ApplicationController
  47. + class ConversationsController < ApplicationController
  48.    before_filter :authenticate_user!
  49.  
  50.    respond_to :html, :json
  51. @@ -19,20 +19,41 @@ class ConversationsController < ApplicationController
  52.  
  53.      @conversation = Conversation.joins(:conversation_visibilities).where(
  54.        :conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first
  55. +    @conversation_vis = ConversationVisibility.where(:conversation_id => params[:conversation_id]).order('owner DESC, editor DESC, deleted ASC')
  56. +    @allow_access = true
  57. +    if not @conversation_vis.any?{|i| i.person_id == current_user.person.id and not i.deleted} then
  58. +      # Access denied
  59. +      @allow_access = false
  60. +    end
  61. +    if params[:conversation_id] then
  62. +      @owner = @conversation_vis.any?{|i| i.person_id == current_user.person.id and i.owner and not i.deleted}
  63. +      @url_new_contact = url_for(:controller=>'conversations',:action=>'new_contact',:conversation_id=>params[:conversation_id])
  64. +    end
  65.    end
  66.  
  67.    def create
  68. -    person_ids = Contact.where(:id => params[:contact_ids].split(',')).map! do |contact|
  69. +    contact_ids = []
  70. +    if params[:contact_ids] then
  71. +      contact_ids = params[:contact_ids].split(',')
  72. +    end
  73. +    if contact_ids.length == 0 then
  74. +      flash[:notice] = t('.desteny_field_error')
  75. +      redirect_to conversations_path
  76. +      return
  77. +    end
  78. +    person_ids = Contact.where(:id => contact_ids).map! do |contact|
  79.        contact.person_id
  80.      end
  81.  
  82.      params[:conversation][:participant_ids] = person_ids | [current_user.person.id]
  83.      params[:conversation][:author] = current_user.person
  84.  
  85. -    if @conversation = Conversation.create(params[:conversation])
  86. +    @conversation = Conversation.create(params[:conversation])
  87. +    if @conversation  then
  88. +      @conversation.participants.update_all({:owner => false, :editor=> true, :deleted=> false})
  89. +      @conversation.participants.update_all({:owner => true, :editor=> true, :deleted=> false},{:id => current_user.person.id})
  90.        Postzord::Dispatch.new(current_user, @conversation).post
  91. -
  92. -      flash[:notice] = "Message sent"
  93. +      flash[:notice] = t('.message_sent')
  94.        if params[:profile]
  95.          redirect_to person_path(params[:profile])
  96.        else
  97. @@ -42,8 +63,16 @@ class ConversationsController < ApplicationController
  98.    end
  99.  
  100.    def show
  101. +    @conversation_vis = ConversationVisibility.where(:conversation_id => params[:id]).order('owner DESC, editor DESC, deleted ASC')
  102. +    if not @conversation_vis.any?{|i| i.person_id == current_user.person.id and not i.deleted} then
  103. +      # Access denied
  104. +      render :access_denied,:layout=>false
  105. +      return
  106. +    end
  107. +    @owner = @conversation_vis.any?{|i| i.person_id == current_user.person.id and i.owner and not i.deleted}
  108. +    @url_new_contact = url_for(:controller=>'conversations',:action=>'new_contact',:conversation_id=>params[:id])
  109.      @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
  110. -                                                                         :conversation_visibilities => {:person_id => current_user.person.id}).first
  111. +      :conversation_visibilities => {:person_id => current_user.person.id}).first
  112.  
  113.      if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
  114.        @visibility.unread = 0
  115. @@ -53,7 +82,7 @@ class ConversationsController < ApplicationController
  116.      if @conversation
  117.        render :layout => false
  118.      else
  119. -      redirect_to conversations_path
  120. +      # render error message! don't redirect!
  121.      end
  122.    end
  123.  
  124. @@ -63,4 +92,133 @@ class ConversationsController < ApplicationController
  125.      render :layout => false
  126.    end
  127.  
  128. +  def new_contact
  129. +    @aspect = :manage
  130. +    @contacts = current_user.contacts.includes(:person => :profile)
  131. +    @conversation_id = params[:conversation_id]    
  132. +    @active_contacts = ConversationVisibility.where(:conversation_id => @conversation_id).order('owner DESC, editor DESC, deleted ASC')
  133. +    #@active_contacts = ConversationVisibility.order('owner DESC, editor DESC, deleted ASC') + ConversationVisibility.order('owner DESC, editor DESC, deleted ASC')  # TODO!
  134. +    render :layout => false
  135. +  end
  136. +  
  137. +  def prepare_info(item)
  138. +    str = ''
  139. +    if item then
  140. +      if (item.owner) then
  141. +        str = str + 'O';
  142. +      end
  143. +      if (item.editor) then
  144. +        str = str + 'E';
  145. +      end
  146. +      if (not item.deleted) then
  147. +        str = str + 'R';
  148. +      end
  149. +    end
  150. +    return str
  151. +  end
  152. +  
  153. +  def is_owner
  154. +    item = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => current_user.person.id).first
  155. +    return (item.owner and not item.deleted)
  156. +  end
  157. +
  158. +  def create_contact
  159. +    if is_owner then
  160. +      @conversation = Conversation.find(params[:conversation_id])
  161. +      if @conversation then
  162. +        if not @conversation.participant_ids.any?{|rec| rec == params[:person_id].to_i} then
  163. +          @conversation.participant_ids = @conversation.participant_ids + [params[:person_id]]
  164. +        else
  165. +          item = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => params[:person_id]).first
  166. +          if item then
  167. +            item.deleted = false
  168. +            item.save
  169. +          end
  170. +        end
  171. +        @participant = Person.find(params[:person_id])
  172. +      end
  173. +    end
  174. +    render :text => prepare_info(item),:layout => false
  175. +  end
  176. +
  177. +  def delete_contact
  178. +    if is_owner then
  179. +      @conversation = Conversation.find(params[:conversation_id])
  180. +      if @conversation then
  181. +        count = ConversationVisibility.where(:conversation_id => params[:conversation_id],:deleted=>false).count(:all)
  182. +        item = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => params[:person_id]).first
  183. +        if item and count > 1 then
  184. +          item.deleted = true
  185. +          item.owner = false
  186. +          item.editor = false
  187. +          item.save
  188. +        end
  189. +      end
  190. +    end
  191. +    render :text => prepare_info(item),:layout => false
  192. +  end
  193. +  
  194. +  def afford_to_own
  195. +    if is_owner then
  196. +      conversation = Conversation.find(params[:conversation_id])
  197. +      if conversation then
  198. +        item = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => params[:person_id]).first
  199. +        if item then
  200. +          item.owner = true
  201. +          item.editor = true
  202. +          item.deleted = false
  203. +          item.save
  204. +        else
  205. +          ConversationVisibility.create(:conversation_id => params[:conversation_id],:person_id => params[:person_id],:owner => true, :editor=>true, :deleted => false, :unread=>true)
  206. +        end
  207. +      end
  208. +    end
  209. +    render :text=>prepare_info(item),:layout=>false
  210. +  end
  211. +
  212. +  def prohibit_owning
  213. +    if is_owner then
  214. +      conversation = Conversation.find(params[:conversation_id])
  215. +      if conversation then
  216. +        count_owner = ConversationVisibility.where(:conversation_id => params[:conversation_id],:owner=>true).count(:all)
  217. +        item = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => params[:person_id]).first
  218. +        if item and count_owner > 1 then
  219. +          item.owner = false
  220. +          item.save
  221. +        end
  222. +      end
  223. +    end
  224. +    render :text=>prepare_info(item),:layout=>false
  225. +  end
  226. +
  227. +  def allow_edit
  228. +    if is_owner then
  229. +      conversation = Conversation.find(params[:conversation_id])
  230. +      if conversation then
  231. +        item = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => params[:person_id]).first
  232. +        if item then
  233. +          item.editor = true
  234. +          item.deleted = false
  235. +          item.save
  236. +        else
  237. +          ConversationVisibility.create(:conversation_id => params[:conversation_id],:person_id => params[:person_id],:owner => false, :editor=>true, :deleted => false, :unread=>true)
  238. +        end
  239. +      end
  240. +    end
  241. +    render :text=>prepare_info(item),:layout=>false
  242. +  end
  243. +
  244. +  def prohibit_edit
  245. +    if is_owner then
  246. +      conversation = Conversation.find(params[:conversation_id])
  247. +      if conversation then
  248. +        item = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => params[:person_id]).first
  249. +        if item then
  250. +          item.editor = false
  251. +          item.save
  252. +        end
  253. +      end
  254. +    end
  255. +    render :text=>prepare_info(item),:layout=>false
  256. +  end
  257.  end
  258. diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
  259. index 2dac50d..82f5a6e 100644
  260. --- a/app/controllers/messages_controller.rb
  261. +++ b/app/controllers/messages_controller.rb
  262. @@ -14,6 +14,8 @@ class MessagesController < ApplicationController
  263.                                :conversation_visibilities => {:person_id => current_user.person.id}).first
  264.  
  265.      if cnv
  266. +      cur_user = ConversationVisibility.where(:conversation_id => params[:conversation_id],:person_id => current_user.person.id).first
  267. +      if cur_user.editor and not cur_user.deleted then
  268.        message = Message.new(:conversation_id => cnv.id, :text => params[:message][:text], :author => current_user.person)
  269.        
  270.        if message.save
  271. @@ -25,6 +27,10 @@ class MessagesController < ApplicationController
  272.          render :nothing => true, :status => 406
  273.        end
  274.      else
  275. +      flash[:error] = t('.sending_prohibited')
  276. +      redirect_to conversations_path(:conversation_id => cnv.id)
  277. +    end
  278. +    else
  279.        render :nothing => true, :status => 406
  280.      end
  281.    end
  282. diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
  283. index 4c2a780..c7e5ffc 100644
  284. --- a/app/helpers/application_helper.rb
  285. +++ b/app/helpers/application_helper.rb
  286. @@ -158,6 +158,17 @@ module ApplicationHelper
  287.      end
  288.    end
  289.  
  290. +  def person_image_link_with_class(person, opts = {},class_name = '')
  291. +    return "" if person.nil? || person.profile.nil?
  292. +    if opts[:to] == :photos
  293. +      link_to person_image_tag(person, opts[:size]), person_photos_path(person)
  294. +    else
  295. +      "<a href='/people/#{person.id}' class='#{class_name}'>
  296. +  #{person_image_tag(person)}
  297. +</a>".html_safe
  298. +    end
  299. +  end
  300. +
  301.    def post_yield_tag(post)
  302.      (':' + post.id.to_s).to_sym
  303.    end
  304. diff --git a/app/views/conversations/_access_denied.haml b/app/views/conversations/_access_denied.haml
  305. new file mode 100644
  306. index 0000000..4856062
  307. --- /dev/null
  308. +++ b/app/views/conversations/_access_denied.haml
  309. @@ -0,0 +1,15 @@
  310. +.span-16.last
  311. +  .conversation_participants
  312. +    .span-9
  313. +      %h3
  314. +        = t('.no_conversation_selected')
  315. +      .conversation_controls
  316. +    .span-6.avatars.last
  317. +
  318. +%br
  319. +%br
  320. +%br
  321. +%br
  322. +%br
  323. +.span-16.last
  324. +  .stream
  325. \ No newline at end of file
  326. diff --git a/app/views/conversations/_show.haml b/app/views/conversations/_show.haml
  327. index 0d7e7c1..77f738b 100644
  328. --- a/app/views/conversations/_show.haml
  329. +++ b/app/views/conversations/_show.haml
  330. @@ -1,8 +1,52 @@
  331.  -#   Copyright (c) 2010, Diaspora Inc.  This file is
  332.  -#   licensed under the Affero General Public License version 3 or later.  See
  333.  -#   the COPYRIGHT file.
  334. -
  335. -
  336. +:javascript
  337. +  function add_contact_hide_keyup(ev)
  338. +  {
  339. +    if (ev.keyCode == 27){ // Escape key
  340. +        $('#add_avatar_container').animate({ opacity: "hide" },200);
  341. +        $(document).unbind('click');
  342. +        $(document).unbind('keyup');
  343. +    }
  344. +    if (ev.keyCode == 13){ // Enter key
  345. +        $('.contact_list_new ul li:not(.hiding):first .right.add_delete_button span a:not(.hiding)').click()
  346. +    }
  347. +  }
  348. +  function add_contact_hide(ev)
  349. +    {
  350. +      el = $('#add_avatar_container');
  351. +      pos = $('#add_avatar_container').offset();
  352. +      shadow_size = 12;
  353. +      if (!(ev.pageX >= pos.left &&
  354. +        ev.pageX <= (pos.left + el[0].clientWidth) &&
  355. +        ev.pageY >= (pos.top - shadow_size) &&
  356. +        ev.pageY <= (pos.top + el[0].clientHeight + shadow_size)))
  357. +      {
  358. +        $('#add_avatar_container').animate({ opacity: "hide" },200);
  359. +        $(document).unbind('click');
  360. +        $(document).unbind('keyup');
  361. +      }
  362. +    }
  363. +  $(document).ready(function(){
  364. +    $('a#add_avatar img').click(function(){
  365. +        $('#add_avatar_container').load('#{@url_new_contact}',function(){
  366. +        pos = $('a#add_avatar').position();
  367. +        width = 330;
  368. +        height = 350;
  369. +        this.style.width = width + 'px';
  370. +        this.style.position = 'absolute';
  371. +        this.style.left = (pos.left - width + 25) + 'px';
  372. +        this.style.top = (pos.top + 34) + 'px';
  373. +        this.style.opacity = 0;
  374. +        this.style.display = 'block';
  375. +        $(this).animate({opacity: 1},150);
  376. +        $(document).bind('click',add_contact_hide);
  377. +        $(document).bind('keyup',add_contact_hide_keyup);
  378. +        $('#contact_search').focus();
  379. +        });
  380. +    });
  381. +  });
  382.  .span-16.last
  383.    .conversation_participants
  384.      .span-9
  385. @@ -14,8 +58,16 @@
  386.          = link_to (image_tag('deletelabel.png') + ' ' + t('.delete').downcase), conversation_conversation_visibility_path(conversation), :method => 'delete', :confirm => t('are_you_sure')
  387.  
  388.      .span-6.avatars.last
  389. -      - for participant in conversation.participants
  390. -        = person_image_link(participant)
  391. +      - if owner then
  392. +        %div#add_avatar_container
  393. +        %a.no_highlight#add_avatar
  394. +          %img{:alt=>t('.add_contact'),:src=>'/images/user/add_contact.png',:title=>t('.add_contact')}
  395. +      - for participant in @conversation_vis
  396. +        - class_name = 'no_highlight'
  397. +        - if participant.owner then class_name = 'owner_highlight'
  398. +        - if participant.editor then class_name = 'editor_highlight'
  399. +        - if participant.deleted then class_name = class_name + ' avatar_hiding'
  400. +        = person_image_link_with_class(participant.person,{},class_name)
  401.  
  402.  %br
  403.  %br
  404. diff --git a/app/views/conversations/access_denied.haml b/app/views/conversations/access_denied.haml
  405. new file mode 100644
  406. index 0000000..69f91a4
  407. --- /dev/null
  408. +++ b/app/views/conversations/access_denied.haml
  409. @@ -0,0 +1,5 @@
  410. +-#   Copyright (c) 2010, Diaspora Inc.  This file is
  411. +-#   licensed under the Affero General Public License version 3 or later.  See
  412. +-#   the COPYRIGHT file.
  413. +
  414. += render 'access_denied'
  415. \ No newline at end of file
  416. diff --git a/app/views/conversations/create_contact.haml b/app/views/conversations/create_contact.haml
  417. new file mode 100644
  418. index 0000000..253b9b7
  419. --- /dev/null
  420. +++ b/app/views/conversations/create_contact.haml
  421. @@ -0,0 +1 @@
  422. += person_image_link(@participant)
  423. \ No newline at end of file
  424. diff --git a/app/views/conversations/delete_contact.haml b/app/views/conversations/delete_contact.haml
  425. new file mode 100644
  426. index 0000000..45b18c4
  427. --- /dev/null
  428. +++ b/app/views/conversations/delete_contact.haml
  429. @@ -0,0 +1 @@
  430. += 'REMOVED'
  431. \ No newline at end of file
  432. diff --git a/app/views/conversations/index.haml b/app/views/conversations/index.haml
  433. index 1285cdd..027b867 100644
  434. --- a/app/views/conversations/index.haml
  435. +++ b/app/views/conversations/index.haml
  436. @@ -34,10 +34,14 @@
  437.            = t('.no_messages')
  438.  
  439.  #conversation_show.span-16.prepend-8.last
  440. -  - if @conversation
  441. -    = render 'conversations/show', :conversation => @conversation
  442. +  - if @conversation and @allow_access then
  443. +    = render 'conversations/show', :conversation => @conversation,:url_new_contact => @url_new_contact,:conversation_vis => @conversation_vis,:owner=>@owner
  444.    - else
  445. -    #no_conversation_text
  446. -      = t('.no_conversation_selected')
  447. -    #no_conversation_controls
  448. -      = link_to t('.create_a_new_message'), new_conversation_path, :rel => 'facebox'
  449. +    - if not @allow_access then
  450. +      = render 'conversations/access_denied',:layout=>false
  451. +    - else
  452. +      #no_conversation_text
  453. +        = t('.no_conversation_selected')
  454. +      #no_conversation_controls
  455. +        = link_to t('.create_a_new_message'), new_conversation_path, :rel => 'facebox'
  456. +
  457. diff --git a/app/views/conversations/new_contact.haml b/app/views/conversations/new_contact.haml
  458. new file mode 100644
  459. index 0000000..f792eb1
  460. --- /dev/null
  461. +++ b/app/views/conversations/new_contact.haml
  462. @@ -0,0 +1,177 @@
  463. +-#   Copyright (c) 2010, Diaspora Inc.  This file is
  464. +-#   licensed under the Affero General Public License version 3 or later.  See
  465. +-#   the COPYRIGHT file.
  466. +-#
  467. +:javascript
  468. +  $(document).ready(function(){
  469. +    $('#contact_search').change(function(){
  470. +      $('.contact_list_new ul li').each(function(indx,val){
  471. +        text_serach = $('#contact_search')[0].value.replace(' ','').toLowerCase();
  472. +        content = $(val).find('h4.name a')[0].textContent.replace(' ','').toLowerCase();
  473. +        if ((content.search(text_serach) >= 0))
  474. +        {
  475. +            $(val).removeClass('hiding');
  476. +        }
  477. +        else
  478. +        {
  479. +            $(val).addClass('hiding');
  480. +        }
  481. +      });
  482. +    });
  483. +  });
  484. +  function change_contact(people_id,url_path,people_url,it,class_name)
  485. +    {
  486. +        g = $.ajax({url:url_path,async:false,cache:false});
  487. +        if (g.status == 200)
  488. +        {
  489. +            if (g.responseText.indexOf('O') != -1)
  490. +            {
  491. +              $(it).parent().parent().parent().find('.right.owner_button span a').addClass('hiding');
  492. +              $(it).parent().parent().parent().find('.right.owner_button span a.remove_owner').removeClass('hiding');
  493. +            }
  494. +            else
  495. +            {
  496. +              $(it).parent().parent().parent().find('.right.owner_button span a').addClass('hiding');
  497. +              $(it).parent().parent().parent().find('.right.owner_button span a.add_owner').removeClass('hiding');
  498. +            }
  499. +
  500. +            if (g.responseText.indexOf('E') != -1)
  501. +            {
  502. +              $(it).parent().parent().parent().find('.right.edit_button span a').addClass('hiding');
  503. +              $(it).parent().parent().parent().find('.right.edit_button span a.remove_editor').removeClass('hiding');
  504. +            }
  505. +            else
  506. +            {
  507. +              $(it).parent().parent().parent().find('.right.edit_button span a').addClass('hiding');
  508. +              $(it).parent().parent().parent().find('.right.edit_button span a.add_editor').removeClass('hiding');
  509. +            }
  510. +
  511. +            if (g.responseText.indexOf('R') != -1)
  512. +            {
  513. +               al_have = false;
  514. +                $('div.span-6.avatars.last a').each(function(indx,itm){
  515. +                    if ($(itm).find('img').data('person_id') == people_id)
  516. +                    {
  517. +                        al_have = true;
  518. +                        if ($(itm).hasClass('avatar_hiding'))
  519. +                        {
  520. +                            $(itm).animate({opacity:1.0},500);
  521. +                            $(itm).removeClass('avatar_hiding');
  522. +                        }
  523. +                    }
  524. +                });
  525. +                if (!al_have)
  526. +                {
  527. +                    $('div.span-6.avatars.last').append(g.responseText);
  528. +                }
  529. +              $(it).parent().parent().parent().find('.right.add_delete_button span a').addClass('hiding');
  530. +              $(it).parent().parent().parent().find('.right.add_delete_button span a.remove').removeClass('hiding');
  531. +            }
  532. +            else
  533. +            {
  534. +              $(it).parent().parent().parent().find('.right.add_delete_button span a').addClass('hiding');
  535. +              $(it).parent().parent().parent().find('.right.add_delete_button span a.add').removeClass('hiding');
  536. +               $('div.span-6.avatars.last a').each(function(indx,itm){
  537. +                    if ($(itm).find('img').data('person_id') == people_id)
  538. +                    {
  539. +                        $(itm).animate({opacity:0.5},500);
  540. +                        $(itm).addClass('avatar_hiding');
  541. +                    }
  542. +                });
  543. +            }
  544. +            if (class_name == 'remove_owner')
  545. +            {
  546. +                $(it).parent().parent().parent().find('.right.edit_button span a').addClass('hiding');
  547. +                $(it).parent().parent().parent().find('.right.edit_button span a.remove_editor').removeClass('hiding');
  548. +                $(it).parent().parent().parent().find('.right.add_delete_button span a').addClass('hiding');
  549. +                $(it).parent().parent().parent().find('.right.add_delete_button span a.remove').removeClass('hiding');
  550. +            }
  551. +            if (class_name == 'remove_editor')
  552. +            {                
  553. +                $(it).parent().parent().parent().find('.right.add_delete_button span a').addClass('hiding');
  554. +                $(it).parent().parent().parent().find('.right.add_delete_button span a.remove').removeClass('hiding');
  555. +            }
  556. +            $('div.span-6.avatars.last a').each(function(indx,itm){
  557. +              if ($(itm).find('img').data('person_id') == people_id)
  558. +              {
  559. +                $(itm).removeClass('no_highlight');
  560. +                $(itm).removeClass('editor_highlight');
  561. +                $(itm).removeClass('owner_highlight');
  562. +                if (g.responseText.indexOf('O')!=-1)
  563. +                {
  564. +                    $(itm).addClass('owner_highlight');
  565. +                }
  566. +                else
  567. +                {
  568. +                    if (g.responseText.indexOf('E')!=-1)
  569. +                    {
  570. +                        $(itm).addClass('editor_highlight');
  571. +                    }
  572. +                    else
  573. +                    {
  574. +                        if (g.responseText.indexOf('R')!=-1)
  575. +                        {
  576. +                            $(itm).addClass('no_highlight');
  577. +                        }
  578. +                    }
  579. +                }
  580. +              }
  581. +            });
  582. +        };
  583. +    }
  584. +.contact_list_new
  585. +  = search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('shared.contact_list.all_contacts')
  586. +  %ul
  587. +    - active_records = @active_contacts.map{|rec| rec.person.id}
  588. +    - for contact in @active_contacts
  589. +      %li{:data=>{:contact_id=>contact.person_id}}
  590. +        = person_image_tag contact.person
  591. +        %h4.name
  592. +          = link_to contact.person.name, contact.person
  593. +          .description
  594. +            = contact.person.diaspora_handle
  595. +        .right.owner_button
  596. +          %span
  597. +            %a{:title=>t('.add_owner'),:class => 'button add_owner' + ((not contact.owner) ? '': ' hiding'),:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'afford_to_own',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"remove_owner");'}
  598. +              = image_tag('icons/monotone_plus_add_round.png')
  599. +            %a{:title=>t('.remove_owner'),:class => 'button remove_owner' + (contact.owner ? '': ' hiding'),:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'prohibit_owning',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"add_owner");'}
  600. +              = image_tag('icons/monotone_check_yes.png')
  601. +        .right.edit_button
  602. +          %span
  603. +            %a{:title=>t('.add_editor'),:class => 'button add_editor' + ((not contact.editor) ? '' : ' hiding'),:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'allow_edit',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"remove_editor");'}
  604. +              = image_tag('icons/monotone_plus_add_round.png')
  605. +            %a{:title=>t('.remove_editor'),:class => 'button remove_editor'  + (contact.editor ? '' : ' hiding'),:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'prohibit_edit',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"add_editor");'}
  606. +              = image_tag('icons/monotone_check_yes.png')
  607. +        .right.add_delete_button
  608. +          %span
  609. +            %a{:title=>t('.add_contact'),:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'create_contact',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"remove");',:class => 'button add'  + (contact.deleted ? '' : ' hiding'),:data_id=>contact.person_id.to_s}
  610. +              = image_tag('icons/monotone_plus_add_round.png')
  611. +            %a{:title=>t('.remove_contact'),:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'delete_contact',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"add");',:class => 'button remove' + ((not contact.deleted) ? '' : ' hiding'),:data_id=>contact.person_id.to_s}
  612. +              = image_tag('icons/monotone_check_yes.png')
  613. +    - for contact in @contacts
  614. +      - if not active_records.any?{|rec| rec == contact.person.id} then
  615. +        %li{:data=>{:contact_id=>contact.person_id}}
  616. +          = person_image_tag contact.person
  617. +          %h4.name
  618. +            = link_to contact.person.name, contact.person
  619. +            .description
  620. +              = contact.person.diaspora_handle
  621. +          .right.owner_button
  622. +            %span
  623. +              %a{:title=>t('.add_owner'),:class => 'button add_owner',:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'afford_to_own',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"remove_owner");'}
  624. +                = image_tag('icons/monotone_plus_add_round.png')
  625. +              %a{:title=>t('.remove_owner'),:class => 'button remove_owner hiding',:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'prohibit_owning',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"add_owner");'}
  626. +                = image_tag('icons/monotone_check_yes.png')
  627. +          .right.edit_button
  628. +            %span
  629. +              %a{:title=>t('.add_editor'),:class => 'button add_editor',:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'allow_edit',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"remove_editor");'}
  630. +                = image_tag('icons/monotone_plus_add_round.png')
  631. +              %a{:title=>t('.remove_editor'),:class => 'button remove_editor hiding',:data_id=>contact.person_id.to_s,:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'prohibit_edit',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"add_editor");'}
  632. +                = image_tag('icons/monotone_check_yes.png')
  633. +          .right.add_delete_button
  634. +            %span
  635. +              %a{:title=>t('.add_contact'),:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'create_contact',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"remove");',:class => 'button add',:data_id=>contact.person_id.to_s}
  636. +                = image_tag('icons/monotone_plus_add_round.png')
  637. +              %a{:title=>t('.remove_contact'),:onclick => 'change_contact(' + contact.person_id.to_s + ',"' + url_for(:action => 'delete_contact',:conversation_id => params[:conversation_id],:person_id => contact.person_id) + '","' + url_for(:controller=>'people',:id => contact.person_id) + '",this,"add");',:class => 'button remove hiding',:data_id=>contact.person_id.to_s}
  638. +                = image_tag('icons/monotone_check_yes.png')
  639. +      
  640. \ No newline at end of file
  641. diff --git a/app/views/conversations/show.haml b/app/views/conversations/show.haml
  642. index b5d871d..77174d2 100644
  643. --- a/app/views/conversations/show.haml
  644. +++ b/app/views/conversations/show.haml
  645. @@ -2,4 +2,4 @@
  646.  -#   licensed under the Affero General Public License version 3 or later.  See
  647.  -#   the COPYRIGHT file.
  648.  
  649. -= render 'show', :conversation => @conversation
  650. += render 'show', :conversation => @conversation,:url_new_contact => @url_new_contact,:conversation_vis => @conversation_vis,:owner => @owner
  651. diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml
  652. index 4dc2743..63a67d9 100644
  653. --- a/config/locales/diaspora/en.yml
  654. +++ b/config/locales/diaspora/en.yml
  655. @@ -188,6 +188,7 @@ en:
  656.      show:
  657.        reply: "reply"
  658.        delete: "delete and block conversation"
  659. +      add_contact: "Add contact"
  660.      new:
  661.        to: "to"
  662.        subject: "subject"
  663. diff --git a/config/locales/diaspora/ru.yml b/config/locales/diaspora/ru.yml
  664. index 0bdb584..92452af 100644
  665. --- a/config/locales/diaspora/ru.yml
  666. +++ b/config/locales/diaspora/ru.yml
  667. @@ -165,6 +165,7 @@ ru:
  668.      show:
  669.        delete: "delete and block conversation"
  670.        reply: "reply"
  671. +      add_contact: "Добавить контакт"
  672.    date:
  673.      formats:
  674.        birthday: "%B %d"
  675. diff --git a/config/routes.rb b/config/routes.rb
  676. index ad70d3e..84d2b5e 100644
  677. --- a/config/routes.rb
  678. +++ b/config/routes.rb
  679. @@ -25,7 +25,13 @@ Diaspora::Application.routes.draw do
  680.    resources :contacts
  681.    resources :aspect_memberships, :only => [:destroy, :create]
  682.  
  683. -
  684. +  match 'conversations/:conversation_id/afford_to_own/:person_id', :to => 'conversations#afford_to_own'
  685. +  match 'conversations/:conversation_id/prohibit_owning/:person_id', :to => 'conversations#prohibit_owning'
  686. +  match 'conversations/:conversation_id/allow_edit/:person_id', :to => 'conversations#allow_edit'
  687. +  match 'conversations/:conversation_id/prohibit_edit/:person_id', :to => 'conversations#prohibit_edit'
  688. +  match 'conversations/:conversation_id/delete_contact/:person_id', :to => 'conversations#delete_contact'
  689. +  match 'conversations/:conversation_id/create_contact/:person_id', :to => 'conversations#create_contact'
  690. +  match 'conversations/:conversation_id/new_contact', :to => 'conversations#new_contact'
  691.    resources :conversations do
  692.      resources :messages, :only => [:create, :show]
  693.      resource :conversation_visibility, :only => [:destroy], :path => '/visibility/'
  694. diff --git a/db/migrate/20110326095653_add_owner_to_conversation_visibility.rb b/db/migrate/20110326095653_add_owner_to_conversation_visibility.rb
  695. new file mode 100644
  696. index 0000000..b97c06e
  697. --- /dev/null
  698. +++ b/db/migrate/20110326095653_add_owner_to_conversation_visibility.rb
  699. @@ -0,0 +1,19 @@
  700. +class AddOwnerToConversationVisibility < ActiveRecord::Migration
  701. +  def self.up
  702. +    add_column :conversation_visibilities, :owner, :boolean
  703. +    add_column :conversation_visibilities, :editor, :boolean
  704. +    add_column :conversation_visibilities, :deleted, :boolean
  705. +    ConversationVisibility.find(:all).each do |p|
  706. +      p.owner = true
  707. +      p.editor = false
  708. +      p.deleted = false
  709. +      p.save
  710. +    end
  711. +  end
  712. +
  713. +  def self.down
  714. +    remove_column :conversation_visibilities, :owner    
  715. +    remove_column :conversation_visibilities, :editor
  716. +    remove_column :conversation_visibilities, :deleted
  717. +  end
  718. +end
  719. diff --git a/db/schema.rb b/db/schema.rb
  720. index a55b15a..8317501 100644
  721. --- a/db/schema.rb
  722. +++ b/db/schema.rb
  723. @@ -10,7 +10,7 @@
  724.  #
  725.  # It's strongly recommended to check this file into your version control system.
  726.  
  727. -ActiveRecord::Schema.define(:version => 20110319005509) do
  728. +ActiveRecord::Schema.define(:version => 20110326095653) do
  729.  
  730.    create_table "aspect_memberships", :force => true do |t|
  731.      t.integer  "aspect_id",  :null => false
  732. @@ -76,6 +76,9 @@ ActiveRecord::Schema.define(:version => 20110319005509) do
  733.      t.integer  "unread",          :default => 0, :null => false
  734.      t.datetime "created_at"
  735.      t.datetime "updated_at"
  736. +    t.boolean  "owner"
  737. +    t.boolean  "deleted"
  738. +    t.boolean  "editor"
  739.    end
  740.  
  741.    add_index "conversation_visibilities", ["conversation_id", "person_id"], :name => "index_conversation_visibilities_on_conversation_id_and_person_id", :unique => true
  742. diff --git a/public/images/user/add_button.png b/public/images/user/add_button.png
  743. new file mode 100644
  744. index 0000000000000000000000000000000000000000..a8ebad327e8ef81cae8c5e5e286446520e5e2ae3
  745. GIT binary patch
  746. literal 242
  747. zcmeAS@N?(olHy`uVBq!ia0vp^Qb26P!3HFqww|5}q!^2X+?^QKos)S9<gg`qySp&_
  748. z2f+n<mrn+Ya29w(7Bet#3xhBt!>l<HKtc8rPhVH|+stAdDqJ%!=H3SiNtU=qlsM<-
  749. z=BDPAFgO>bCYGe8D3oWGWGJ|M`UZqI@`(c#`FgrIhD02GdwnDC0R<igN9&|%DRT_8
  750. zUK{YvR1kD^X?zzQz3b4_&vMT@SY<bA2yn14{f(FznRU_rxv8ExQ=@}|Kt{gC-f0Rz
  751. cnX31Ur+2b@r=0(N8E7zrr>mdKI;Vst0AA)u+W-In
  752.  
  753. literal 0
  754. HcmV?d00001
  755.  
  756. diff --git a/public/images/user/add_contact.png b/public/images/user/add_contact.png
  757. new file mode 100644
  758. index 0000000000000000000000000000000000000000..27125ee0c7b8f5199767024d614bc0f34164bafc
  759. GIT binary patch
  760. literal 234
  761. zcmeAS@N?(olHy`uVBq!ia0vp^{6H+n!3HEh$GDULDaPU;cPEB*=VV?2Ih+L^k;M!Q
  762. z+`=Ht$S`Y;1W=H@#M9T6{Wh~0hoL49^RJyiA;}Wgh!W@g+}zZ>5(ej@)Wnk16ovB4
  763. zk_-iRPv3y>Mm}+%qHs?a#}JFt$u(bJU9D#`Viaa(O$hmX;=-9GZ>9Wft2wqOtDhy5
  764. zeyeA@^qE~*CtUIOM1h7@M&X^?g5IRN<+L8GZ~M>lGuoI<VU>iW1pA5ei+@&z7#lG#
  765. Y#0$vj$4>U}1zN%2>FVdQ&MBb@0GifDvH$=8
  766.  
  767. literal 0
  768. HcmV?d00001
  769.  
  770. diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass
  771. index 9e801f8..b3b2b50 100644
  772. --- a/public/stylesheets/sass/application.sass
  773. +++ b/public/stylesheets/sass/application.sass
  774. @@ -53,6 +53,15 @@ form
  775.    :width 50px
  776.    :height 50px
  777.  
  778. +#add_avatar_container
  779. +  :border 2px solid rgba(0,0,0,0.3)
  780. +  :-moz-box-shadow 0 0 8px black
  781. +  :-webkit-box-shadow 0 0 8px black
  782. +  :box-shadow 0 0 8px black
  783. +  :border-radius 3px
  784. +  :opacity 0.0
  785. +  :display none
  786. +
  787.  #content
  788.    :background
  789.      :color #fff
  790. @@ -1811,6 +1820,94 @@ ul#request_result
  791.        :bottom 25px
  792.      input.add
  793.        :color green
  794. +.contact_list_new
  795. +  :height 450px
  796. +  :max-height 450px
  797. +
  798. +  :overflow-y hidden
  799. +  :overflow-x hidden
  800. +
  801. +  :border 2px solid #eee
  802. +
  803. +  :background
  804. +    :color rgb(252,252,252)
  805. +
  806. +  .name
  807. +    :position absolute
  808. +    :left 70px
  809. +    :top 10px
  810. +
  811. +  .avatar
  812. +    :position absolute
  813. +    :left 6px
  814. +    :height 50px
  815. +    :width 50px
  816. +
  817. +  :-webkit-box-shadow 0 1px #fff
  818. +  :-moz-box-shadow 0 1px #fff
  819. +  :box-shadow 0 1px #fff
  820. +
  821. +  :-webkit-border-radius 0 0 5px 5px
  822. +  :-moz-border-radius 0 0 5px 5px
  823. +  :border-radius 0 0 5px 5px
  824. +
  825. +  input.contact_list_search
  826. +    :width 97.5%
  827. +    :margin
  828. +      :top 0
  829. +
  830. +  ul
  831. +    :margin-top 1px
  832. +    :margin-left 0px
  833. +    :margin-right 0px
  834. +    :padding 0
  835. +    :overflow-y auto
  836. +    :height 423px
  837. +
  838. +    > li.hiding
  839. +      :display none
  840. +
  841. +    > li
  842. +      :position relative
  843. +      :height 50px
  844. +      :padding 4px
  845. +      :border
  846. +        :bottom 1px solid #eee
  847. +
  848. +      &:last-child
  849. +        :border
  850. +          :bottom none
  851. +
  852. +      &:hover
  853. +        :background
  854. +          :color rgb(245,245,245)
  855. +      .hiding
  856. +        :display none
  857. +      .right
  858. +        :right 8px
  859. +        :top 12px
  860. +      .overflow
  861. +        :overflow-y scroll
  862. +      .owner_button
  863. +        :margin-right 70px
  864. +      .edit_button
  865. +        :margin-right 35px
  866. +      a.button
  867. +        :padding
  868. +          :right 4px
  869. +          :left 4px
  870. +        &.added
  871. +          :background -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(92,199,86)), color-stop(1, rgb(158,255,153)))
  872. +          :background -moz-linear-gradient(top, rgb(158,255,153), rgb(92,199,86))
  873. +
  874. +        &.added.remove
  875. +          :background -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(199,86,86)), color-stop(1, rgb(255,153,153)))
  876. +          :background -moz-linear-gradient(top, rgb(255,153,153), rgb(199,86,86))
  877. +
  878. +          &:active
  879. +            :background -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(130,55,55)), color-stop(1, rgb(199,119,119)))
  880. +            :background -moz-linear-gradient(top, rgb(199,119,119), rgb(130,55,55))
  881. +
  882.  
  883.  .contact_list,
  884.  .aspect_list
  885. @@ -1845,7 +1942,7 @@ ul#request_result
  886.    :border-radius 0 0 5px 5px
  887.  
  888.    input.contact_list_search
  889. -    :width 100%
  890. +    :width 97.5%
  891.      :margin
  892.        :top 0
  893.  
  894. @@ -1853,6 +1950,9 @@ ul#request_result
  895.      :margin 0
  896.      :padding 0
  897.  
  898. +    > li.hiding
  899. +      :display none
  900. +
  901.      > li
  902.        :position relative
  903.        :height 50px
  904. @@ -1867,11 +1967,17 @@ ul#request_result
  905.        &:hover
  906.          :background
  907.            :color rgb(245,245,245)
  908. -
  909. +      .hiding
  910. +        :display none
  911.        .right
  912.          :right 8px
  913.          :top 12px
  914. -
  915. +      .overflow
  916. +        :overflow-y scroll
  917. +      .owner_button
  918. +        :margin-right 70px
  919. +      .edit_button
  920. +        :margin-right 35px
  921.        a.button
  922.          :padding
  923.            :right 4px
  924. @@ -2629,7 +2735,6 @@ ul.show_comments
  925.      a
  926.        :margin
  927.          :right 10px
  928. -
  929.      :margin
  930.        :bottom 10px
  931.  
  932. @@ -2647,6 +2752,28 @@ ul.show_comments
  933.      :margin
  934.        :top 9px
  935.  
  936. +
  937. +.avatars.last
  938. +  a.owner_highlight
  939. +    img
  940. +      :-moz-box-shadow 0 0 3px #006700
  941. +      :-webkit-box-shadow 0 0 3px #006700
  942. +      :box-shadow 0 0 3px #006700
  943. +  a.editor_highlight
  944. +    img
  945. +      :-moz-box-shadow 0 0 3px #A87DFF
  946. +      :-webkit-box-shadow 0 0 3px #A87DFF
  947. +      :box-shadow 0 0 3px #A87DFF
  948. +  a.no_highlight
  949. +    img
  950. +      :-moz-box-shadow 0 0 3px gray
  951. +      :-webkit-box-shadow 0 0 3px gray
  952. +      :box-shadow 0 0 3px gray
  953. +  a.avatar_hiding
  954. +    img
  955. +      :opacity 0.5
  956. +
  957. +
  958.  .stream_element.new_message
  959.    :border
  960.      :top 1px solid #999
  961. @@ -2767,6 +2894,16 @@ ul.show_comments
  962.    :font
  963.      :size 12px
  964.  
  965. +#acces_denied
  966. +  :text
  967. +    :align center
  968. +  :font
  969. +    :size 20px
  970. +    :weight bold
  971. +  :color black
  972. +  :margin
  973. +    :top 200px
  974. +
  975.  .text-right
  976.    :text
  977.      :align right
  978. --
  979. 1.7.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement