Skip to content

Commit 18e5dc3

Browse files
prepping for the publish today
1 parent 1a7e4ad commit 18e5dc3

File tree

4 files changed

+92
-80
lines changed

4 files changed

+92
-80
lines changed

packages/0.6.0/action-v0.6.0.js

+45-39
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ https://github.com/designfrontier/Action
319319
, modelMe: function(objectIn){
320320
//this is the module for creating a data model object
321321
var that = this
322-
, newModel = that.eventMe({})
322+
, newModel = that.compose(that.eventMe, that.ajaxMe)
323323
, attributes = {}
324324
, changes = [];
325325

@@ -424,43 +424,6 @@ https://github.com/designfrontier/Action
424424
}
425425
};
426426

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-
464427
newModel.save = function(){
465428
//TODO make this talk to a server with the URL
466429
//TODO make it only mark the saved changes clear
@@ -546,6 +509,49 @@ https://github.com/designfrontier/Action
546509
return newModel;
547510
}
548511

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(/^[23][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+
549555
, viewMe : function(objectIn){
550556
var that = this
551557
, newView = that.eventMe(objectIn);
@@ -678,7 +684,7 @@ https://github.com/designfrontier/Action
678684
});
679685
} else if (typeof arguments[i] === 'function') {
680686
//this is a function apply it
681-
arguments[i].apply(obj);
687+
arguments[i].call(obj, obj);
682688
}
683689
}
684690

0 commit comments

Comments
 (0)