rsence 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.1.3
@@ -27,7 +27,8 @@ COMM.Transporter = HApplication.extend({
27
27
  **/
28
28
  constructor: function(){
29
29
  var _this = this;
30
- this.serverLostMessage = 'Server Connection Lost: Reconnecting...';
30
+ _this._detectNativeJSONSupport();
31
+ _this.serverLostMessage = 'Server Connection Lost: Reconnecting...';
31
32
  _this.label = 'Transporter';
32
33
  _this.url = false;
33
34
  _this.busy = false;
@@ -37,6 +38,17 @@ COMM.Transporter = HApplication.extend({
37
38
  _this._busyFlushTimeout = false;
38
39
  _this.base(1);
39
40
  },
41
+
42
+ _detectNativeJSONSupport: function(){
43
+ if(window['JSON']){
44
+ var
45
+ _JSON = window.JSON,
46
+ _fun = 'function';
47
+ if((typeof _JSON['parse'] === _fun) && (typeof _JSON['stringify'] === _fun)){
48
+ this.parseResponseArray = this._nativeParseResponseArray;
49
+ }
50
+ }
51
+ },
40
52
 
41
53
  /** Tries to (re)connect to the server as often as possible,
42
54
  * mandated essentially by the priority of its
@@ -64,6 +76,49 @@ COMM.Transporter = HApplication.extend({
64
76
  COMM.Values._encodeString(_this._clientEvalError):'';
65
77
  },
66
78
 
79
+ parseResponseArray: function( _responseText ){
80
+ var _arr = eval( _responseText );
81
+ return _arr;
82
+ },
83
+
84
+ _nativeParseResponseArray: function( _responseText ){
85
+ var _arr = JSON.parse( _responseText );
86
+ return _arr;
87
+ },
88
+
89
+ setValues: function( _values ){
90
+ if(!_values instanceof Object){
91
+ console.log("Invalid values block: ", _values );
92
+ return;
93
+ }
94
+ var
95
+ i = 0,
96
+ _valueManager = COMM.Values,
97
+ _itemtype,
98
+ _valueId,
99
+ _valueData;
100
+ if(_values['new'] instanceof Array){
101
+ for(i=0;i<_values['new'].length;i++){
102
+ _valueId = _values['new'][i][0];
103
+ _valueData = _values['new'][i][1];
104
+ _valueManager.create( _valueId, _valueData );
105
+ }
106
+ }
107
+ if(_values['set'] instanceof Array){
108
+ for(i=0;i<_values['set'].length;i++){
109
+ _valueId = _values['set'][i][0];
110
+ _valueData = _values['set'][i][1];
111
+ _valueManager.s( _valueId, _valueData );
112
+ }
113
+ }
114
+ if(_values['del'] instanceof Array){
115
+ for(i=0;i<_values['del'].length;i++){
116
+ _valueId = _values['del'][i];
117
+ _valueManager.del( _valueId );
118
+ }
119
+ }
120
+ },
121
+
67
122
  /** = Description
68
123
  * Handles synchronization responses.
69
124
  *
@@ -83,10 +138,11 @@ COMM.Transporter = HApplication.extend({
83
138
  _this.failure(resp);
84
139
  return;
85
140
  }
86
- var _responseArray = eval(resp.X.responseText),
87
- i = 1,
141
+ var _responseArray = _this.parseResponseArray(resp.X.responseText),
142
+ i = 2,
88
143
  _responseArrayLen = _responseArray.length,
89
144
  _sesKey = _responseArray[0],
145
+ _values = _responseArray[1],
90
146
  _session = COMM.Session,
91
147
  _queue = COMM.Queue;
92
148
  if(_sesKey === ''){
@@ -95,6 +151,7 @@ COMM.Transporter = HApplication.extend({
95
151
  else {
96
152
  _session.newKey(_sesKey);
97
153
  }
154
+ _this.setValues( _values );
98
155
  for(;i<_responseArrayLen;i++){
99
156
  try {
100
157
  _queue.pushEval( _responseArray[i] );
@@ -123,7 +180,7 @@ COMM.Transporter = HApplication.extend({
123
180
  failMessage: function(_title,_message){
124
181
  var _this = COMM.Transporter,
125
182
  _queue = COMM.Queue;
126
- console.log('failMessage?');
183
+ console.log('failMessage title:',_title,', message:',_message);
127
184
  _this.stop = true;
128
185
  _queue.push(function(){jsLoader.load('default_theme');});
129
186
  _queue.push(function(){jsLoader.load('controls');});
@@ -322,6 +322,11 @@ COMM.Values = HClass.extend({
322
322
  return _str;
323
323
  },
324
324
 
325
+ _nativeEncode: function(_obj){
326
+ return JSON.stringify( _obj );
327
+ },
328
+
329
+
325
330
  /** = Description
326
331
  * Decodes a JSON object. Decodes url-encoded strings contained.
327
332
  *
@@ -355,6 +360,29 @@ COMM.Values = HClass.extend({
355
360
  return _obj;
356
361
  },
357
362
 
363
+ _nativeDecode: function(_ibj){
364
+ var _obj, _type, _this = this;
365
+ if(_ibj !== null && _ibj !== undefined){
366
+ _type = _this.type(_ibj);
367
+ if(!_type){
368
+ return null;
369
+ }
370
+ switch(_type){
371
+ case 'b': _obj = _ibj; break;
372
+ case 'n': _obj = _ibj; break;
373
+ case 's': _obj = _this._decodeString(_ibj); break;
374
+ case 'd': _obj = _ibj; break;
375
+ case 'a': _obj = JSON.parse(_ibj); break;
376
+ case 'h': _obj = JSON.parse(_ibj); break;
377
+ default: _obj = null; break;
378
+ }
379
+ }
380
+ else {
381
+ return null;
382
+ }
383
+ return _obj;
384
+ },
385
+
358
386
  /** = Description
359
387
  * Makes a deep copy of the object.
360
388
  *
@@ -408,6 +436,24 @@ COMM.Values = HClass.extend({
408
436
  }
409
437
  },
410
438
 
439
+ _nativeClone: function( _obj ){
440
+ if(_obj === null){
441
+ return null;
442
+ }
443
+ else if (_obj === undefined){
444
+ console.log('Undefined object, supplementing with null.');
445
+ return null;
446
+ }
447
+ if( (_obj instanceof Array) || (_obj instanceof Object) ){
448
+ // conversion via encoding/decoding via JSON string.
449
+ return JSON.parse( JSON.stringify( _obj ) );
450
+ }
451
+ else {
452
+ // no conversion needed (numbers, strings, booleans etc..)
453
+ return _obj;
454
+ }
455
+ },
456
+
411
457
  /** = Description
412
458
  * Returns an URI-encoded string representation of all the changed values to
413
459
  * synchronize to the server.
@@ -431,9 +477,25 @@ COMM.Values = HClass.extend({
431
477
  _syncValues[_id] = _value;
432
478
  }
433
479
  return encodeURIComponent(_this.encode(_syncValues));
480
+ },
481
+
482
+ _detectNativeJSONSupport: function(){
483
+ if(window['JSON']){
484
+ var
485
+ _JSON = window.JSON,
486
+ _fun = 'function';
487
+ if((typeof _JSON['parse'] === _fun) && (typeof _JSON['stringify'] === _fun)){
488
+ // console.log('Has native JSON support. Re-routing encode, decode and clone methods of COMM.Values...');
489
+ this.clone = this._nativeClone;
490
+ this.encode = this._nativeEncode;
491
+ // this.decode = this._nativeDecode;
492
+ }
493
+ }
434
494
  }
435
495
  });
436
496
 
497
+ COMM.Values._detectNativeJSONSupport();
498
+
437
499
  // Backwards compatibility assignment for code that still
438
500
  // uses HVM as a reference of the Value Manager:
439
501
  HVM = COMM.Values;
@@ -24,7 +24,7 @@
24
24
  //var//RSence.Foundation
25
25
  COMM.JSONRenderer = HClass.extend({
26
26
 
27
- version: 0.7,
27
+ version: 0.8,
28
28
 
29
29
  /** = Description
30
30
  * Renders JSON structured data, see some of the demos for usage examples.
@@ -77,7 +77,10 @@ COMM.JSONRenderer = HClass.extend({
77
77
  for( _key in _definition ){
78
78
  if( _reserved.indexOf( _key ) === -1 ){
79
79
  _value = _definition[_key];
80
- _extension[_key] = this.extEval( _value );
80
+ if( typeof _value === 'string' ){
81
+ _value = this.extEval( _value );
82
+ }
83
+ _extension[_key] = _value;
81
84
  }
82
85
  }
83
86
  _scope[ _className ] = _extend.extend( _extension );
data/lib/session/msg.rb CHANGED
@@ -111,7 +111,11 @@ module RSence
111
111
  @options = options
112
112
 
113
113
  # Value response output.
114
- @value_buffer = []
114
+ @value_buffer = {
115
+ :new => [],
116
+ :set => [],
117
+ :del => []
118
+ }
115
119
 
116
120
  # The session key placeholder.
117
121
  @ses_key = false
@@ -238,21 +242,22 @@ module RSence
238
242
  if not @response_success
239
243
  @response.status = 200
240
244
  #@response.status = 503
241
-
245
+
242
246
  buffer = [
243
- "" # empty session key will stop the syncing
247
+ "", # empty session key will stop the syncing
248
+ {}, # no session values
244
249
  ] + @error_js
245
250
  else
246
251
  ## The response status should always be 200 (OK)
247
252
  @response.status = 200
248
-
249
- buffer = @value_buffer + @buffer
250
- if @ses_key
251
- buffer.unshift( @ses_key )
252
- end
253
-
253
+
254
+ buffer = [
255
+ @ses_key,
256
+ @value_buffer,
257
+ ] + @buffer
258
+
254
259
  end
255
-
260
+
256
261
  # flush the output
257
262
  if @do_gzip
258
263
  outp = GZString.new('')
@@ -262,13 +267,13 @@ module RSence
262
267
  else
263
268
  outp = buf_json(buffer)
264
269
  end
265
-
270
+
266
271
  @response['content-length'] = outp.size
267
272
  @response.body = outp
268
-
273
+
269
274
  @response_sent = true
270
275
  end
271
-
276
+
272
277
  # Sends data to the client, usually javascript, but is valid for any data that responds to #to_json
273
278
  # @param [String<js>, #to_json] data Javascript source or object that responds to #to_json
274
279
  # @param [Boolean] dont_squeeze When true, doesn't `squeeze` the contents (jsmin + jscompress)
@@ -280,9 +285,16 @@ module RSence
280
285
  end
281
286
 
282
287
  # @private For value manager; insert changed values BEFORE other js.
283
- def reply_value(data)
284
- puts data if @config[:trace]
285
- @value_buffer.push( data )
288
+ def reply_value( operation_type, value_id, data=nil )
289
+ if operation_type == :set
290
+ @value_buffer[:set].push( [ value_id, data ] )
291
+ elsif operation_type == :new
292
+ @value_buffer[:new].push( [ value_id, data ] )
293
+ elsif operation_type == :del
294
+ @value_buffer[:del].push( value_id )
295
+ else
296
+ throw "Invalid reply_value operation: operation_type: #{operation_type.inspect}, value_id: #{value_id.inspect}, data: #{data.inspect}"
297
+ end
286
298
  end
287
299
 
288
300
  # Sends data to the client's javascript console.
data/lib/values/hvalue.rb CHANGED
@@ -248,12 +248,11 @@ module RSence
248
248
  def to_client( msg )
249
249
  if @is_new_to_client
250
250
  ## Initialize a new client value
251
- init_str = "COMM.Values.create(#{@value_id.to_json},#{@data.to_json});"
252
- msg.reply_value( init_str )
251
+ msg.reply_value( :new, @value_id, @data )
253
252
  @is_new_to_client = false
254
253
  else
255
254
  ## Sets the client value
256
- msg.reply_value "HVM.s(#{@value_id.to_json},#{@data.to_json});"
255
+ msg.reply_value( :set, @value_id, @data )
257
256
  end
258
257
  end
259
258
 
@@ -270,142 +269,13 @@ module RSence
270
269
  session_values.delete( @value_id )
271
270
 
272
271
  if msg and not @is_new_to_client
273
- msg.reply_value("HVM.del(#{@value_id.to_json});")
272
+ msg.reply_value( :del, @value_id )
274
273
  end
275
274
  end
276
275
  alias die die!
277
276
 
278
277
  end
279
278
 
280
-
281
- =begin
282
- class UploadValue < HValue
283
-
284
- @state_responders = {
285
- :ready => [], # id == 0
286
- :started => [], # id == 1
287
- :process => [], # id == 2 ; also uses bind
288
- 3 => [], # id == 3
289
- 4 => [], # id == 4
290
- :error => [] # id < 0
291
- }
292
-
293
- @upload_state = 0
294
- @upload_key = ''
295
- @uploads = []
296
-
297
- # the data should contain both state and key in the value
298
- def from_client( msg, data )
299
-
300
- ## change the valid state, because the value was set by the client!
301
- @is_valid = data.include?(':::')
302
-
303
- # the state and key are separated by the ':::' delimiter string
304
- if @is_valid
305
-
306
- # split state and key using the delimiter
307
- (upload_state, upload_key) = data.split(':::')
308
-
309
- # the state is a number
310
- upload_state = upload_state.to_i
311
-
312
- @upload_state = upload_state
313
- @upload_key = upload_key
314
-
315
- # negative states are errors
316
- if upload_state < 0
317
- # "upload error: #{upload_state}"
318
- # (parse the error)
319
- unless @state_responders[:error].empty?
320
- @state_responders[:error].each do |plugin_name,method_name|
321
- msg.run( plugin_name,method_name,msg,self,upload_state )
322
- end
323
- end
324
-
325
- # the default state, 0 means the UI is ready to send an
326
- # upload and ticketserve is ready to receive it
327
- elsif upload_state == 0
328
- # "upload state: ready to upload."
329
- # (do nothing)
330
-
331
- unless @state_responders[:ready].empty?
332
- @state_responders[:ready].each do |plugin_name,method_name|
333
- msg.run( plugin_name,method_name,msg,self,upload_state )
334
- end
335
- end
336
-
337
- # this state means the upload's transfer is started and progressing
338
- elsif upload_state == 1
339
- # "upload state: upload started."
340
- # (show progress bar)
341
-
342
- unless @state_responders[:started].empty?
343
- @state_responders[:started].each do |plugin_name,method_name|
344
- msg.run( plugin_name,method_name,msg,self,upload_state )
345
- end
346
- end
347
-
348
- # this state means the upload's transfer is complete,
349
- # but the uploaded data hasn't been handled yet.
350
- elsif upload_state == 2
351
- # "upload state: waiting to process."
352
-
353
- uploads = msg.plugins[:ticketservices].get_uploads(upload_key,true)
354
- if uploads.size == 1
355
- uploaded_data = uploads[0]
356
-
357
- # only process changes, if different from the one already stored.
358
- if uploaded_data != @data
359
-
360
- @data = uploaded_data
361
-
362
- ## add the id to the values to be checked
363
- check_ids = msg.session[:values][:check]
364
- unless check_ids.include?( @value_id )
365
- check_ids.push( @value_id )
366
- end
367
-
368
- end
369
- msg.plugins[:ticketservices].del_uploads(upload_key,msg.ses_id)
370
- else
371
- # "upload, amount of uploads: #{uploads.size}"
372
- end
373
-
374
- #
375
- hvalue.set(msg,"3:::#{upload_key}")
376
-
377
- msg.console( "upload state: set to ack" )
378
-
379
- elsif upload_state == 3
380
- # "upload state: waiting for user ack."
381
- # (do nothing)
382
-
383
- msg.console( "upload state: waiting user ack" )
384
-
385
-
386
- elsif upload_state == 4
387
- # "upload state: user wants to upload again."
388
- # (set a new upload key, )
389
-
390
- msg.console( "upload state: ack, getting new key" )
391
-
392
-
393
- setup_upload( msg, hvalue )
394
-
395
-
396
- else
397
- # "upload unknown state: #{upload_state.inspect}"
398
- end
399
- end
400
- return true
401
- end
402
- def setup_upload(msg,hvalue,size_bytes=500*1024,accept_mime=/image\/(.*?)/,allow_multi=false)
403
- upload_key = msg.plugins[:ticketservices].upload_key(msg,hvalue.val_id,size_bytes,accept_mime,allow_multi)
404
- hvalue.set( msg, upload_key )
405
- end
406
- end
407
- =end
408
-
409
279
  end
410
280
 
411
281
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsence
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 2
10
- version: 2.1.2
9
+ - 3
10
+ version: 2.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Riassence Inc.
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-09 00:00:00 +02:00
18
+ date: 2010-12-12 00:00:00 +02:00
19
19
  default_executable: rsence
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency