From 01dac4d1735f943b8ef2c57b0be1e68f1b3643ef Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 23 Aug 2010 11:56:06 -0700 Subject: [PATCH 1/6] Take tinymce out of layout --- app/controllers/photos_controller.rb | 1 + app/models/user.rb | 3 +++ app/views/layouts/application.html.haml | 1 - app/views/photos/_new_photo.haml | 13 +++++++++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 2996a23ec..eb165ca2d 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -21,6 +21,7 @@ class PhotosController < ApplicationController def new @photo = Photo.new + render :partial => "new_photo" end def destroy diff --git a/app/models/user.rb b/app/models/user.rb index c26e02f1c..fe4cb1ea9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -46,6 +46,9 @@ class User options.delete(:group_id) model_class = class_name.to_s.camelize.constantize + + pp options + post = model_class.instantiate(options) post.creator_signature = post.sign_with_key(encryption_key) post.save diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index da2b73eb8..8432ac92a 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -13,7 +13,6 @@ /= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" = javascript_include_tag 'jquery142', 'rails', 'google' - = javascript_include_tag 'tiny_mce/tiny_mce' = javascript_include_tag 'jquery.infieldlabel', 'jquery.cycle/jquery.cycle.min.js' = javascript_include_tag 'fancybox/jquery.fancybox-1.3.1.pack' diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index b57731596..0704c0244 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -12,8 +12,9 @@ $("#add_photo_loader").fadeOut(400); $("#photo_title_status").text("Done!"); - $("#progress_report").html("Great job!"); - }, + $("#progress_report").html(""); + resetPhotoButton + }, onStart: function(event, total){ $("#add_photo_button").html( "Uploading Photos" ); $("#add_photo_loader").fadeIn(400); @@ -26,6 +27,14 @@ }); }); + function resetPhotoButton{ + $("#add_photo_button").click(function (evt){ + $("#new_photo_pane").html($.get("photos/ajax_new")); + $("#add_photo_button").unbind(); + $("#add_photo_button").fancybox(); + } + } + %h1 %span{:id=>"photo_title_status"} Add photos to From 0092069372b616e77c6a20ffb3a3a3da22d30517 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 23 Aug 2010 11:57:29 -0700 Subject: [PATCH 2/6] Take signed in check out of websocket js --- app/views/js/_websocket_js.haml | 184 ++++++++++++++++---------------- 1 file changed, 91 insertions(+), 93 deletions(-) diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index 443726e50..282a07624 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -1,103 +1,101 @@ -- if user_signed_in? - = javascript_include_tag 'FABridge', 'swfobject', 'web_socket' - :javascript - WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf"; - :javascript - $(document).ready(function(){ - function debug(str){ $("#debug").append("

" + str); }; += javascript_include_tag 'FABridge', 'swfobject', 'web_socket' +:javascript + WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf"; + $(document).ready(function(){ + function debug(str){ $("#debug").append("

" + str); }; - ws = new WebSocket("ws://#{request.host}:8080/#{CGI::escape(current_user.id.to_s)}"); + ws = new WebSocket("ws://#{request.host}:8080/#{CGI::escape(current_user.id.to_s)}"); - //Attach onmessage to websocket - ws.onmessage = function(evt) { - var obj = jQuery.parseJSON(evt.data); - debug("got a " + obj['class'] + " for group " + obj['group_id']); + //Attach onmessage to websocket + ws.onmessage = function(evt) { + var obj = jQuery.parseJSON(evt.data); + debug("got a " + obj['class'] + " for group " + obj['group_id']); - if (obj['class']=="retractions"){ - processRetraction(obj['post_id']); - - }else if (obj['class']=="comments"){ - processComment(obj['post_id'], obj['html']) - - }else if (obj['class']=='photos' && onPageForClass('albums')){ - processPhotoInAlbum(obj['photo_hash']) - }else if (obj['class']=='status_messages'){ - processStatusMessage(obj['class'], obj['html'], obj['status_message_hash'], obj['group_id'], obj['mine?']) - }else{ - processPost(obj['class'], obj['html'], obj['group_id'], obj['mine?']) - } - - - }; - ws.onclose = function() { debug("socket closed"); }; - ws.onopen = function() { - ws.send(location.pathname); - debug("connected..."); - }; - - function processRetraction(post_id){ - $('#' + post_id ).fadeOut(500, function(){ - $(this).remove; - }); - } - - function processComment(post_id, html){ - post = $('#' + post_id)[0] - $(' .comment_set li:last', post ).before( - $(html).fadeIn("fast", function(){}) - ); - toggler = $('.show_post_comments', post) - toggler.html( - toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1)); - } - - function processPost(className, html, groupId, mineBool){ - if(mineBool || onPageForClass(className) || onPageForGroup(groupId)){ - $("#stream").prepend( - $(html).fadeIn("fast", function(){ - $("#stream label:first").inFieldLabels(); - }) - ); - } - } - - function processStatusMessage(className, html, messageHash, groupId, mineBool){ - processPost(className, html, groupId, mineBool); - console.log(messageHash) - if(messageHash['mine?']){ - updateMyLatestStatus(messageHash); - } - } + if (obj['class']=="retractions"){ + processRetraction(obj['post_id']); - function updateMyLatestStatus(messageHash){ - $("#latest_message").text(messageHash['text']); - $("#latest_message_time").text(' - just now'); + }else if (obj['class']=="comments"){ + processComment(obj['post_id'], obj['html']) + + }else if (obj['class']=='photos' && onPageForClass('albums')){ + processPhotoInAlbum(obj['photo_hash']) + }else if (obj['class']=='status_messages'){ + processStatusMessage(obj['class'], obj['html'], obj['status_message_hash'], obj['group_id'], obj['mine?']) + }else{ + processPost(obj['class'], obj['html'], obj['group_id'], obj['mine?']) } - function processPhotoInAlbum(photoHash){ - if (location.href.indexOf(photoHash['album_id']) == -1){ - return ; - } - html = "

" - $("#thumbnails").append( $(html) ) - $("#"+ photoHash['id'] + " img").load( function() { - $(this).fadeIn("slow"); - }); - } - function onPageForClass(className){ - return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne(); - } + }; + ws.onclose = function() { debug("socket closed"); }; + ws.onopen = function() { + ws.send(location.pathname); + debug("connected..."); + }; - function onPageForGroup(groupId){ - return (location.href.indexOf(groupId) != -1 ) + function processRetraction(post_id){ + $('#' + post_id ).fadeOut(500, function(){ + $(this).remove; + }); + } + + function processComment(post_id, html){ + post = $('#' + post_id)[0] + $(' .comment_set li:last', post ).before( + $(html).fadeIn("fast", function(){}) + ); + toggler = $('.show_post_comments', post) + toggler.html( + toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1)); + } + + function processPost(className, html, groupId, mineBool){ + if(mineBool || onPageForClass(className) || onPageForGroup(groupId)){ + $("#stream").prepend( + $(html).fadeIn("fast", function(){ + $("#stream label:first").inFieldLabels(); + }) + ); } - - function onPageOne() { - var c = document.location.search.charAt(document.location.search.length-1); - return ((c =='') || (c== '1')); + } + + function processStatusMessage(className, html, messageHash, groupId, mineBool){ + processPost(className, html, groupId, mineBool); + console.log(messageHash) + if(messageHash['mine?']){ + updateMyLatestStatus(messageHash); } - }); + } + + function updateMyLatestStatus(messageHash){ + $("#latest_message").text(messageHash['text']); + $("#latest_message_time").text(' - just now'); + } + + function processPhotoInAlbum(photoHash){ + if (location.href.indexOf(photoHash['album_id']) == -1){ + return ; + } + html = "" + $("#thumbnails").append( $(html) ) + $("#"+ photoHash['id'] + " img").load( function() { + $(this).fadeIn("slow"); + }); + } + + function onPageForClass(className){ + return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne(); + } + + function onPageForGroup(groupId){ + return (location.href.indexOf(groupId) != -1 ) + } + + function onPageOne() { + var c = document.location.search.charAt(document.location.search.length-1); + return ((c =='') || (c== '1')); + } + }); From 9ef200861308eb0fdb134e76b803bc424b218812 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 23 Aug 2010 11:59:58 -0700 Subject: [PATCH 3/6] Remove tinymce init block --- public/javascripts/view.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/public/javascripts/view.js b/public/javascripts/view.js index aa87fda21..b1baae31e 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -1,19 +1,4 @@ $(document).ready(function(){ - tinyMCE.init({ - mode : "exact", - elements: "blog_editor", - theme : "advanced", - plugins : "emotions,spellchecker,advhr,insertdatetime,preview", - - // Theme options - button# indicated the row# only - theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontsizeselect,formatselect", - theme_advanced_buttons2 : "cut,copy,paste|,bullist,numlist,|,outdent,indent|,undo,redo,|,link,unlink,anchor,image,|,preview,|,forecolor,backcolor", - theme_advanced_buttons3 : "insertdate,inserttime,|,spellchecker,|,sub,sup,|,charmap,emotions", - theme_advanced_toolbar_location : "top", - theme_advanced_toolbar_align : "left", - //theme_advanced_resizing : true //leave this out as there is an intermittent bug. - }); - $('.comment_set').each(function(index) { if($(this).children().length > 1) { From 97aa8a4dc949f374ccbf4e4febc6854109d1be30 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 23 Aug 2010 13:57:33 -0700 Subject: [PATCH 4/6] No photos index route --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 946d34729..80aa3d872 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ Diaspora::Application.routes.draw do resources :status_messages resources :comments resources :requests - resources :photos + resources :photos, :except => [:index] resources :albums resources :groups From efb4100e013d333161e0abb47b136eb1d150cf28 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 23 Aug 2010 13:58:09 -0700 Subject: [PATCH 5/6] Split up socket debug and app debug --- config/app_config.yml | 3 +++ config/initializers/socket.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/app_config.yml b/config/app_config.yml index 0c87b6b4c..1eee9376c 100644 --- a/config/app_config.yml +++ b/config/app_config.yml @@ -1,14 +1,17 @@ development: debug: false + socket_debug : false socket_port: 8080 pubsub_server: 'https://pubsubhubbub.appspot.com/' test: debug: false + socket_debug : false socket_port: 8081 pubsub_server: 'https://pubsubhubbub.appspot.com/' production: debug: false + socket_debug : false socket_port: 8080 pubsub_server: 'https://pubsubhubbub.appspot.com/' diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 381d1f6c2..03f9e24eb 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -7,7 +7,7 @@ require "lib/diaspora/websocket" EventMachine::WebSocket.start( :host => "0.0.0.0", :port => APP_CONFIG[:socket_port], - :debug =>APP_CONFIG[:debug]) do |ws| + :debug =>APP_CONFIG[:socket_debug]) do |ws| ws.onopen { sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws) From ae6f0fdc51be17b3c90bbacfd9d4979bc9b3d56a Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 23 Aug 2010 13:58:33 -0700 Subject: [PATCH 6/6] new photo form now loads through ajax --- app/controllers/photos_controller.rb | 2 ++ app/models/user.rb | 7 +++++-- app/views/albums/show.html.haml | 7 ++++++- app/views/photos/_new_photo.haml | 21 +++++++-------------- public/javascripts/view.js | 15 ++++++++++++++- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index eb165ca2d..46332992d 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -2,6 +2,7 @@ class PhotosController < ApplicationController before_filter :authenticate_user! def create + render :nothing => true begin @photo = current_user.post(:photo, params) @@ -21,6 +22,7 @@ class PhotosController < ApplicationController def new @photo = Photo.new + @album = current_user.album_by_id(params[:album_id]) render :partial => "new_photo" end diff --git a/app/models/user.rb b/app/models/user.rb index fe4cb1ea9..38dde280a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,8 +47,6 @@ class User model_class = class_name.to_s.camelize.constantize - pp options - post = model_class.instantiate(options) post.creator_signature = post.sign_with_key(encryption_key) post.save @@ -327,6 +325,11 @@ class User groups.detect{|x| x.id == id } end + def album_by_id( id ) + id = ensure_bson id + albums.detect{|x| x.id == id } + end + def groups_with_person person id = ensure_bson person.id groups.select {|group| group.person_ids.include? id} diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index 04b117645..c0cf97427 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -1,3 +1,9 @@ +:javascript + $(document).ready(function(){ + reset_photo_fancybox(); + }); + +.album_id{:id => @album.id, :style => "display:hidden;"} .back= link_to '⇧ albums', albums_path %h1.big_text @@ -11,7 +17,6 @@ .yo{:style => "display:none;"} #new_photo_pane - = render "photos/new_photo", :photo => @photo, :album => @album .sub_header ="updated #{how_long_ago(@album)}" diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index 0704c0244..5bc6d6882 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -2,7 +2,7 @@ $(function() { $("#photo_image").html5_upload({ // WE INSERT ALBUM_ID PARAM HERE - url: "/photos?album_id=#{album.id}", + url: "/photos?album_id=#{@album.id}", sendBoundary: window.FormData || $.browser.mozilla, setName: function(text) { $("#progress_report_name").text(text); @@ -12,8 +12,9 @@ $("#add_photo_loader").fadeOut(400); $("#photo_title_status").text("Done!"); - $("#progress_report").html(""); - resetPhotoButton + $("#progress_report").html("Good job me!"); + + $("#add_photo_button").addClass("uploading_complete"); }, onStart: function(event, total){ $("#add_photo_button").html( "Uploading Photos" ); @@ -27,21 +28,13 @@ }); }); - function resetPhotoButton{ - $("#add_photo_button").click(function (evt){ - $("#new_photo_pane").html($.get("photos/ajax_new")); - $("#add_photo_button").unbind(); - $("#add_photo_button").fancybox(); - } - } - %h1 %span{:id=>"photo_title_status"} Add photos to - %i= album.name -= form_for photo, :html => {:multipart => true} do |f| + %i= @album.name += form_for @photo, :html => {:multipart => true} do |f| = f.error_messages - = f.hidden_field :album_id, :value => album.id + = f.hidden_field :album_id, :value => @album.id = f.file_field :image, :multiple => 'multiple' #progress_report{ :style => "display:none;text-align:center;" } diff --git a/public/javascripts/view.js b/public/javascripts/view.js index b1baae31e..720709b8e 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -71,7 +71,14 @@ $(document).ready(function(){ $("#add_album_button").fancybox(); $("#add_group_button").fancybox(); $("#add_request_button").fancybox({ 'titleShow': false }); - $("#add_photo_button").fancybox(); + $("#add_photo_button").fancybox({ + 'onClosed' : function(){ + if($("#add_photo_button").hasClass("uploading_complete")){ + $("#add_photo_button").removeClass("uploading_complete"); + reset_photo_fancybox(); + } + } + }); //pane_toggler_button("photo"); @@ -91,6 +98,12 @@ $(document).ready(function(){ });//end document ready +function reset_photo_fancybox(){ + album_id = $(".album_id")[0].id; + ajax = $.get("/photos/new?album_id=" + album_id, function(){ + $("#new_photo_pane").html(ajax.responseText) + }); +} function pane_toggler_button( name ) {