Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
View
7 Gemfile
@@ -22,6 +22,7 @@ group :default do
gem 'nested_form', :git => 'git://github.com/ryanb/nested_form.git'
gem 'openteam-commons'
gem 'pg', :require => false
+ gem 'progress_bar'
gem 'rails'
gem 'russian'
gem 'show_for'
@@ -36,9 +37,3 @@ group :development do
gem 'sunspot_solr'
end
-group :test do
- gem 'fabrication', :require => false
- gem 'rspec-rails'
- gem 'shoulda-matchers', :require => false
- gem 'sunspot_matchers', :require => false
-end
View
30 Gemfile.lock
@@ -59,7 +59,6 @@ GEM
json
curb (0.8.0)
default_value_for (1.0.7)
- diff-lcs (1.1.3)
el_vfs_client (0.3.5)
configliere
curb
@@ -67,13 +66,14 @@ GEM
erubis (2.7.0)
execjs (1.3.1)
multi_json (~> 1.0)
- fabrication (1.4.0)
+ fattr (2.2.1)
formtastic (2.2.0)
actionpack (>= 3.0)
fssm (0.2.9)
has_scope (0.5.1)
has_searcher (0.0.13)
rails
+ highline (1.6.12)
hike (1.2.1)
hirb (0.6.2)
i18n (0.6.0)
@@ -108,9 +108,14 @@ GEM
configliere
rails
unicorn
+ options (2.3.0)
+ fattr
pg (0.13.2)
polyglot (0.3.3)
pr_geohash (1.0.0)
+ progress_bar (0.4.0)
+ highline (~> 1.6.1)
+ options (~> 2.3.0)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -141,19 +146,6 @@ GEM
railties (~> 3.1)
rsolr (1.0.8)
builder (>= 2.1.2)
- rspec (2.10.0)
- rspec-core (~> 2.10.0)
- rspec-expectations (~> 2.10.0)
- rspec-mocks (~> 2.10.0)
- rspec-core (2.10.0)
- rspec-expectations (2.10.0)
- diff-lcs (~> 1.1.3)
- rspec-mocks (2.10.1)
- rspec-rails (2.10.1)
- actionpack (>= 3.0)
- activesupport (>= 3.0)
- railties (>= 3.0)
- rspec (~> 2.10.0)
russian (0.6.0)
i18n (>= 0.5.0)
sass (3.1.16)
@@ -161,8 +153,6 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- shoulda-matchers (1.1.0)
- activesupport (>= 3.0.0)
show_for (0.2.4)
simple_form (2.0.2)
actionpack (~> 3.0)
@@ -175,7 +165,6 @@ GEM
sunspot (2.0.0.pre.120417)
pr_geohash (~> 1.0)
rsolr (~> 1.0.7)
- sunspot_matchers (1.3.0.1)
sunspot_rails (2.0.0.pre.120417)
nokogiri
sunspot (= 2.0.0.pre.120417)
@@ -211,7 +200,6 @@ DEPENDENCIES
curb
default_value_for
el_vfs_client
- fabrication
formtastic
has_scope
has_searcher
@@ -222,15 +210,13 @@ DEPENDENCIES
nested_form!
openteam-commons
pg
+ progress_bar
rails
- rspec-rails
russian
sass-rails
- shoulda-matchers
show_for
simple_form
sqlite3
- sunspot_matchers
sunspot_rails
sunspot_solr
therubyracer
View
1 app/assets/javascripts/manage/application.js
@@ -10,5 +10,6 @@
* = require ./datetime_picker
* = require ./jwysiwyg
* = require ./geocoder
+ * = require ./info_plugin
* = require ./main
*/
View
3 app/assets/javascripts/manage/info_plugin/index.js
@@ -0,0 +1,3 @@
+/*
+ * = require_tree .
+ */
View
264 app/assets/javascripts/manage/info_plugin/info_plugin.js
@@ -0,0 +1,264 @@
+// Добавление loader и блокировка ссылки
+$.fn.add_loader_and_lock = function(){
+ $(this).append($('<span/>', { class: 'ajax_loading' }));
+ $(this).addClass('clicked');
+};
+
+// Создание диалога
+$.fn.create_or_return_dialog = function(class_name){
+ var clicked_link = $(this);
+ var container = $('#'+class_name);
+
+ if (container.length == 0) {
+ $('<div/>', { id: class_name }).appendTo('body').dialog({
+ autoOpen: false,
+ draggable: false,
+ height: '525',
+ modal: true,
+ position: 'center',
+ resizable: false,
+ title: 'Выбор файла',
+ width: '855',
+ beforeClose: function(event, ui){
+ $('body').css({ overflow: 'inherit' });
+ remove_ajax_and_unblock_link();
+ }
+ });
+ };
+
+ return $('#'+class_name);
+};
+
+// Загрузка iframe в диалог
+$.fn.load_iframe = function(params){
+ var dialog = $(this);
+ dialog.dialog({height: '445'});
+ dialog.html(
+ $('<iframe/>',
+ {
+ height: '402',
+ scrolling: 'no',
+ src: '/el_finder?'+params,
+ width: '825'
+ }
+ ).load(function(){
+ dialog.open_dialog();
+ })
+ )
+};
+
+// Показать диалог
+$.fn.open_dialog = function(){
+ remove_ajax_and_unblock_link();
+ $('body').css({ overflow: 'hidden' });
+ $(this).dialog('open');
+};
+
+$.fn.create_or_return_ckeditor = function(){
+ var dialog = $(this);
+ var dialog_id = dialog.attr('id');
+ var ckeditor_instance = CKEDITOR.instances['editor1'];
+
+ if (!ckeditor_instance){
+ ckeditor_instance = CKEDITOR.appendTo(
+ dialog_id,
+ {
+ height: '320',
+ width: '830',
+ resize_enabled: false
+ }
+ );
+ };
+
+ return ckeditor_instance;
+};
+
+$.fn.save_file_content = function(common_path, info_path){
+ var dialog = $(this);
+ var content = CKEDITOR.instances['editor1'].getData();
+ var path_object = get_file_name_and_hash(info_path);
+
+ $('.error_messages').remove();
+ $('.ui-dialog-buttonset').append($('<span/>', { class: 'ajax_loading', style: 'float: left; margin: 10px 5px 0 0;' }));
+
+ $.post(common_path+'&root_path='+path_object.info_path+'&cmd=put&target=r1_'+path_object.file_name_hash, { content: content })
+ .success(function(){
+ dialog.dialog('close');
+ show_content(content);
+ })
+ .error(function(){
+ $('.ui-dialog-buttonset')
+ .append('<span style="color:red; float: left; margin: 10px 5px 0 0;" class="error_messages">Ошибка при сохранении! Обратитесь в службу поддержки.</span>');
+ })
+ .complete(function(){remove_ajax_and_unblock_link()});
+};
+
+$.fn.get_file_content = function(common_path, info_path, ckeditor){
+ var dialog = $(this);
+ // Получить путь к папке, имя файла и base64 хеш файла
+ var path_object = get_file_name_and_hash(info_path);
+ var file_name = path_object.file_name;
+ var file_name_hash = path_object.file_name_hash;
+ info_path = path_object.info_path;
+
+ // Открыть папку
+ $.get(common_path+'&root_path='+info_path+'&cmd=open&init=1', function(folder_data){
+ var files = folder_data.files;
+ var folder = folder_data.cwd;
+ var file_content = '';
+ var need_create_index_html = true;
+
+ // Посмотреть есть ли файл
+ $(files).each(function(index, file){
+ if (file.hash.match(file_name_hash)){
+ need_create_index_html = false;
+ // Загрузить файл в CKEditor
+ $.get(common_path+'&root_path='+info_path+'&cmd=get&target='+file.hash, function(file_data){
+ file_content = file_data.content;
+ ckeditor.setData(file_content);
+ dialog.open_dialog();
+ });
+ return false;
+ }
+ });
+
+ // Создать файл если его нет
+ if (need_create_index_html){
+ $.get(common_path+'&root_path='+info_path+'&cmd=mkfile&name='+file_name+'&target='+folder.hash, function(file_data){
+ dialog.open_dialog();
+ });
+ };
+ });
+};
+
+function get_file_name_and_hash(info_path){
+ var file_name = info_path.match(/[^\/]*?$/)[0];
+ var file_name_hash = service({ encode: true, path_to_hash: file_name });
+ info_path = info_path.replace(file_name, '');
+
+ return {
+ file_name: file_name,
+ file_name_hash: file_name_hash,
+ info_path: info_path
+ };
+};
+
+function remove_ajax_and_unblock_link(){
+ $('.ajax_loading').remove();
+ $('.clicked').removeClass('clicked');
+};
+
+// Работа с service_controller
+function service(params){
+ var result = '';
+ $.ajax({
+ url: '/build_info_path',
+ async: false,
+ type: 'GET',
+ data: params,
+ success: function(data){
+ result = data;
+ }
+ });
+
+ return result;
+};
+
+function show_content(content) {
+ $('.show_info_path').html(content);
+};
+
+// Вешаем обработку изменения поля info_path после callback из elFinder
+$.fn.watch_for_callback_from_elFinder = function(){
+ var dialog = $(this);
+ $('#info_path').change(function(){
+ var info_path_input = $(this);
+ var info_path_hash = info_path_input.val();
+
+ // Декодировать hash из callback elFinder
+ var info_path = service({ decode: true, path_hash: info_path_hash});
+
+ // Записать в input
+ info_path_input.val(info_path);
+ info_path_input.unbind('change');
+
+ dialog.dialog('close');
+ });
+};
+
+//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
+$(function(){
+ var create_edit_link = $('.info_link');
+ var choose_link = $('.choose_link');
+ var info_path_input = $('#info_path');
+ var info_path = info_path_input.val(); // Путь к файлу контента
+ var common_path = '/api/el_finder/v2?format=json';
+
+ create_edit_link.click(function(){
+ var parent_id = create_edit_link.attr('parent_data');
+ var additional = $('.for_info_path').val();
+
+ $('.error_messages').remove();
+
+ if (additional.length == 0){
+ $('.info_wrapper').append('<span class="error_messages" style="float: right; color: red;">Заполните обязательные поля!!!</span>');
+ remove_ajax_and_unblock_link();
+ return false;
+ };
+
+ if ($(this).hasClass('clicked')) {
+ return false;
+ };
+ // Добавить loader и заблокировать ссылку
+ create_edit_link.add_loader_and_lock();
+
+ // Создать диалог для CKEditor
+ var dialog = create_edit_link.create_or_return_dialog('ckeditor_dialog');
+ dialog.dialog({
+ buttons: {
+ 'Сохранить': function(){
+ dialog.save_file_content(common_path, info_path);
+ },
+
+ 'Отмена': function(){
+ dialog.dialog('close');
+ }
+ }
+ });
+
+ // Если нет info_path сгенерить
+ if (info_path.length == 0){
+ info_path = service({ parent_id: parent_id, additional: additional });
+ info_path_input.val(info_path);
+ };
+
+ // Создать CKEditor
+ var ckeditor = dialog.create_or_return_ckeditor();
+
+ dialog.get_file_content(common_path, info_path, ckeditor);
+
+ return false;
+ });
+
+ choose_link.click(function(){
+ if ($(this).hasClass('clicked')) {
+ return false;
+ };
+ // Добавить loader и заблокировать ссылку
+ choose_link.add_loader_and_lock();
+
+ // Создать диалог для elFinder
+ var dialog = choose_link.create_or_return_dialog('elfinder_dialog');
+
+ // Загрузить iframe elFinder в диалог и показать его
+ dialog.load_iframe();
+
+ // Повесить обработчик на callback elFinder
+ dialog.watch_for_callback_from_elFinder();
+
+ return false;
+ });
+
+});
+
+
View
32 app/assets/javascripts/manage/main.js.coffee
@@ -1,25 +1,25 @@
handle_adding_poster = ->
- $('.add_poster').click ->
+ $('.choose_file').live('click', ->
+ link = $(this)
params = $(this).attr('params')
- target = '.' + $(this).attr('id')
+ attached_file_wrapper = link.parent()
+ origin_id = attached_file_wrapper.find('input').attr('id')
+ input = $('#'+origin_id)
- $(this).slideUp()
+ dialog = link.create_or_return_dialog('elfinder_picture_dialog')
- $(target).html($('<iframe/>',
- src: '/el_finder?' + params
- width: '700'
- height: '400'
- scrolling: 'no'
- id: 'el_finder_iframe'
- ).load ->
- $('.content_wrapper').animate
- scrollTop: $(document).height() + $(target).height()
- 'slow'
- ).slideDown()
+ dialog.attr('id_data', origin_id)
- false
+ dialog.load_iframe(params)
+
+ input.change ->
+ image_url = input.val()
+ file_name = decodeURIComponent(image_url).match(/([^\/.]+)(\.(.{3}))?$/)
+ attached_file_wrapper.children('.image_wrapper').html('<a href="'+image_url+'"><img src="'+image_url.replace(new RegExp(/\d+-\d+/), '150-150')+'" width="150" ></a>')
+ input.unbind('change')
-handle_date_picker = ->
+ false
+ )
$ ->
handle_adding_poster()
View
3 app/assets/stylesheets/public/main_page.sass
@@ -114,7 +114,8 @@
width: 100%
position: relative
- .poster_wrapper
+ .poster_wrapper,
+ .image_wrapper
float: left
width: 100%
View
4 app/helpers/application_helper.rb
@@ -12,6 +12,10 @@ def poster_image_tag_for(affiche, width, height, crop = true)
image_tag resized_image_url(affiche.poster_url, width, height, crop)
end
+ def image_image_tag_for(affiche, width, height)
+ image_tag resized_image_url(affiche.image_url, width, height, true)
+ end
+
private
def resized_image_url(url, width, height, crop)
image_url, image_id, image_width, image_height, image_crop, image_filename =
View
4 app/models/affiches/affiche.rb
@@ -1,5 +1,5 @@
class Affiche < ActiveRecord::Base
- attr_accessible :description, :poster_url, :showings_attributes, :tag, :title
+ attr_accessible :description, :poster_url, :image_url, :showings_attributes, :tag, :title, :vfs_path
validates_presence_of :description, :poster_url, :title
@@ -20,7 +20,7 @@ def showings_grouped_by_day(search_params = nil)
end
def tags
- tag.split(',').map(&:squish)
+ tag.split(/,\s+/).map(&:squish)
end
end
View
17 app/views/manage/affiches/_fields.html.erb
@@ -4,10 +4,19 @@
<%= yield :additional_fields %>
-<%= link_to 'Добавить постер', '#', :class => 'add_poster', :id => 'poster_wrapper' %>
-<%= f.input :poster_url, :input_html => { :id => 'file_url' } %>
-<%= poster_image_tag_for resource, 290, 390 if resource.poster_url? %>
-<div class='poster_wrapper'></div>
+<div>
+ <%= link_to 'Добавить постер', '#', :class => 'choose_file', :id => 'poster_wrapper', :params => "vfs_path=#{resource.vfs_path}" %>
+ <%= f.input :poster_url, :input_html => { :id => 'poster_url' } %>
+ <%= poster_image_tag_for resource, 290, 390 if resource.poster_url? %>
+</div>
+
+<div>
+ <%= link_to 'Добавить изображение для главной страницы', '#', :class => 'choose_file', :id => 'image_wrapper', :params => "vfs_path=#{resource.vfs_path}" %>
+ <%= f.input :image_url, :input_html => { :id => 'image_url' } %>
+ <%= image_image_tag_for resource, 653, 363 if resource.image_url? %>
+</div>
+
+<%= f.hidden_field :vfs_path %>
<%= field_set_tag "<i class='icon-resize-full' style='margin: 5px 5px 0 0'></i>#{t('simple_form.fieldset.showings')}".html_safe do %>
<%= f.simple_fields_for :showings %>
View
15 app/views/manage/affiches/new.html.erb
@@ -1,8 +1,11 @@
+<h1>
+ Добавление мероприятия
+</h1>
+
<ul>
- <li><%= link_to 'Добавить кино', new_manage_movie_path %></li>
- <li><%= link_to 'Добавить концерт', new_manage_concert_path %></li>
- <li><%= link_to 'Добавить выставку', new_manage_exhibition_path %></li>
- <li><%= link_to 'Добавить спектакль', new_manage_spectacle_path %></li>
- <li><%= link_to 'Добавить вечеринку', new_manage_party_path %></li>
- <li><%= link_to 'Добавить спортивное мероприятие', new_manage_sports_event_path %></li>
+ <% Affiche.descendants.each do |type| %>
+ <% type_name = type.to_s.underscore %>
+ <% vfs_path = "/znaigorod/afiches/#{type_name.pluralize}/#{Time.now.strftime('%Y/%m/%d/%H-%M')}-#{SecureRandom.hex(4)}" %>
+ <li><%= link_to type.model_name.human, send("new_manage_#{type_name}_path", "#{type_name}[vfs_path]" => vfs_path) %></li>
+ <% end %>
</ul>
View
4 config/routes.rb
@@ -9,8 +9,8 @@
resources res, :except => :show
end
- [:concerts, :exhibitions, :movies, :parties, :spectacles, :sports_events].each do |res|
- resources res, :except => :show
+ Affiche.descendants.each do |type|
+ resources type.name.underscore.pluralize, :except => :show
end
root :to => 'organizations#index'
View
5 db/migrate/20120525034939_add_vfs_path_to_affiches.rb
@@ -0,0 +1,5 @@
+class AddVfsPathToAffiches < ActiveRecord::Migration
+ def change
+ add_column :affiches, :vfs_path, :string
+ end
+end
View
5 db/migrate/20120525050740_add_image_url_to_affiches.rb
@@ -0,0 +1,5 @@
+class AddImageUrlToAffiches < ActiveRecord::Migration
+ def change
+ add_column :affiches, :image_url, :string
+ end
+end
View
4 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120521095731) do
+ActiveRecord::Schema.define(:version => 20120525050740) do
create_table "addresses", :force => true do |t|
t.string "street"
@@ -35,6 +35,8 @@
t.text "trailer_code"
t.string "type"
t.text "tag"
+ t.string "vfs_path"
+ t.string "image_url"
end
create_table "halls", :force => true do |t|
View
2 lib/path_interpolator.rb
@@ -1,6 +1,6 @@
class PathInterpolator
# NOTE: может в будущем измениться
def self.path(request)
- "/affiches/#{Date.today.to_s}"
+ request.params['vfs_path']
end
end

No commit comments for this range

Something went wrong with that request. Please try again.