# -*- encoding : utf-8 -*-
class Admin::EditWatchersController < ApplicationController
	before_filter :auth_admin


	
	def create
		@edit_watcher = EditWatcher.new(params.require(:edit_watcher).permit!)
    
    @edit_watcher.admin = current_admin
	
		if @edit_watcher.save
      
			@edit_watchers_source = EditWatcher.where("admin_id != ?", current_admin.id).where(:element_type => @edit_watcher.element_type, :element_id => @edit_watcher.element_id,:key => @edit_watcher.key)
		  
      @edit_wacthers_to_destroy = EditWatcher.where("created_at < ?", (Time.now - 2)).destroy_all
    
      @edit_watchers_source = @edit_watchers_source.where("created_at >= ?", (Time.now - 2)).group(:admin_id).all
    
    else
			render :action => :new
		
		end
	end


  

end
