lib/values/hvalue.rb in rsence-2.1.2 vs lib/values/hvalue.rb in rsence-2.1.3
- old
+ new
@@ -246,16 +246,15 @@
# @private Tell the client that the value changed.
def to_client( msg )
if @is_new_to_client
## Initialize a new client value
- init_str = "COMM.Values.create(#{@value_id.to_json},#{@data.to_json});"
- msg.reply_value( init_str )
+ msg.reply_value( :new, @value_id, @data )
@is_new_to_client = false
else
## Sets the client value
- msg.reply_value "HVM.s(#{@value_id.to_json},#{@data.to_json});"
+ msg.reply_value( :set, @value_id, @data )
end
end
# Destructor method. If msg is supplied, deletes the client representation too.
# @param [false, Message] A {Message} instance. When supplied, deletes the client representation.
@@ -268,144 +267,15 @@
## Store the object here
session_values.delete( @value_id )
if msg and not @is_new_to_client
- msg.reply_value("HVM.del(#{@value_id.to_json});")
+ msg.reply_value( :del, @value_id )
end
end
alias die die!
end
-
-
-=begin
- class UploadValue < HValue
-
- @state_responders = {
- :ready => [], # id == 0
- :started => [], # id == 1
- :process => [], # id == 2 ; also uses bind
- 3 => [], # id == 3
- 4 => [], # id == 4
- :error => [] # id < 0
- }
-
- @upload_state = 0
- @upload_key = ''
- @uploads = []
-
- # the data should contain both state and key in the value
- def from_client( msg, data )
-
- ## change the valid state, because the value was set by the client!
- @is_valid = data.include?(':::')
-
- # the state and key are separated by the ':::' delimiter string
- if @is_valid
-
- # split state and key using the delimiter
- (upload_state, upload_key) = data.split(':::')
-
- # the state is a number
- upload_state = upload_state.to_i
-
- @upload_state = upload_state
- @upload_key = upload_key
-
- # negative states are errors
- if upload_state < 0
- # "upload error: #{upload_state}"
- # (parse the error)
- unless @state_responders[:error].empty?
- @state_responders[:error].each do |plugin_name,method_name|
- msg.run( plugin_name,method_name,msg,self,upload_state )
- end
- end
-
- # the default state, 0 means the UI is ready to send an
- # upload and ticketserve is ready to receive it
- elsif upload_state == 0
- # "upload state: ready to upload."
- # (do nothing)
-
- unless @state_responders[:ready].empty?
- @state_responders[:ready].each do |plugin_name,method_name|
- msg.run( plugin_name,method_name,msg,self,upload_state )
- end
- end
-
- # this state means the upload's transfer is started and progressing
- elsif upload_state == 1
- # "upload state: upload started."
- # (show progress bar)
-
- unless @state_responders[:started].empty?
- @state_responders[:started].each do |plugin_name,method_name|
- msg.run( plugin_name,method_name,msg,self,upload_state )
- end
- end
-
- # this state means the upload's transfer is complete,
- # but the uploaded data hasn't been handled yet.
- elsif upload_state == 2
- # "upload state: waiting to process."
-
- uploads = msg.plugins[:ticketservices].get_uploads(upload_key,true)
- if uploads.size == 1
- uploaded_data = uploads[0]
-
- # only process changes, if different from the one already stored.
- if uploaded_data != @data
-
- @data = uploaded_data
-
- ## add the id to the values to be checked
- check_ids = msg.session[:values][:check]
- unless check_ids.include?( @value_id )
- check_ids.push( @value_id )
- end
-
- end
- msg.plugins[:ticketservices].del_uploads(upload_key,msg.ses_id)
- else
- # "upload, amount of uploads: #{uploads.size}"
- end
-
- #
- hvalue.set(msg,"3:::#{upload_key}")
-
- msg.console( "upload state: set to ack" )
-
- elsif upload_state == 3
- # "upload state: waiting for user ack."
- # (do nothing)
-
- msg.console( "upload state: waiting user ack" )
-
-
- elsif upload_state == 4
- # "upload state: user wants to upload again."
- # (set a new upload key, )
-
- msg.console( "upload state: ack, getting new key" )
-
-
- setup_upload( msg, hvalue )
-
-
- else
- # "upload unknown state: #{upload_state.inspect}"
- end
- end
- return true
- end
- def setup_upload(msg,hvalue,size_bytes=500*1024,accept_mime=/image\/(.*?)/,allow_multi=false)
- upload_key = msg.plugins[:ticketservices].upload_key(msg,hvalue.val_id,size_bytes,accept_mime,allow_multi)
- hvalue.set( msg, upload_key )
- end
- end
-=end
end