serverpath = Native `window.location.host + window.location.pathname`
@page_adress= Native `window.location.pathname`.split("/")[1]
# alert @page_adress
@edit_mode="move"
serverpath="ws://"+serverpath
@activeFlow=Browser::Socket.new serverpath do
on :open do
Element.find("body").append("
")
Element.find("body").append("")
end
on :message do |message_received|
message_received= JSON.parse(message_received.data)
# ------------------ read_page ici ----------------
Element.find("#page_content").append(message_received)
#------------------ a modifier pour mise en base -----------------#
require "user_app"
#------------------ a modifier pour mise en base -----------------#
end
on :close do
Element.find("body").html("Bye bye")
end
end
def montest
alert "mon test succeed !!!"
end
def set_default_page
Element.find("body").append("")
Element.find("#menubox").append("Edit
")
Element.find("#edittoggle").on :click do
# l'action "list_modules_number" recupere le nombre total de module et le stock dans un attr dans la div moduleutil
@activeFlow.send({:action => "list_modules_number", :pass => "pass"}.to_json);
def move_or_edit_fct
if @edit_mode=="move"
@edit_mode="edit"
# alert "edit"
remove_drag
elsif @edit_mode=="edit"
@edit_mode="move"
# alert "move"
make_it_draggable
end
end
edittoggle=Element.find(".editablecontent")
if edittoggle.has_class?("wysiwyg-editor")
if edittoggle.attr("contenteditable")=="true"
Element.find("#menus_container").remove
edittoggle.remove_attr("contenteditable")
remove_drag
elsif edittoggle.attr("contenteditable").nil?
create_default_objet
bind_save
bind_tools
make_it_draggable
edittoggle.attr("contenteditable", "true")
end
else
create_default_objet
bind_save
bind_tools
make_it_draggable
Native `editcontent()`
end
end
Native `$('#menubox').draggable()`
end
def create_default_objet
# Creation du container d'outil ici
Element.find("#menubox").append("")
# add the tools
Element.find("#menus_container").append("Save
")
Element.find("#menus_container").append("")
Element.find("#toolbox").append("Tools List
")
Element.find("#menus_container").append("")
Element.find("#modulebox").append("Modules
")
bind_modules_utils
end
set_default_page
def bindHref
Element.find("a").on :mousedown do |acontent|
@startime=gettime
end
Element.find("a").on :mouseup do |acontent|
# tester si l'editeur est ouvert plutot que la difference de temps
@endtime= gettime
totaltime=@endtime-@startime
editionstate= Element.find("#authentifier").css("display")
begin
if editionstate=="block"
end
rescue
editionstate="none"
end
pass=Element.find("#passhere").text
target =acontent.current_target.attr("href")
if editionstate=="block"
if totaltime >1000
Native `window.location.href = #{target}+'?pass='+#{pass}`
end
else
Native `window.location.href = #{target}+'?pass='+#{pass}`
end
end
end
def bind_create_module
Element.find("#module_creator").on :click do
number_of_modules=`$('#module_utils').attr('number_of_modules')`
id= "mon_module_nb_#{number_of_modules}"
classname= "editablecontent modules"
name= "les infos"
content=" module vide"
Element.find("#master_items").append("#{content}
")
Native `$('.modules').draggable()`
# On incremente temporarirement le nombre de module dans modules_utils
number_of_modules=number_of_modules.to_i+1
number_of_modules=number_of_modules.to_s
Element.find("#module_utils").attr("number_of_modules", number_of_modules)
end
end
def bind_modules_utils
Element.find("#module_utils").on :click do
elementexist= Element.find("#module_creator").attr :id
if elementexist.nil?
Element.find("#modulebox").append("")
Element.find("#modules_container").append("New
")
Element.find("#modules_container").append("list
")
Element.find("#modules_container").append("on page
")
Element.find("#modules_container").append("infos
")
bind_create_module
bind_modules_list
bind_modules_on_page
else
Element.find("#modules_container").remove
end
end
end
def bind_tools
Element.find("#tools").on :click do
elementexist= Element.find("#tool_handler").attr :id
if elementexist.nil?
Element.find("#toolbox").append("")
Element.find("#tools_container").append("")
Element.find("#tool_handler").append("mover
")
Element.find("#move_or_edit").on :click do
# alert "edit or move"
move_or_edit_fct
end
else
Element.find("#tools_container").remove
end
end
end
def bind_save
Element.find("#save_page").on :click do
editablecontent = Element.find(".modules")
list_of_modules_on_page=[]
editablecontent.each do |content|
item_id= content.id.to_sym
list_of_modules_on_page << item_id
module_content= Native `get_full_object(#{item_id})`
save_module ({item_id => module_content})
end
#--------- pour na pas sauvegarder en double les objets systemes créé en code --------#
temp_item=Element.find(".system_object")
`$( ".system_object").remove()`
#--------- pour na pas sauvegarder en double les objets systemes créé en code --------#
page_content= Element.find("#page_content")
item_id= @page_adress
save_list_of_modules_on_page ({item_id => list_of_modules_on_page})
item_to_save=page_content.html
save_page ({item_id => item_to_save})
#--------- pour na pas sauvegarder en double les objets systemes créé en code --------#
Element.find("#page_content").append(temp_item)
#--------- pour na pas sauvegarder en double les objets systemes créé en code --------#
end
end
def bind_modules_list
Element.find("#modules_list").on :click do
@activeFlow.send({:action => "read_modules_list", :pass => "pass"}.to_json);
Timeout.new 1000 do
Element.find(".module_available").on :click do |evt|
module_requested= evt.current_target.html
@activeFlow.send({:action => "get_module", :pagecontent => module_requested, :currentpage => @page_adress, :pass => "pass"}.to_json);
end
end
end
end
def bind_modules_on_page
Element.find("#modules_on_page").on :click do
# page_content= Element.find("#page_content")
# title= page_content.id.to_sym
if @page_adress.nil?
@page_adress=""
end
@activeFlow.send({:action => "read_modules_on_page", :currentpage => @page_adress, :pass => "pass"}.to_json);
end
end
def save_page (datas)
pass= Element.find('#passhere').text
key, value = datas.first
title=key
content= value
@activeFlow.send({:action => "save", :pagecontent => content, :currentpage => @page_adress, :pass => "pass"}.to_json);
end
def save_module (datas)
# pass= Element.find('#passhere').text
# alert "save module : #{datas}"
key, value = datas.first
title=key
content= value
# module_content=Element.find("##{title}")
@activeFlow.send({:action => "save_module", :pagecontent => content, :currentpage => title, :pass => "pass"}.to_json);
end
def save_list_of_modules_on_page (datas)
# alert "modules sur la page sont : #{datas}"
key, value = datas.first
title=key
content= value
@activeFlow.send({:action => "save_list_of_modules_on_page", :pagecontent => content, :currentpage => @page_adress, :pass => "pass"}.to_json);
end
def read_file (datas)
alert "ou ici"
pass= Element.find('#passhere').text
key, value = datas.first
title=key
title= value
@activeFlow.send({:action => "read", :currentpage => value, :pass => pass}.to_json);
end
def read_sensor (datas)
pass= Element.find('#passhere').text
key, value = datas.first
title= value
@activeFlow.send({:action => "readsensor", :currentpage => value, :pass => pass}.to_json);
end
%x{
$("a").click(function( event ) {
event.preventDefault();
});
}
class Timeout
def initialize(time=0, &block)
`setTimeout(function(){#{block.call}}, time)`
end
end
def make_it_draggable
# Native `$('#toolbox').draggable()`
Native `$('.modules').draggable()`
Native `$('.editablecontent').find("img").draggable()`
Native `$('.editablecontent').find("div").not(".system_object").draggable()`
# Native `$('.editablecontent').find("span").draggable()`
end
def remove_drag
make_it_draggable
# Native `$('#toolbox').draggable('destroy')`
Native `$('.modules').draggable('destroy')`
Native `$('.editablecontent').find('img').draggable('destroy')`
Native `$('.editablecontent').find('div').draggable('destroy')`
end