1 rio.File = { 2 open: function(path, options) { 3 var file; 4 var asynchronous = (options.asynchronous != undefined ? options.asynchronous : true); 5 new Ajax.Request(rio.url(path), { 6 asynchronous: asynchronous, 7 method: "get", 8 evalJSON: false, 9 evalJS: false, 10 onSuccess: function(response) { 11 file = response.responseText; 12 (options.onSuccess || Prototype.emptyFunction)(file); 13 }, 14 onFailure: function() { 15 if(options.onFailure) { 16 options.onFailure(); 17 } else { 18 rio.Application.fail("Failed loading file: " + path); 19 } 20 } 21 }); 22 if (!asynchronous) { return file; } 23 }, 24 25 json: function(path, options) { 26 new Ajax.Request(rio.url(path), { 27 asynchronous: true, 28 method: "get", 29 evalJSON: true, 30 evalJS: false, 31 onSuccess: function(response) { 32 options.onSuccess(response.responseJSON); 33 }, 34 onFailure: function() { 35 rio.Application.fail("Failed loading file: " + path); 36 } 37 }); 38 }, 39 40 execute: function(path, options) { 41 new Ajax.Request(rio.url(path), { 42 asynchronous: (options.asynchronous != undefined ? options.asynchronous : true), 43 method: "get", 44 evalJSON: false, 45 evalJS: true, 46 onSuccess: function(response) { 47 }, 48 onFailure: function() { 49 rio.Application.fail("Failed loading file: " + path); 50 } 51 }); 52 }, 53 54 write: function(path, content, options) { 55 new Ajax.Request("/rio/file", { 56 asynchronous: (options.asynchronous != undefined ? options.asynchronous : true), 57 method: "post", 58 evalJSON: false, 59 evalJS: false, 60 parameters: { 61 path: path, 62 content: content 63 }, 64 onSuccess: function(response) { 65 options.onSuccess(response); 66 }, 67 onFailure: function() { 68 rio.Application.fail("Failed writing file: " + path); 69 } 70 }); 71 } 72 }; 73