@@ -319,7 +319,7 @@ https://github.com/designfrontier/Action
319
319
, modelMe : function ( objectIn ) {
320
320
//this is the module for creating a data model object
321
321
var that = this
322
- , newModel = that . eventMe ( { } )
322
+ , newModel = that . compose ( that . eventMe , that . ajaxMe )
323
323
, attributes = { }
324
324
, changes = [ ] ;
325
325
@@ -424,43 +424,6 @@ https://github.com/designfrontier/Action
424
424
}
425
425
} ;
426
426
427
- newModel . ajaxGet = function ( setVariableName , successFunction ) {
428
- var that = this
429
- , requestUrl = that . url // + '?' + Date.now()
430
-
431
- , oReq = new XMLHttpRequest ( ) ;
432
-
433
- oReq . onload = function ( ) {
434
- var data = JSON . parse ( this . responseText ) ;
435
-
436
- //TODO: make the statuses more generic
437
- if ( this . status === 200 || this . status === 302 ) {
438
- that . emit ( that . get ( 'dataEvent' ) , data ) ;
439
-
440
- if ( typeof setVariableName === 'string' ) {
441
- that . set ( setVariableName , data ) ;
442
- } else {
443
- that . set ( data ) ;
444
- }
445
-
446
- if ( typeof successFunction === 'function' ) {
447
- successFunction . apply ( that , [ data ] ) ;
448
- }
449
- } else if ( this . status === 400 ) {
450
-
451
- } else if ( this . status === 500 ) {
452
- that . emit ( 'global:error' , new action . Error ( 'http' , 'Error in request' , that ) ) ;
453
- }
454
- } ;
455
-
456
- oReq . onerror = function ( xhr , errorType , error ) {
457
- that . emit ( 'global:error' , new action . Error ( 'http' , 'Error in request type: ' + errorType , that , error ) ) ;
458
- } ;
459
-
460
- oReq . open ( 'get' , requestUrl , true ) ;
461
- oReq . send ( ) ;
462
- } ;
463
-
464
427
newModel . save = function ( ) {
465
428
//TODO make this talk to a server with the URL
466
429
//TODO make it only mark the saved changes clear
@@ -546,6 +509,49 @@ https://github.com/designfrontier/Action
546
509
return newModel ;
547
510
}
548
511
512
+ , ajaxMe : function ( objectIn ) {
513
+ var obj = objectIn || { } ;
514
+
515
+ obj . ajaxGet = function ( setVariableName , successFunction , urlIn ) {
516
+ var that = this
517
+ , requestUrl = urlIn || that . url // + '?' + Date.now()
518
+
519
+ , oReq = new XMLHttpRequest ( ) ;
520
+
521
+ oReq . onload = function ( ) {
522
+ var data = JSON . parse ( this . responseText ) ;
523
+
524
+ if ( this . status . match ( / ^ [ 2 3 ] [ 0 - 9 ] [ 0 - 9 ] $ / ) ) {
525
+ that . emit ( that . get ( 'dataEvent' ) , data ) ;
526
+
527
+ if ( typeof setVariableName === 'string' ) {
528
+ that . set ( setVariableName , data ) ;
529
+ } else {
530
+ that . set ( data ) ;
531
+ }
532
+
533
+ if ( typeof successFunction === 'function' ) {
534
+ successFunction . apply ( that , [ data ] ) ;
535
+ }
536
+ } else if ( this . status . match ( / ^ [ 4 ] [ 0 - 9 ] [ 0 - 9 ] $ / ) ) {
537
+
538
+ } else if ( this . status . match ( / ^ [ 5 ] [ 0 - 9 ] [ 0 - 9 ] $ / ) ) {
539
+ that . emit ( 'global:error' , new action . Error ( 'http' , 'Error in request' , that ) ) ;
540
+ }
541
+ } ;
542
+
543
+ oReq . onerror = function ( xhr , errorType , error ) {
544
+ that . emit ( 'global:error' , new action . Error ( 'http' , 'Error in request type: ' + errorType , that , error ) ) ;
545
+ } ;
546
+
547
+ oReq . open ( 'get' , requestUrl , true ) ;
548
+ oReq . send ( ) ;
549
+ } ;
550
+
551
+
552
+ return obj ;
553
+ }
554
+
549
555
, viewMe : function ( objectIn ) {
550
556
var that = this
551
557
, newView = that . eventMe ( objectIn ) ;
@@ -678,7 +684,7 @@ https://github.com/designfrontier/Action
678
684
} ) ;
679
685
} else if ( typeof arguments [ i ] === 'function' ) {
680
686
//this is a function apply it
681
- arguments [ i ] . apply ( obj ) ;
687
+ arguments [ i ] . call ( obj , obj ) ;
682
688
}
683
689
}
684
690
0 commit comments