From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- js/io/document/base-document.js | 0 js/io/document/document-controller.js | 166 ++++- js/io/document/html-document.js | 0 js/io/document/text-document.js | 15 +- js/io/system/config.xml | 6 - js/io/system/coreioapi.js | 819 +++++++++++++++++++++ js/io/system/fileio.js | 0 js/io/system/filesystem.js | 78 +- js/io/system/projectio.js | 0 js/io/system/shellapi.js | 806 -------------------- js/io/templates/files/template.css | 0 js/io/templates/files/template.html | 0 js/io/templates/files/template.js | 0 js/io/templates/files/template.json | 0 js/io/templates/files/template.php | 0 js/io/templates/files/template.pl | 0 js/io/templates/files/template.py | 0 js/io/templates/files/template.rb | 0 js/io/templates/files/template.xml | 0 js/io/workflow/new-project-manager.js | 0 .../new-file-location.reel/new-file-location.css | 23 +- .../new-file-location.reel/new-file-location.html | 61 +- .../new-file-location.reel/new-file-location.js | 30 +- .../new-file-options-navigator.css | 107 ++- .../new-file-options-navigator.html | 45 +- .../new-file-options-navigator.js | 375 ++++++++-- .../newFileDialog/new-file-workflow-controller.js | 75 +- .../newFileDialog/new-file-workflow-model.js | 39 +- js/io/workflow/newProjectNavigator.js | 0 .../newProjectNavigator.css | 0 .../newProjectNavigator.html | 0 .../save-as-dialog.reel/save-as-dialog.css | 60 ++ .../save-as-dialog.reel/save-as-dialog.html | 84 +++ .../workflow/save-as-dialog.reel/save-as-dialog.js | 126 ++++ 34 files changed, 1898 insertions(+), 1017 deletions(-) mode change 100644 => 100755 js/io/document/base-document.js mode change 100644 => 100755 js/io/document/document-controller.js mode change 100644 => 100755 js/io/document/html-document.js mode change 100644 => 100755 js/io/document/text-document.js delete mode 100644 js/io/system/config.xml create mode 100755 js/io/system/coreioapi.js mode change 100644 => 100755 js/io/system/fileio.js mode change 100644 => 100755 js/io/system/filesystem.js mode change 100644 => 100755 js/io/system/projectio.js delete mode 100644 js/io/system/shellapi.js create mode 100755 js/io/templates/files/template.css create mode 100755 js/io/templates/files/template.html create mode 100755 js/io/templates/files/template.js create mode 100755 js/io/templates/files/template.json create mode 100755 js/io/templates/files/template.php create mode 100755 js/io/templates/files/template.pl create mode 100755 js/io/templates/files/template.py create mode 100755 js/io/templates/files/template.rb create mode 100755 js/io/templates/files/template.xml mode change 100644 => 100755 js/io/workflow/new-project-manager.js mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-location.reel/new-file-location.css mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-location.reel/new-file-location.html mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-location.reel/new-file-location.js mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.css mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.html mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-options-navigator.reel/new-file-options-navigator.js mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-workflow-controller.js mode change 100644 => 100755 js/io/workflow/newFileDialog/new-file-workflow-model.js mode change 100644 => 100755 js/io/workflow/newProjectNavigator.js mode change 100644 => 100755 js/io/workflow/newProjectNavigator.reel/newProjectNavigator.css mode change 100644 => 100755 js/io/workflow/newProjectNavigator.reel/newProjectNavigator.html create mode 100755 js/io/workflow/save-as-dialog.reel/save-as-dialog.css create mode 100755 js/io/workflow/save-as-dialog.reel/save-as-dialog.html create mode 100755 js/io/workflow/save-as-dialog.reel/save-as-dialog.js (limited to 'js/io') diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js old mode 100644 new mode 100755 diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js old mode 100644 new mode 100755 index 99177de0..6f363bc7 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -12,26 +12,35 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot @requires js/document/text-document */ -// TODO : Fix deps from Montage V4 Archi - var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, - Uuid = require("montage/core/uuid").Uuid; + Uuid = require("montage/core/uuid").Uuid, + fileSystem = require("js/io/system/filesystem").FileSystem; var HTMLDocument = require("js/io/document/html-document").HTMLDocument; var TextDocument = require("js/io/document/text-document").TextDocument; var DocumentController = exports.DocumentController = Montage.create(Component, { - hasTemplate: { value: false }, + hasTemplate: { + value: false + }, + + _documents: { + value: [] + }, - _documents: { value: [] }, - _documentsHash: { value: {} }, _activeDocument: { value: null }, _iframeCounter: { value: 1, enumerable: false }, _iframeHolder: { value: null, enumerable: false }, _textHolder: { value: null, enumerable: false }, _codeMirrorCounter: {value: 1, enumerable: false}, + tmpSourceForTesting: { + value: "function CodeMirror(place, givenOptions) {" + + "// Determine effective options based on given values and defaults." + + "var options = {}, defaults = CodeMirror.defaults; }" + }, + _codeEditor: { value: { "editor": { @@ -50,33 +59,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component, return this._activeDocument; }, set: function(doc) { - if(this._activeDocument) { - if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { - // TODO selection should use the document own selectionModel - //this._activeDocument.selectionModel = selectionManagerModule.selectionManager._selectedItems; - } - - this._activeDocument.isActive = false; - } + if(this._activeDocument) this._activeDocument.isActive = false; - if(this._documents.indexOf(doc) === -1) { - //this._documentsHash[doc.uuid] = this._documents.push(doc) - 1; - this._documents.push(doc); - } + if(this._documents.indexOf(doc) === -1) this._documents.push(doc); this._activeDocument = doc; this._activeDocument.isActive = true; - if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { - // TODO selection should use the document own selectionModel - //selectionManagerModule.selectionManager._selectedItems = this._activeDocument.selectionModel; - } } }, deserializedFromTemplate: { value: function() { this.eventManager.addEventListener("appLoaded", this, false); + + this.eventManager.addEventListener("executeFileOpen", this, false); } }, @@ -86,28 +83,126 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + handleExecuteFileOpen: { + value: function(event) { + var pickerSettings = event._event.settings || {}; + pickerSettings.callback = this.openFileWithURI; + pickerSettings.callbackScope = this; + this.application.ninja.filePickerController.showFilePicker(pickerSettings); + + //this.openDocument({"type": "js", "source": this.tmpSourceForTesting}); + } + }, + + openFileWithURI: { + value: function(uriArrayObj) { + var uri = "", fileContent = "", response=null; + if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ + uri = uriArrayObj.uri[0]; + } + console.log("URI is: ", uri); + + // Get file from Jose Code with a callback to here + if(!!uri){ + response = fileSystem.shellApiHandler.openFile({"uri":uri}); + if((response.success === true) && ((response.status === 200) || (response.status === 304))){ + fileContent = response.content; + } + + console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); + this.openDocument({"type": "js", "name": "tmp.js", "source": fileContent}); + } + + } + }, + + openProjectWithURI: { + value: function(uri) { + console.log("URI is: ", uri); + + // Get project from Jose Code with a callback to here + } + }, + /** Open a Document **/ openDocument: { value: function(doc) { - var d; + var newDoc; if(!doc) return false; - try { + // try { if (doc.type === 'html' || doc.type === 'htm') { - d = Montage.create(HTMLDocument); - d.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); + newDoc = Montage.create(HTMLDocument); + newDoc.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); } else { - d = Montage.create(TextDocument); - d.initialize(doc, Uuid.generate(), this._createTextAreaElement(), this._onOpenTextDocument); + newDoc = Montage.create(TextDocument, { + "source": { value: doc.source } + }); + newDoc.initialize(doc, Uuid.generate(), this._createTextAreaElement()); + + // Tmp this will be filled with the real content + newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; + + this.textDocumentOpened(newDoc); + } - } catch (err) { - console.log("Could not open Document ", err); - } + // } catch (err) { + // console.log("Could not open Document ", err); + // } } }, + // Document has been loaded into the Iframe. Dispatch the event. + // Event Detail: Contains the current ActiveDocument + _onOpenDocument: { + value: function(doc){ + + DocumentController.activeDocument = doc; + + NJevent("onOpenDocument", doc); + + } + }, + + textDocumentOpened: { + value: function(doc) { + + this.activeDocument = doc; + + this.application.ninja.stage.stageView.createTextView(doc); + + /* + DocumentManager._hideCurrentDocument(); + stageManagerModule.stageManager._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe + DocumentManager.activeDocument = doc; + + var type; + + switch(doc.documentType) { + case "css" : + type = "css"; + break; + case "js" : + type = "javascript"; + break; + } + + DocumentManager._codeEditor.editor = CodeMirror.fromTextArea(doc.textArea, { + lineNumbers: true, + mode: type, + onCursorActivity: function() { + DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.hline, null); + DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.editor.getCursor().line, "activeline"); + } + }); + DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(0, "activeline"); + */ + + } + }, + closeDocument: { value: function(id) { var doc = this._findDocumentByUUID(id); @@ -168,6 +263,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + // Document has been loaded into the Iframe. Dispatch the event. // Event Detail: Contains the current ActiveDocument _onOpenDocument: { @@ -185,6 +281,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + _onOpenTextDocument: { value: function(doc) { DocumentManager._hideCurrentDocument(); @@ -306,7 +403,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - _createTextAreaElement: { + /** + * Creates a text area which will contain the content of the opened text document. + */ +_createTextAreaElement: { value: function() { var codeMirrorDiv = document.createElement("div"); codeMirrorDiv.id = "codeMirror_" + (this._codeMirrorCounter++); @@ -323,4 +423,4 @@ var DocumentController = exports.DocumentController = Montage.create(Component, return codeMirrorDiv; } } -}); +}); \ No newline at end of file diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js old mode 100644 new mode 100755 diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js old mode 100644 new mode 100755 index 3506891a..599d311c --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -17,16 +17,8 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base } }, - _textArea: { value: null, enumerable: false }, - - // Temporary Save the source _source: { value: null, enumerable: false}, - textArea: { - get: function() { return this._textArea;}, - set: function(value) { this._textArea = value; } - }, - source: { get: function() { return this._source;}, set: function(value) { this._source = value;} @@ -53,10 +45,11 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base // PUBLIC METHODS initialize: { value: function(doc, uuid, textArea, callback) { - this.init(doc.name, doc.uri, doc.type, textArea, uuid, callback); - this.textArea = textArea.firstChild; + this.init(doc.name, doc.uri, doc.type, textArea, uuid); + this.currentView = "code"; - this._loadContent(); + this.textArea = textArea; +// this._loadContent(); } }, diff --git a/js/io/system/config.xml b/js/io/system/config.xml deleted file mode 100644 index 4660d647..00000000 --- a/js/io/system/config.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js new file mode 100755 index 00000000..c920d8cd --- /dev/null +++ b/js/io/system/coreioapi.js @@ -0,0 +1,819 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +/* ///////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +NOTES: +These methods should only be access through the file and project IO classes. +//////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// */ +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component; +//////////////////////////////////////////////////////////////////////// +//Exporting as Project I/O +exports.CoreIoApi = Montage.create(Component, { + //////////////////////////////////////////////////////////////////// + // private property containing the file service URL to use for all file IO calls + _fileServiceURL: { + enumerable: false, + value: "http://localhost:16380/file" + }, + //////////////////////////////////////////////////////////////////// + // private property containing the directory service URL to use for all file IO calls + _directoryServiceURL: { + enumerable: false, + value: "http://localhost:16380/directory" + }, + //////////////////////////////////////////////////////////////////// + // private helper to parse URIs and append them to the service URL + _prepareServiceURL: { + enumerable: false, + value: function(serviceURL, path) { + var urlOut = path.replace(/\\/g,"/"); + urlOut = urlOut.replace(/:/g,""); + urlOut = encodeURI(urlOut); + //add leading / if not already there + if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ + urlOut = "/" + urlOut; + } + //remove extra / at the end + if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ + urlOut = urlOut.substring(0, (urlOut.length - 1)); + } + + return serviceURL + urlOut; + } + }, + //////////////////////////////////////////////////////////////////// + // Checks for the existence of a file + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the file exists + // 404 - the file does not exist + // 500 - unknown server error occurred + fileExists: { + enumerable: false, + value: function(file) { + // + var retValue = { success:null, status:null }; + // + if(file && file.uri && file.uri.length) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("GET", serviceURL, false); + xhr.setRequestHeader("check-existence-only", "true"); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Creates a new file at the specified path + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" + // it can optionally contain the following properties + // contentType: string with the content type i.e. "text/plain". "text/plain" is assumed if this property is not specified + // contents: string containing the file contents. These contents will be saved to the new file. + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 201 - the file was created and contents were saved if they were passed + // 400 - the file already exists and could not be created + // 500 - unknown server error occurred + createFile: { + enumerable: false, + value: function(file) { + var retValue = { success:null, status:null }; + if(file && file.uri && file.uri.length) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("POST", serviceURL, false); + if(file.contentType && file.contentType.length) + xhr.setRequestHeader("Content-Type", file.contentType); + else + xhr.setRequestHeader("Content-Type", "text/plain"); + + if(file.contents && file.contents.length) + xhr.send(file.contents); + else + xhr.send(); + + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Save contents into an existing file at the specified path + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" + // it can optionally contain the following properties + // contentType: string with the content type i.e. "text/plain". "text/plain" is assumed if this property is not specified + // contents: string containing the file contents. These contents will be saved to the new file. + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the file was saved + // 404 - the file specified does not exist + // 500 - unknown server error occurred + updateFile: { + enumerable: false, + value: function(file) { + var retValue = { success:null, status:null }; + if(file && file.uri && file.uri.length && file.contents && file.contents.length) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("PUT", serviceURL, false); + if(file.contentType && file.contentType.length) + xhr.setRequestHeader("Content-Type", file.contentType); + else + xhr.setRequestHeader("Content-Type", "text/plain"); + + xhr.send(file.contents); + + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Copies a file from one location to another + // Parameters: + // the file parameter must contain the following properties + // sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar.html" + // destUri: string containing the full path/URI to copy to + // it can optionally contain the following properties + // overwriteDestination: bool indicating whether it is okay to overwrite the file specified at destUri if it already exists + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the file was copied + // 404 - the file specified in sourceUri does not exist + // 500 - unknown server error occurred + copyFile: { + enumerable: false, + value: function(file) { + var retValue = { success:null, status:null }; + if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.destUri), + xhr = new XMLHttpRequest(); + // + xhr.open("PUT", serviceURL, false); + xhr.setRequestHeader("sourceURI", file.sourceUri); + // + if(file.overwriteDestination && file.overwriteDestination === true) { + xhr.setRequestHeader("overwrite-destination", "true"); + } + // + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Moves a file from one location to another + // Parameters: + // the file parameter must contain the following properties + // sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar.html" + // destUri: string containing the full path/URI to copy to + // it can optionally contain the following properties + // overwriteDestination: bool indicating whether it is okay to overwrite the file specified at destUri if it already exists + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the file was moved + // 404 - the file specified in sourceUri does not exist + // 500 - unknown server error occurred + moveFile: { + enumerable: false, + value: function(file) { + var retValue = { success:null, status:null }; + if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.destUri), + xhr = new XMLHttpRequest(); + // + xhr.open("PUT", serviceURL, false); + xhr.setRequestHeader("sourceURI", file.sourceUri); + xhr.setRequestHeader("delete-source", "true"); + // + if(file.overwriteDestination && file.overwriteDestination === true) { + xhr.setRequestHeader("overwrite-destination", "true"); + } + // + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Deletes an existing file + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the file was deleted + // 404 - the file does not exist + // 500 - unknown server error occurred + deleteFile: { + enumerable: false, + value: function(file) { + var retValue = { success:null, status:null }; + if(file && file.uri && file.uri.length) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("DELETE", serviceURL, false); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Reads an existing file + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // content: string containing the file contents + // status: int indicating the request HTTP status code + // 200 - the file was read and its contents were returned + // 404 - the file does not exist + // 500 - unknown server error occurred + openFile: { + enumerable: false, + value: function(file) { + // + var retValue = { success:null, content:null, status:null}; + // + if(file && file.uri && file.uri.length) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("GET", serviceURL, false); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + if(xhr.status == 200) { + retValue.content = xhr.responseText; + } + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Create a new directory/folder + // Parameters: + // the dir parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/dir/subdir" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 201 - the directory was created + // 400 - the directory was unable to be created + // 500 - unknown server error occurred + createDirectory: { + enumerable: false, + value: function(dir) { + var retValue = { success:null, status:null }; + if(dir && dir.uri && dir.uri.length) { + try { + var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("POST", serviceURL, false); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Delete a directory/folder + // Parameters: + // the dir parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/dir/subdir" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the directory was deleted + // 404 - the directory does not exist + // 500 - unknown server error occurred + deleteDirectory: { + enumerable: false, + value: function(dir) { + var retValue = { success:null, status:null }; + if(dir && dir.uri && dir.uri.length) { + try { + var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("DELETE", serviceURL, false); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // List the contents of a directory/folder + // Parameters: + // the dir parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/dir/subdir" + // recursive: boolean true to list contents of all subdirectories as well. if this is not specified "false" is the default. + // returnType: string "all", "files", "directories". Specifies the types to return. if this is not specified, the default is "all" + // fileFilters: string containing the file extensions to include in the return listing. This list is semi-colon separated. i.e. "xml;html" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // content: string containing the JSON structure of the file contents + // status: int indicating the request HTTP status code + // 200 - the directory was read and the content JSON string was returned in dir.content + // 404 - the directory does not exist + // 500 - unknown server error occurred + getDirectoryContents: { + enumerable: false, + value: function(dir) { + var retValue = { success:null, content:null, status:null }; + if(!!dir && (typeof dir.uri !== "undefined") && (dir.uri !== null) ) { + try { + var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("GET", serviceURL, false); + // + if(dir.recursive) { + xhr.setRequestHeader("recursive", dir.recursive.toString()); + } + + // + if (dir.fileFilters) { + xhr.setRequestHeader("file-filters", dir.fileFilters.toString()); + } + // + + // + if(dir.returnType) { + xhr.setRequestHeader("return-type", dir.returnType.toString()); + } + // + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + if(xhr.status == 200) { + retValue.content = xhr.responseText; + } + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Check if a directory/folder exists + // Parameters: + // the dir parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/dir/subdir" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the directory exists + // 404 - the directory does not exist + // 500 - unknown server error occurred + directoryExists: { + enumerable: false, + value: function(dir) { + var retValue = { success:null, content:null, status:null }; + if(dir && dir.uri && dir.uri.length) { + try { + var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri), + xhr = new XMLHttpRequest(); + // + xhr.open("GET", serviceURL, false); + xhr.setRequestHeader("check-existence-only", "true"); + // + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // copies an existing directory/folder to a new location + // Parameters: + // the dir parameter must contain the following properties + // sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar" + // destUri: string containing the full path/URI to copy to + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the operation succeeded + // 400 - the operation could not be performed because the destUri existed + // 404 - the source directory does not exist + // 500 - unknown server error occurred + copyDirectory: { + enumerable: false, + value: function(dir) { + return this._copyMoveDirHelper(dir.sourceUri, dir.destUri, "copy"); + } + }, + //////////////////////////////////////////////////////////////////// + // Moves an existing directory/folder to a new location + // Parameters: + // the dir parameter must contain the following properties + // sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar" + // destUri: string containing the full path/URI to move to + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the operation succeeded + // 400 - the operation could not be performed because the destUri existed + // 404 - the source directory does not exist + // 500 - unknown server error occurred + moveDirectory: { + enumerable: false, + value: function(dir) { + return this._copyMoveDirHelper(dir.sourceUri, dir.destUri, "move"); + } + }, + //////////////////////////////////////////////////////////////////// + // Moves an existing directory/folder to a new location + // Parameters: + // the dir parameter must contain the following properties + // sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar" + // newDirectoryName: string containing the new name of the directory i.e. "bar2" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - the operation succeeded + // 400 - the operation could not be performed because the destUri existed + // 404 - the source directory does not exist + // 500 - unknown server error occurred + renameDirectory: { + enumerable: false, + value: function(dir) { + return this._copyMoveDirHelper(dir.sourceUri, dir.sourceUri + "/" + dir.newDirectoryName, "move"); + } + }, + //////////////////////////////////////////////////////////////////// + //Helper that is used by copyDirectory, moveDirectory, renameDirectory + _copyMoveDirHelper: { + enumerable: false, + value: function(sourceDir, destDir, operation) { + var retValue = {}; + if(sourceDir && sourceDir.length && destDir && destDir.length && operation && operation.length) { + try { + var serviceURL = this._prepareServiceURL(this._directoryServiceURL, destDir), + xhr = new XMLHttpRequest(); + // + xhr.open("PUT", serviceURL, false); + xhr.setRequestHeader("sourceURI", sourceDir); + xhr.setRequestHeader("operation", operation); + // + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// + // Checks if the file has been modified since it was last queried + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" + // recursive: boolean true to check the modified date of all subdirectories as well. if this is not specified "false" is the default. + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 200 - the file has been modified + // 304 - the file has not been modified + // 404 - the file does not exist + // 500 - unknown server error occurred + + isFileModified:{ + enumerable:true, + writable:false, + value:function(file, lastQueriedTimestamp){ + var retValue = { success:null, status:null }; + if(file && file.uri && (typeof lastQueriedTimestamp !== "undefined")) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), + xhr = new XMLHttpRequest(); + xhr.open("GET", serviceURL, false); + xhr.setRequestHeader("if-modified-since", lastQueriedTimestamp); + xhr.send(); + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + return retValue; + } + }, + + //////////////////////////////////////////////////////////////////// + // Checks if the directory content has been modified since it was last queried + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full directory path/URI i.e. "c:/foo/bar.html" + // recursive: boolean true to check the modified date of all subdirectories as well. if this is not specified "false" is the default. + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 200 - the file has been modified + // 304 - the file has not been modified + // 404 - the file does not exist + // 500 - unknown server error occurred + + isDirectoryModified:{ + enumerable:true, + writable:false, + value:function(file, lastQueriedTimestamp){ + var retValue = { success:null, status:null }; + if(file && file.uri && (typeof lastQueriedTimestamp !== "undefined")) { + try { + var serviceURL = this._prepareServiceURL(this._directoryServiceURL, file.uri), + xhr = new XMLHttpRequest(); + xhr.open("GET", serviceURL, false); + xhr.setRequestHeader("if-modified-since", lastQueriedTimestamp); + xhr.send(); + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + return retValue; + } + }, + + //////////////////////////////////////////////////////////////////// + // Checks if the file is writable + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - The file exists and response body has writable flag + // 404 - the file does not exist + // 500 - unknown server error occurred + //TODO:to be finalized + isFileWritable:{ + enumerable:true, + writable:false, + value:function(file){ + var retValue = { success:null, status:null }; + if(file && file.uri) { + try { + var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), + xhr = new XMLHttpRequest(); + xhr.open("GET", serviceURL, false); + xhr.setRequestHeader("get-attributes", "true"); + xhr.send(); + if (xhr.readyState === 4) { + retValue.status = xhr.status; + if(xhr.status == 200) { + retValue.content = xhr.responseText; + } + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + return retValue; + } + }, + + //////////////////////////////////////////////////////////////////// + // Checks if the directory is writable + // Parameters: + // the file parameter must contain the following properties + // uri: string value containing the full directory path/URI i.e. "c:/foo" + // + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // status: int indicating the request HTTP status code + // 204 - The file exists and response body has writable flag + // 404 - the file does not exist + // 500 - unknown server error occurred + //TODO:to be finalized + isDirectoryWritable:{ + enumerable:true, + writable:false, + value:function(file){ + var retValue = { success:null, status:null }; + if(file && file.uri) { + try { + var serviceURL = this._prepareServiceURL(this._directoryServiceURL, file.uri), + xhr = new XMLHttpRequest(); + xhr.open("GET", serviceURL, false); + xhr.setRequestHeader("get-attributes", "true"); + xhr.send(); + if (xhr.readyState === 4) { + retValue.status = xhr.status; + if(xhr.status == 200) { + retValue.content = xhr.responseText; + } + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + return retValue; + } + } + + + +}); +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js old mode 100644 new mode 100755 diff --git a/js/io/system/filesystem.js b/js/io/system/filesystem.js old mode 100644 new mode 100755 index 54c16a05..cd158812 --- a/js/io/system/filesystem.js +++ b/js/io/system/filesystem.js @@ -4,31 +4,23 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var FileIo = require("js/io/system/fileio").FileIo, - ProjectIo = require("js/io/system/projectio").ProjectIo, - ShellApi = require("js/io/system/shellapi").ShellApi, - ComponentsPanelBase = require("js/panels/Components/ComponentsPanelBase.reel").ComponentsPanelBase; +//////////////////////////////////////////////////////////////////////// +// +var Montage = require("montage/core/core").Montage, + FileIo = require("js/io/system/fileio").FileIo, + ProjectIo = require("js/io/system/projectio").ProjectIo, + CoreIoApi = require("js/io/system/coreioapi").CoreIoApi; //////////////////////////////////////////////////////////////////////// //Exporting as File System -exports.FileSystem = (require("montage/core/core").Montage).create(Object.prototype, { +exports.FileSystem = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// // - init: { - enumerable: false, - value: function () { - //Called by NinjaMain - - - - //Calling Shell API to initialize - ShellApi.init(); - } - }, + shellApiHandler :{ enumerable:true, writable:false, - value:ShellApi + value:CoreIoApi }, @@ -78,8 +70,8 @@ exports.FileSystem = (require("montage/core/core").Montage).create(Object.protot //documentManagerModule.DocumentManager.openDocument({"type": "html"}); } else { // - var file = {uri: ShellApi.openShellDialog({type: 'file', action: 'new'})}, type; - var check = ShellApi.fileExists(file); + var file = {uri: CoreIoApi.openShellDialog({type: 'file', action: 'new'})}, type; + var check = CoreIoApi.fileExists(file); @@ -117,13 +109,13 @@ exports.FileSystem = (require("montage/core/core").Montage).create(Object.protot //TODO: Improve logic //Checking for file to exist in files template folder - var templateCheck = ShellApi.fileExists({uri: window.NativeShellApp.GetKnownFolder('appsource')+'\\document-templates\\files\\template.'+type}), content; + var templateCheck = CoreIoApi.fileExists({uri: window.NativeShellApp.GetKnownFolder('appsource')+'\\document-templates\\files\\template.'+type}), content; // if (templateCheck.success) { switch (check.status) { case 204: //Template exists, so opening and getting contents to be used when creating file - content = ShellApi.openFile({uri: 'template.'+type}); + content = CoreIoApi.openFile({uri: 'template.'+type}); if (content.content) { file.content = content.content; } else { @@ -169,7 +161,7 @@ switch (type.toLowerCase()) { - var create = ShellApi.createFile(file); + var create = CoreIoApi.createFile(file); if (create.success) { switch (create.status) { case 201: @@ -239,8 +231,8 @@ switch (type.toLowerCase()) { //documentManagerModule.DocumentManager.openDocument({"type": "html"}); } else { // - var directory = {uri: ShellApi.openShellDialog({type: 'directory', action: 'new'})}; - var check = ShellApi.directoryExists(directory); + var directory = {uri: CoreIoApi.openShellDialog({type: 'directory', action: 'new'})}; + var check = CoreIoApi.directoryExists(directory); // if (check.success) { switch (check.status) { @@ -249,7 +241,7 @@ switch (type.toLowerCase()) { break; case 404: //Directory does not exists, ready to be created - var create = ShellApi.createDirectory(directory); + var create = CoreIoApi.createDirectory(directory); if (create.success) { switch (create.status) { case 201: @@ -294,7 +286,7 @@ switch (type.toLowerCase()) { enumerable: false, value: function (file) { //Checking for file to exist - var check = ShellApi.fileExists(file), createdFile = null; + var check = CoreIoApi.fileExists(file), createdFile = null; // if (check.success) { switch (check.status) { @@ -303,7 +295,7 @@ switch (type.toLowerCase()) { break; case 404: //File does not exists, ready to be created - var create = ShellApi.createFile(file); + var create = CoreIoApi.createFile(file); if (create.success) { switch (create.status) { case 201: @@ -357,7 +349,7 @@ switch (type.toLowerCase()) { //TODO: Add cloud integration } else { //Getting file URI from native prompt - uri = ShellApi.openShellDialog({type: 'file', action: 'open'}); + uri = CoreIoApi.openShellDialog({type: 'file', action: 'open'}); } } //Checking for a valid URI @@ -378,7 +370,7 @@ switch (type.toLowerCase()) { //Opening file via shell function shellOpenFile (f) { //Getting string from file - var doc = ShellApi.openFile({uri: f}), type = f.split('.'); + var doc = CoreIoApi.openFile({uri: f}), type = f.split('.'); //Splitting to get file extension type = type[type.length-1]; //TODO: Fix this HACK to generate string @@ -387,7 +379,7 @@ switch (type.toLowerCase()) { dir_str += dir[i] + '\\'; } //Starting an instance of the shell server on directory - server = ShellApi.startServer(dir_str); + server = CoreIoApi.startServer(dir_str); //Opening file in app FileIo.open(doc, type, f, server); } @@ -439,7 +431,7 @@ switch (type.toLowerCase()) { value: function (directory) { var mjs_dir = {uri: directory.uri}; mjs_dir.uri += '\\m-js'; - var mjs_check = ShellApi.directoryExists(mjs_dir); + var mjs_check = CoreIoApi.directoryExists(mjs_dir); // if (mjs_check.success) { switch (mjs_check.status) { @@ -455,7 +447,7 @@ switch (type.toLowerCase()) { //Creating m-js folder and copying contents - var mjs_folder = ShellApi.createDirectory(mjs_dir); + var mjs_folder = CoreIoApi.createDirectory(mjs_dir); if (mjs_folder.success) { switch (mjs_folder.status) { case 201: @@ -463,12 +455,12 @@ switch (type.toLowerCase()) { var temp_dir = window.NativeShellApp.GetKnownFolder('appsource')+'\\user-document-templates\\montage-application\\systemio\\new\\project\\montage'; - var mjs_deps = ShellApi.createDirectory({uri: mjs_dir.uri+'\\deps'}); + var mjs_deps = CoreIoApi.createDirectory({uri: mjs_dir.uri+'\\deps'}); //Folder created, now copying contents - var copy_lib = ShellApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\lib', destUri: mjs_dir.uri+'\\lib'}), - copy_deps = ShellApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\deps\\require', destUri: mjs_dir.uri+'\\deps\\require'}), - copy_components = ShellApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('appsource')+'\\montage-components', destUri: directory.uri+'\\montage-components'}); + var copy_lib = CoreIoApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\lib', destUri: mjs_dir.uri+'\\lib'}), + copy_deps = CoreIoApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\deps\\require', destUri: mjs_dir.uri+'\\deps\\require'}), + copy_components = CoreIoApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('appsource')+'\\montage-components', destUri: directory.uri+'\\montage-components'}); //Checking for lib operation's result if (copy_lib.success) { @@ -496,11 +488,11 @@ switch (type.toLowerCase()) { var prj_tmplt = window.NativeShellApp.GetKnownFolder('appsource')+'\\document-templates\\projects\\montage'; //TODO: Add error handling for file copying, clean up this HACK - var copy_packagemjs = ShellApi.copyFile({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\package.json', destUri: mjs_dir.uri+'\\package.json'}), - copy_styles = ShellApi.copyFile({sourceUri: prj_tmplt+'\\styles.css', destUri: directory.uri+'\\styles.css'}), - copy_appdelegate = ShellApi.copyFile({sourceUri: prj_tmplt+'\\appdelegate.js', destUri: directory.uri+'\\appdelegate.js'}), - copy_package = ShellApi.copyFile({sourceUri: prj_tmplt+'\\package.json', destUri: directory.uri+'\\package.json'}), - copy_index = ShellApi.copyFile({sourceUri: prj_tmplt+'\\index.html', destUri: directory.uri+'\\index.html'}); + var copy_packagemjs = CoreIoApi.copyFile({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\package.json', destUri: mjs_dir.uri+'\\package.json'}), + copy_styles = CoreIoApi.copyFile({sourceUri: prj_tmplt+'\\styles.css', destUri: directory.uri+'\\styles.css'}), + copy_appdelegate = CoreIoApi.copyFile({sourceUri: prj_tmplt+'\\appdelegate.js', destUri: directory.uri+'\\appdelegate.js'}), + copy_package = CoreIoApi.copyFile({sourceUri: prj_tmplt+'\\package.json', destUri: directory.uri+'\\package.json'}), + copy_index = CoreIoApi.copyFile({sourceUri: prj_tmplt+'\\index.html', destUri: directory.uri+'\\index.html'}); // this.openProject(directory); @@ -567,7 +559,7 @@ switch (type.toLowerCase()) { //TODO: Add cloud integration } else { //Getting file URI from native prompt - uri = ShellApi.openShellDialog({type: 'directory', action: 'open'}); + uri = CoreIoApi.openShellDialog({type: 'directory', action: 'open'}); } } //Checking for a valid URI @@ -608,7 +600,7 @@ switch (type.toLowerCase()) { //////////////////////////////////////////////////////////////////// if (f) { - var s = ShellApi.updateFile(f); + var s = CoreIoApi.updateFile(f); } else { //HACK this.saveProject(); diff --git a/js/io/system/projectio.js b/js/io/system/projectio.js old mode 100644 new mode 100755 diff --git a/js/io/system/shellapi.js b/js/io/system/shellapi.js deleted file mode 100644 index 9976dbed..00000000 --- a/js/io/system/shellapi.js +++ /dev/null @@ -1,806 +0,0 @@ -/* -This file contains proprietary software owned by Motorola Mobility, Inc.
-No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
-(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ - -/* ///////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////// -NOTES: All logic should be handled in the FileSystem and I/O classes - -Dialog methods on NativeShellApp -ShowFileOpenDialog(initialDir) - shows a file open dialog -initialDir is optional and if specified will cause the dialog to initially display that directory as the open location -ShowFileSaveAsDialog(initialURI) - shows a file Save As dialog -initialURI is optional and if specified will cause the dialog to initially display the directory as the default location -and the filename as the current filename. -ShowSelectDirectoryDialog(initialDir, dialogTitle) - displays a directory select/chooser dialog -intitalDir is optional and specifies the directory that should be selected/shown when the dialog opens -dialogTitle is optional and specifies the title that should appear in the dialog caption -//////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////// */ -//Exporting as Project I/O -exports.ShellApi = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, { - ///////