From 9140a5bb6e7ecc24e6b4e540308042e10165e604 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 9 Feb 2012 11:07:10 -0800 Subject: New File Adding new file functionality, awaiting UI to implement correct file path for templates to hook into mediator. --- js/io/system/coreioapi.js | 3 +++ js/io/system/fileio.js | 17 +++++++---------- js/mediators/io-mediator.js | 40 +++++++++++++++++++++++++--------------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index bdba5240..d9505cd6 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -92,6 +92,9 @@ exports.CoreIoApi = Montage.create(Component, { //TODO: Remove test //this.ninjaLibrary.copyLibToCloud('Users/kgq387/Desktop/Ninja Cloud/Disk', 'montage0.6.0'); //this.ninjaLibrary.deleteLibraries(); + window.hack = function (name, type) { + this.application.ninja.ioMediator.fileNew('Users/kgq387/Desktop/Ninja Cloud/Disk/'+name+'.'+type, '/js/io/templates/files/'+type+'.txt', function (status) {console.log(status)}); + }.bind(this); } }, //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 2c49e849..7bf4d41f 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -17,15 +17,13 @@ NOTES: //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // -var Montage = require("montage/core/core").Montage; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component; //////////////////////////////////////////////////////////////////////// //Exporting as File I/O -exports.FileIo = Montage.create(Object.prototype, { +exports.FileIo = Montage.create(Component, { //////////////////////////////////////////////////////////////////// //newFile Object (*required): {uri*, contents, contentType} - //Return codes - // 204: File exists | 400: File exists | 404: File does not exists - // 201: File succesfully created | 500: Unknown | undefined: Unknown newFile: { enumerable: true, value: function(file) { @@ -35,7 +33,7 @@ exports.FileIo = Montage.create(Object.prototype, { return null; } //Peforming check for file to exist - var check = this.application.ninja.coreIoApi.fileExists(file.uri), status, create; + var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create; //Upon successful check, handling results if (check.success) { //Handling status of check @@ -47,10 +45,7 @@ exports.FileIo = Montage.create(Object.prototype, { case 404: //File does not exists, ready to be created create = this.application.ninja.coreIoApi.createFile(file); - //Storing status to be returned (for UI handling) - if (create.success) { - status = check.status; - } + status = create.status; break; default: //Unknown Error @@ -61,6 +56,8 @@ exports.FileIo = Montage.create(Object.prototype, { } //Returning resulting code return status; + // 204: File exists | 400: File exists | 404: File does not exists + // 201: File succesfully created | 500: Unknown | undefined: Unknown } }, //////////////////////////////////////////////////////////////////// diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index b6d0e598..66fea8b3 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -14,10 +14,17 @@ var Montage = require("montage/core/core").Montage, // exports.IoMediator = Montage.create(Component, { //////////////////////////////////////////////////////////////////// + // + hasTemplate: { + enumerable: false, + value: false + }, + //////////////////////////////////////////////////////////////////// // deserializedFromTemplate: { enumerable: false, value: function () { + // } }, //////////////////////////////////////////////////////////////////// @@ -32,27 +39,30 @@ exports.IoMediator = Montage.create(Component, { enumerable: false, value: function (file, template, callback) { // - var xhr = new XMLHttpRequest(); + var xhr = new XMLHttpRequest(), result; xhr.open("GET", template, false); xhr.send(); if (xhr.readyState === 4) { // - console.log(this.fio.newFile({uri: file, contents: xhr.response})); + switch (this.fio.newFile({uri: file, contents: xhr.response})) { + case 201: + result = {status: 201, success: true, uri: file}; + break; + case 204: + result = {status: 204, success: false, uri: file}; + break; + case 400: + result = {status: 400, success: false, uri: file}; + break; + default: + result = {status: 500, success: false, uri: file}; + break; + } } else { - //Error + result = {status: 500, success: false, uri: file}; } - - - - - - - - //callback('win'); - /* -var returnObj = null; //like {"uri": "/gfdg/gdf/dfg.js", "success": true,...} - callback(returnObj); -*/ + // + if (callback) callback(result); } }, //////////////////////////////////////////////////////////////////// -- cgit v1.2.3