From adb90eff3323aa780f9a0879572e3cf3b9f0b969 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 13:04:58 -0800 Subject: - file picker - select file on double click - check cloud availability before IO operations [open file, new file, Save, Save As]. Canceling operation if cloud was unavailable, as per team's agreement. Signed-off-by: Ananya Sen --- js/components/ui/icon-list-basic/icon.reel/icon.js | 5 ++++ .../ui/tree-basic/treeItem.reel/treeItem.js | 5 ++++ js/controllers/document-controller.js | 33 ++++++++++++++++------ js/data/menu-data.js | 2 +- .../picker-navigator.reel/picker-navigator.js | 26 +++++++++++++---- .../new-file-workflow-controller.js | 7 ----- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 4 +-- 7 files changed, 58 insertions(+), 24 deletions(-) diff --git a/js/components/ui/icon-list-basic/icon.reel/icon.js b/js/components/ui/icon-list-basic/icon.reel/icon.js index b0279207..72adbfa1 100755 --- a/js/components/ui/icon-list-basic/icon.reel/icon.js +++ b/js/components/ui/icon-list-basic/icon.reel/icon.js @@ -131,6 +131,11 @@ var Icon = exports.Icon = Montage.create(Component, { openFolderEvent.initEvent("openFolder", false, false); openFolderEvent.folderUri = this.icondata.uri; this.element.dispatchEvent(openFolderEvent); + }else{ + var openFolderEvent = document.createEvent("Events"); + openFolderEvent.initEvent("selectFile", false, false); + openFolderEvent.fileUri = this.icondata.uri; + this.element.dispatchEvent(openFolderEvent); } if(evt.bubbles){ evt.stopPropagation(); diff --git a/js/components/ui/tree-basic/treeItem.reel/treeItem.js b/js/components/ui/tree-basic/treeItem.reel/treeItem.js index 755eab8c..4c71cb6b 100755 --- a/js/components/ui/tree-basic/treeItem.reel/treeItem.js +++ b/js/components/ui/tree-basic/treeItem.reel/treeItem.js @@ -225,6 +225,11 @@ exports.TreeItem = Montage.create(Component, { openFolderEvent.initEvent("openFolder", false, false); openFolderEvent.folderUri = this.treeItemData.uri; this.element.dispatchEvent(openFolderEvent); + }else{ + var openFolderEvent = document.createEvent("Events"); + openFolderEvent.initEvent("selectFile", false, false); + openFolderEvent.fileUri = this.treeItemData.uri; + this.element.dispatchEvent(openFolderEvent); } if(evt.bubbles){ evt.stopPropagation(); diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 9a063280..505daaba 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -58,6 +58,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("executeFileOpen", this, false); this.eventManager.addEventListener("executeNewFile", this, false); this.eventManager.addEventListener("executeSave", this, false); + this.eventManager.addEventListener("executeSaveAs", this, false); this.eventManager.addEventListener("recordStyleChanged", this, false); @@ -100,33 +101,47 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileOpen: { value: function(event) { var pickerSettings = event._event.settings || {}; - pickerSettings.callback = this.openFileWithURI.bind(this); - pickerSettings.pickerMode = "read"; - pickerSettings.inFileMode = true; - this.application.ninja.filePickerController.showFilePicker(pickerSettings); + if (this.application.ninja.coreIoApi.cloudAvailable()) { + pickerSettings.callback = this.openFileWithURI.bind(this); + pickerSettings.pickerMode = "read"; + pickerSettings.inFileMode = true; + this.application.ninja.filePickerController.showFilePicker(pickerSettings); + } } }, handleExecuteNewFile: { value: function(event) { var newFileSettings = event._event.settings || {}; - newFileSettings.callback = this.createNewFile.bind(this); - this.application.ninja.newFileController.showNewFileDialog(newFileSettings); + if (this.application.ninja.coreIoApi.cloudAvailable()) { + newFileSettings.callback = this.createNewFile.bind(this); + this.application.ninja.newFileController.showNewFileDialog(newFileSettings); + } } }, - - //////////////////////////////////////////////////////////////////// //TODO: Check for appropiate structures handleExecuteSave: { value: function(event) { - if(!!this.activeDocument){ + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ //Text and HTML document classes should return the same save object for fileSave this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); } } }, //////////////////////////////////////////////////////////////////// + handleExecuteSaveAs: { + value: function(event) { + var saveAsSettings = event._event.settings || {}; + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ + saveAsSettings.fileName = this.activeDocument.name; + saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); + //add callback + this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); + } + } + }, + // fileSaveResult: { value: function (result) { diff --git a/js/data/menu-data.js b/js/data/menu-data.js index 7c3ca5d4..52710b3a 100755 --- a/js/data/menu-data.js +++ b/js/data/menu-data.js @@ -44,7 +44,7 @@ exports.MenuData = Montage.create( Montage, { "displayText" : "Save As", "hasSubMenu" : false, "enabled": true, - "action":"saveAs" + "action":"executeSaveAs" }, { "displayText" : "Save All", diff --git a/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js b/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js index 411386f9..428e7bab 100644 --- a/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js +++ b/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js @@ -214,6 +214,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.element.addEventListener("openFolder", function(evt){that.handlePickerNavOpenFolder(evt);}, false);//add icon double click event listener to reload iconList with new set of data this.element.addEventListener("selectedItem", function(evt){that.handlePickerNavSelectedItem(evt);}, false);//for single selection only + this.element.addEventListener("selectFile", function(evt){that.handlePickerNavSelectedFile(evt);}, false);//for file selection this.element.addEventListener("showMetadata", function(evt){that.handlePickerNavShowMetadata(evt);}, false);//show metadata on hover of icon this.element.addEventListener("updateMetadata", function(evt){that.handlePickerNavUpdateMetadata(evt);}, false);//show metadata on click of icon //this.addressGo.addEventListener("click", this, false); @@ -669,14 +670,29 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { } }, + handlePickerNavSelectedFile:{ + value: function(evt){ + var uri = evt.fileUri; + + //do selection if in file selection mode + if(this.pickerModel.inFileMode && (this.application.ninja.filePickerController._directoryContentCache[uri].type === "file")){ + this.okButton.removeAttribute("disabled"); + //put into selectedItems..currently single selection is supported + this.selectedItems = [uri]; + this.currentURI = uri.substring(0, uri.lastIndexOf("/")); + this.handleOkButtonAction(); + } + } + }, + handlePickerNavShowMetadata: { value: function(evt){ - //update matadata only if nothing is already selected - if(this.currentSelectedNode == null){ - //console.log("handle showmetadata - true"); - this.metadataSection.innerHTML = evt.metadata; - } + //update matadata only if nothing is already selected + if(this.currentSelectedNode == null){ + //console.log("handle showmetadata - true"); + this.metadataSection.innerHTML = evt.metadata; } + } }, handlePickerNavUpdateMetadata:{ diff --git a/js/io/ui/new-file-dialog/new-file-workflow-controller.js b/js/io/ui/new-file-dialog/new-file-workflow-controller.js index 7b7f4572..f34ee000 100755 --- a/js/io/ui/new-file-dialog/new-file-workflow-controller.js +++ b/js/io/ui/new-file-dialog/new-file-workflow-controller.js @@ -19,12 +19,6 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre writable:false, enumerable:true, value:function(){ - var that = this; - - this.eventManager.addEventListener("saveAs", function(evt){ - var data = evt._event.data || {};//data will contain the current file name, directory location and callback - that.showSaveAsDialog(data); - }, false); } }, @@ -99,7 +93,6 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre saveAsDialog.fileName = fileName; saveAsDialog.folderUri = folderUri; saveAsDialog.callback = data.callback; - saveAsDialog.callbackScope = data.callbackScope; saveAsDialog.element = saveAsDialogContainer; //remove after rendering and add in modal dialog diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.js b/js/io/ui/save-as-dialog.reel/save-as-dialog.js index 55a09fa8..0a322b99 100644 --- a/js/io/ui/save-as-dialog.reel/save-as-dialog.js +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.js @@ -117,8 +117,8 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { try{ //validate file name and folder path //check if file already exists - if(!!this.callback && !!this.callbackScope){//inform document-controller if save successful - this.callback.call(this.callbackScope, {"filename":filename, "destination": newFileDirectory});//document-controller api + if(!!this.callback){//inform document-controller if save successful + this.callback({"filename":filename, "destination": newFileDirectory});//document-controller api }else{ //send save as event var saveAsEvent = document.createEvent("Events"); -- cgit v1.2.3 From 86996190d6a4dd59343d4ce482a9c0e6ef0f1eac Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 15:53:37 -0800 Subject: added null check for matchedRules in styles-controller.js, to fix js error on reopening and edited html document Signed-off-by: Ananya Sen --- js/controllers/styles-controller.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 885d710f..31beb6d0 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -317,7 +317,11 @@ var stylesController = exports.StylesController = Montage.create(Component, { isInlineStyle : true, style : element.style }; - + + if((typeof matchedRules === "undefined") || (matchedRules === null)){ + return null; + } + ///// Now splice it into the matched rules ///// By inserting the inline style at the beginning, ///// we keep the correct order of specificity -- cgit v1.2.3 From 539fb19b2327a9f6fb39403e27c29a8f8d733198 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 16:46:24 -0800 Subject: edit by Eric G.: catch the error instead of doing the null check for the stale element Signed-off-by: Ananya Sen --- js/controllers/styles-controller.js | 46 +++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 31beb6d0..662816f5 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -318,10 +318,6 @@ var stylesController = exports.StylesController = Montage.create(Component, { style : element.style }; - if((typeof matchedRules === "undefined") || (matchedRules === null)){ - return null; - } - ///// Now splice it into the matched rules ///// By inserting the inline style at the beginning, ///// we keep the correct order of specificity @@ -576,37 +572,36 @@ var stylesController = exports.StylesController = Montage.create(Component, { win = element.ownerDocument.defaultView, self = this; - if(!win) { - return null; - } - if(!omitPseudos) { pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter', 'first-line', 'first-child', 'before', 'after', 'lang', 'target']); } - pseudos.forEach(function(pseudo) { - rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { - //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, - //// or only use rules for other stylesheets + try { + pseudos.forEach(function(pseudo) { + rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { + //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, + //// or only use rules for other stylesheets - var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, - isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; + var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, + isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; - ///// filter out (return false) depending on flag - if(useStageStyleSheet && !isStageStyleSheet) { return false; } - if(!useStageStyleSheet && isStageStyleSheet) { return false; } + ///// filter out (return false) depending on flag + if(useStageStyleSheet && !isStageStyleSheet) { return false; } + if(!useStageStyleSheet && isStageStyleSheet) { return false; } - ///// Non-filter code - just assigning specificity to the rule - if(!rule[this.CONST.SPECIFICITY_KEY]) { - rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); - } + ///// Non-filter code - just assigning specificity to the rule + if(!rule[this.CONST.SPECIFICITY_KEY]) { + rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); + } - return true; - - }, this)); - }, this); + return true; + }, this)); + }, this); + } catch(ERROR) { + console.warn('StylesController::getMatchingRules - Un-attached element queried.'); + } ///// Function for sorting by specificity values function sorter(ruleA, ruleB) { var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex; @@ -985,6 +980,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Pass "true" to method to return an override object, which ///// has the rule to override, and whether the !important flag is needed dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement); + } ///// Did we find a dominant rule? -- cgit v1.2.3 From 9aa442da1ac9fd3212b37fa63a36090af47b6808 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 17:41:55 -0800 Subject: fix bug when closing the first document tab Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 505daaba..7470bae2 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -309,7 +309,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab var nextDocumentIndex = -1 ; if((this._documents.length > 0) && (closeDocumentIndex === 0)){ - nextDocumentIndex = 1; + nextDocumentIndex = 0; }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ nextDocumentIndex = closeDocumentIndex - 1; } -- cgit v1.2.3 From f86577d5083aeed2de7a932fe4147e9002e91554 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 21 Feb 2012 21:11:54 -0800 Subject: cleanup - Removing temporary div to render the popups We don't need to render the popup before opening them. Removing that hack. Signed-off-by: Valerio Virgillito --- js/io/ui/file-picker/file-picker-controller.js | 14 -------------- js/io/ui/new-file-dialog/new-file-workflow-controller.js | 12 ------------ 2 files changed, 26 deletions(-) diff --git a/js/io/ui/file-picker/file-picker-controller.js b/js/io/ui/file-picker/file-picker-controller.js index 129bebad..5e4d0be8 100755 --- a/js/io/ui/file-picker/file-picker-controller.js +++ b/js/io/ui/file-picker/file-picker-controller.js @@ -33,7 +33,6 @@ var FilePickerController = exports.FilePickerController = Montage.create(require }, filePickerPopupType:{ - writable: true, enumerable: false, value: "filePicker" }, @@ -152,15 +151,6 @@ var FilePickerController = exports.FilePickerController = Montage.create(require writable:false, enumerable:true, value:function(callback, aModel){ - //render modal dialog - var pickerNavContent = document.createElement("div"); - pickerNavContent.id = "filePicker"; - - pickerNavContent.style.color = "#fff"; - - //hack (elements needs to be on DOM to be drawn) - document.getElementById('modalContainer').appendChild(pickerNavContent); - var pickerNavChoices = Montage.create(pickerNavigatorReel); var initUri = aModel.currentRoot; @@ -171,10 +161,6 @@ var FilePickerController = exports.FilePickerController = Montage.create(require pickerNavChoices.mainContentData = this.prepareContentList(initUri, aModel); pickerNavChoices.pickerModel = aModel; - pickerNavChoices.element = pickerNavContent; - - //hack - remove after rendering and add in modal dialog - document.getElementById('modalContainer').removeChild(pickerNavContent); var popup = Popup.create(); popup.content = pickerNavChoices; diff --git a/js/io/ui/new-file-dialog/new-file-workflow-controller.js b/js/io/ui/new-file-dialog/new-file-workflow-controller.js index 7b7f4572..c2be687a 100755 --- a/js/io/ui/new-file-dialog/new-file-workflow-controller.js +++ b/js/io/ui/new-file-dialog/new-file-workflow-controller.js @@ -29,7 +29,6 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre }, model:{ - writable: true, enumerable:true, value: null }, @@ -56,19 +55,8 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre this.model.defaultProjectType = lastSelectedProjectType; } - //render modal dialog - var newFileNavContent = document.createElement("div"); - newFileNavContent.id = "newFileDialog"; - - //elements needs to be on DOM to be drawn - document.getElementById('modalContainer').appendChild(newFileNavContent); - var newFileOptionsNav = newFileOptionsNavigatorModule.NewFileOptionsNavigator.create(); newFileOptionsNav.newFileModel = this.model; - newFileOptionsNav.element = newFileNavContent; - - //remove after rendering and add in modal dialog - document.getElementById('modalContainer').removeChild(newFileNavContent); var popup = Popup.create(); popup.content = newFileOptionsNav; -- cgit v1.2.3 From 067ebae166ff82ae113a91517dfa59e7de5ae3d3 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 21 Feb 2012 22:36:54 -0800 Subject: cleanup - using montage functions handlers and using the NJevent Signed-off-by: Valerio Virgillito --- .../file-input-field.reel/file-input-field.js | 21 ++++----------------- js/io/ui/file-picker/file-picker-controller.js | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/js/io/ui/file-picker/file-input-field.reel/file-input-field.js b/js/io/ui/file-picker/file-input-field.reel/file-input-field.js index 235be8ad..651fd7fa 100755 --- a/js/io/ui/file-picker/file-input-field.reel/file-input-field.js +++ b/js/io/ui/file-picker/file-input-field.reel/file-input-field.js @@ -9,24 +9,13 @@ var Montage = require("montage/core/core").Montage, var FileInputField = exports.FileInputField = Montage.create(Component, { - hasReel: { - value: true - }, - - willDraw: { - enumerable: false, - value: function() {} - }, - draw: { - enumerable: false, - value: function() {} - }, didDraw: { enumerable: false, value: function() { var that = this; this.findDirectory.identifier = "findDirectory"; - this.findDirectory.addEventListener("click", function(evt){that.handleFindDirectoryClick(evt);}, false); + + this.findDirectory.addEventListener("click", this, false); this.eventManager.addEventListener("pickerSelectionsDone", function(evt){that.handleFileInputPickerSelectionsDone(evt);}, false); @@ -60,8 +49,6 @@ var FileInputField = exports.FileInputField = Montage.create(Component, { handleFindDirectoryClick: { value: function(evt){ - var openFilePicker = document.createEvent("Events"); - openFilePicker.initEvent("openFilePicker", false, false); var settings = {}; if(this.selectDirectory === true){ settings.inFileMode = false; @@ -71,8 +58,8 @@ var FileInputField = exports.FileInputField = Montage.create(Component, { settings.pickerName = this.pickerName || "fileSelector"; } settings.callback = this.filePickerCallback.bind(this); - openFilePicker.settings = settings; - this.eventManager.dispatchEvent(openFilePicker); + + NJevent("openFilePicker", settings); } }, diff --git a/js/io/ui/file-picker/file-picker-controller.js b/js/io/ui/file-picker/file-picker-controller.js index 5e4d0be8..3b19de83 100755 --- a/js/io/ui/file-picker/file-picker-controller.js +++ b/js/io/ui/file-picker/file-picker-controller.js @@ -19,16 +19,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require writable:false, enumerable:true, value:function(){ - var that = this; - - this.eventManager.addEventListener("openFilePicker", function(evt){ - var settings; - if(typeof evt._event.settings !== "undefined"){ - settings = evt._event.settings; - } - that.showFilePicker(settings); - }, false); - + this.eventManager.addEventListener("openFilePicker", this, false); } }, @@ -37,6 +28,12 @@ var FilePickerController = exports.FilePickerController = Montage.create(require value: "filePicker" }, + handleOpenFilePicker: { + value: function(evt) { + this.showFilePicker(evt.detail); + } + }, + /** *this function is used to create an instance of a file picker * @@ -128,7 +125,9 @@ var FilePickerController = exports.FilePickerController = Montage.create(require } if(!!storedUri){ - aModel.currentRoot = unescape(storedUri); + // This is depracated -- use decodeURI instead + //aModel.currentRoot = unescape(storedUri); + aModel.currentRoot = decodeURI(storedUri); } if(!!allFileFilters){aModel.fileFilters = allFileFilters;} @@ -137,7 +136,6 @@ var FilePickerController = exports.FilePickerController = Montage.create(require if(typeof pickerMode !== "undefined"){aModel.pickerMode = pickerMode;} - //logic: get file content data onDemand from the REST api for the default or last opened root. Cache the data in page [in local cache ? dirty fs? ]. Filter on client side to reduce network calls. this.openFilePickerAsModal(callback, aModel); -- cgit v1.2.3 From a8f5dcd8e85af6600f2e2b6a4536f05fd0c9916d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 21 Feb 2012 22:37:36 -0800 Subject: Adding the default folder by default when opening a new file dialog. Adding the default folder name in the new file dialog input field. Also some more cleanup. Signed-off-by: Valerio Virgillito --- .../new-file-location.reel/new-file-location.js | 57 +++++++++++++--------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js index fae8f9c7..ee2847ca 100755 --- a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js +++ b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js @@ -11,46 +11,55 @@ var newFileWorkflowControllerModule = require("js/io/ui/new-file-dialog/new-file var NewFileLocation = exports.NewFileLocation = Montage.create(Component, { templateHeight:{ - enumerable: true, value:"25 px" }, templateWidth:{ - enumerable: true, value:"25 px" }, - willDraw: { - enumerable: false, - value: function() {} - }, + prepareForDraw: { + value: function() { + // Populate the file input field by using the session storage or the default user folder + var defaultSaveDirectory; + + if(window.sessionStorage) { + var storedFolder = window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection"); + if(storedFolder) defaultSaveDirectory = decodeURI(window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection")); + } + + if(!defaultSaveDirectory) { + var driveData = this.application.ninja.coreIoApi.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); + if(driveData.success){ + var topLevelDirectories = (JSON.parse(driveData.content)).children; + defaultSaveDirectory = topLevelDirectories[0].uri; + } else { + console.log("** Error ** Cannot get directory listing"); + defaultSaveDirectory = ""; + } + } - draw: { - enumerable: false, - value: function() {} + this.fileInputField.newFileDirectory.value = defaultSaveDirectory; + } }, didDraw: { - enumerable: false, value: function() { - var that=this; - this.fileInputField.selectDirectory = true; - this.newFileName.addEventListener("keyup", function(evt){that.handleNewFileNameOnkeyup(evt);}, false); - } - + this.newFileName.addEventListener("keyup", this, false); + } }, - handleNewFileNameOnkeyup:{ - value:function(evt){ - if(this.newFileName.value !== ""){ - var newFileNameSetEvent = document.createEvent("Events"); - newFileNameSetEvent.initEvent("newFileNameSet", false, false); - newFileNameSetEvent.newFileName = this.newFileName.value; - this.eventManager.dispatchEvent(newFileNameSetEvent); - } - } + handleKeyup:{ + value:function(evt){ + if(this.newFileName.value !== "") { + var newFileNameSetEvent = document.createEvent("Events"); + newFileNameSetEvent.initEvent("newFileNameSet", false, false); + newFileNameSetEvent.newFileName = this.newFileName.value; + this.eventManager.dispatchEvent(newFileNameSetEvent); + } + } } }); \ No newline at end of file -- cgit v1.2.3 From 69983b800d0179fcccd5b61b64ed22c02e22b93a Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 21 Feb 2012 22:43:45 -0800 Subject: Adding some comments. Signed-off-by: Valerio Virgillito --- js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js index ee2847ca..849c665c 100755 --- a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js +++ b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js @@ -18,16 +18,18 @@ var NewFileLocation = exports.NewFileLocation = Montage.create(Component, { value:"25 px" }, + // Populating the directory input field with the default save location or the last stored location. prepareForDraw: { value: function() { - // Populate the file input field by using the session storage or the default user folder var defaultSaveDirectory; + // Using session storage location if(window.sessionStorage) { var storedFolder = window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection"); if(storedFolder) defaultSaveDirectory = decodeURI(window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection")); } + // Use default if none found in session storage if(!defaultSaveDirectory) { var driveData = this.application.ninja.coreIoApi.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); if(driveData.success){ @@ -39,6 +41,7 @@ var NewFileLocation = exports.NewFileLocation = Montage.create(Component, { } } + // Set the input field to the correct directory this.fileInputField.newFileDirectory.value = defaultSaveDirectory; } }, -- cgit v1.2.3 From e17fb41feca768d746f89d90cef28192fa60c621 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 21 Feb 2012 23:30:01 -0800 Subject: Temp CSS fix (for file open) Implemented temporary work-around to the css-cross-origin issue on files loaded into Ninja. Fix is for open file, need to implement save functionality and integrate with CSS panel. --- js/document/html-document.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/js/document/html-document.js b/js/document/html-document.js index 9a7755e6..bd41bc46 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -382,24 +382,23 @@ exports.HTMLDocument = Montage.create(TextDocument, { //TODO: Remove, also for prototyping this.application.ninja.documentController._hackRootFlag = true; // - //this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); this.stageBG.onclick = null; this._document = this.iframe.contentWindow.document; this._window = this.iframe.contentWindow; // if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; - // + //Inserting user's document into template this._templateDocument.head.innerHTML = this._userDocument.content.head; - this._templateDocument.body.innerHTML = this._userDocument.content.body; - - // Adding a handler for the main user document reel to finish loading. + //this._templateDocument.body.innerHTML = this._userDocument.content.body; + + //Adding a handler for the main user document reel to finish loading this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once - //TODO: When written, the best way to initialize the document is to listen for the DOM tree being modified + //TODO: When re-written, the best way to initialize the document is to listen for the DOM tree being modified setTimeout(function () { @@ -408,9 +407,41 @@ exports.HTMLDocument = Montage.create(TextDocument, { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(this._document.styleSheets.length > 1) { + //Checking all styleSheets in document + for (var i in this._document.styleSheets) { + //If rules are null, assuming cross-origin issue + if(this._document.styleSheets[i].rules === null) { + //Disabling style sheet to reload via inserting in style tag + this._document.styleSheets[i].disabled = 'true'; + //TODO: Revisit URLs and URI creation logic, very hack right now + var fileUri, cssUrl, cssData, tag; + if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) { + //Getting the url of the CSS file + cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1]; + //Creating the URI of the file + fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1]; + //Loading the data from the file + cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); + //Creating tag with file content + tag = document.createElement('style'); + tag.ninjauri = fileUri; + tag.innerHTML = cssData.content; + this._templateDocument.head.appendChild(tag); + } + } + } + + //TODO: Revisit this logic this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; this._stylesheets = this._document.styleSheets; // Entire stlyesheets array + + this._templateDocument.body.innerHTML = this._userDocument.content.body; + + + + + //TODO Finish this implementation once we start caching Core Elements // Assign a model to the UserContent and add the ViewPort reference to it. NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); -- cgit v1.2.3 From 8974ecd564563a991ff96f9cb6d47da172174242 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 22 Feb 2012 00:49:47 -0800 Subject: local storage integration and versioning - Fixed the splitters Signed-off-by: Valerio Virgillito --- js/controllers/local-storage-controller.js | 51 +++++++++++++++++++++++------- js/data/settings.js | 17 ---------- js/ninja.reel/ninja.html | 13 +++++--- js/panels/Splitter.js | 22 +++++++++---- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/js/controllers/local-storage-controller.js b/js/controllers/local-storage-controller.js index 6963b245..ea763cff 100755 --- a/js/controllers/local-storage-controller.js +++ b/js/controllers/local-storage-controller.js @@ -7,7 +7,46 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; -exports.LocalStorage = Montage.create( Montage, { +exports.LocalStorage = Montage.create( Component, { + + canStore: { + value: null + }, + + deserializedFromTemplate: { + value: function() { + this.canStore = window.localStorage; + this.application.localStorage = this; + + // Redefine setItem and getItem if local storage is not available. + if(!this.canStore) { + this._getItem = function() { + console.log("Local Storage is not supported on your browser"); + return ""; + }; + + this._setItem = function() { + console.log("Local Storage is not supported on your browser"); + return false; + } + } + } + }, + + _getItem: { + value: function(key) { + var value = window.localStorage.getItem("ninja-" + key); + if(value !== null) value = JSON.parse(value); + + return value; + } + }, + + _setItem: { + value: function(key, value) { + window.localStorage.setItem("ninja-" + key, JSON.stringify(value)); + } + }, getItem: { value: function(item) { @@ -22,16 +61,6 @@ exports.LocalStorage = Montage.create( Montage, { return null; } - /* - if (window.localStorage) { - this.getItem = function(item) { - return window.localStorage.getItem(item); - }(item); - } else { - alert("Local Storage is not supported on your browser"); - - } - */ } }, diff --git a/js/data/settings.js b/js/data/settings.js index ffea2075..6b1af3fc 100755 --- a/js/data/settings.js +++ b/js/data/settings.js @@ -10,10 +10,6 @@ var Montage = require("montage/core/core").Montage, exports.Settings = Montage.create( Component, { - version: { - value: "11.1213" - }, - _settings: { value: null }, @@ -54,18 +50,5 @@ exports.Settings = Montage.create( Component, { return null; } } - }, - - deserializedFromSerialization: { - value: function() { - - if (LocalStorage.getItem("version") != this.version) { - this.settings = {} - LocalStorage.setItem("version",this.version); - } else { - this.settings = LocalStorage.getItem("settings"); - } - - } } }); \ No newline at end of file diff --git a/js/ninja.reel/ninja.html b/js/ninja.reel/ninja.html index 022b3f0a..43774d30 100755 --- a/js/ninja.reel/ninja.html +++ b/js/ninja.reel/ninja.html @@ -22,6 +22,11 @@ "name": "Preloader" }, + "localStorage": { + "module": "js/controllers/local-storage-controller", + "name": "LocalStorage" + }, + "settings1": { "module": "js/data/settings", "name": "Settings" @@ -324,12 +329,12 @@ -
+
-
+
-
+
@@ -392,7 +397,7 @@
-
+
diff --git a/js/panels/Splitter.js b/js/panels/Splitter.js index 9f5b4de7..cb05104d 100755 --- a/js/panels/Splitter.js +++ b/js/panels/Splitter.js @@ -9,6 +9,10 @@ var Component = require("montage/ui/component").Component; exports.Splitter = Montage.create(Component, { + version: { + value: "1.0" + }, + hasTemplate: { value: false }, @@ -49,19 +53,23 @@ exports.Splitter = Montage.create(Component, { get: function() { return this._collapsed; }, - set: function(value) - { + set: function(value) { this._collapsed = value; - this.application.ninja.settings.setSetting(this.element.id, "collapsed", this.collapsed); + + this.application.localStorage._setItem(this.element.getAttribute("data-montage-id"), {"version": this.version, "value": value}); } }, prepareForDraw: { value: function() { - //Get Setting from SettingManager - this.application.ninja.settings.getSetting(this.element.id, "collapsed"); - lapsed = false; - if (lapsed != null) this._collapsed = lapsed; + //Get splitter initial value from SettingManager + var storedData = this.application.localStorage._getItem(this.element.getAttribute("data-montage-id")); + if(storedData && this.element.getAttribute("data-montage-id") !== null) { + this._collapsed = storedData.value; + } else { + this._collapsed = false; + } + this.element.addEventListener("click", this, false); } }, -- cgit v1.2.3 From 91f6f672ee96c6e7e942b555af7057d6db52d90f Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 22 Feb 2012 11:50:25 -0800 Subject: moving the default folder location to the navigator to fix the ok button issue Signed-off-by: Valerio Virgillito --- .../new-file-location.reel/new-file-location.js | 28 ----------------- .../new-file-options-navigator.js | 36 +++++++++++++++++----- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js index 849c665c..0e1e09a4 100755 --- a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js +++ b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js @@ -18,34 +18,6 @@ var NewFileLocation = exports.NewFileLocation = Montage.create(Component, { value:"25 px" }, - // Populating the directory input field with the default save location or the last stored location. - prepareForDraw: { - value: function() { - var defaultSaveDirectory; - - // Using session storage location - if(window.sessionStorage) { - var storedFolder = window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection"); - if(storedFolder) defaultSaveDirectory = decodeURI(window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection")); - } - - // Use default if none found in session storage - if(!defaultSaveDirectory) { - var driveData = this.application.ninja.coreIoApi.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); - if(driveData.success){ - var topLevelDirectories = (JSON.parse(driveData.content)).children; - defaultSaveDirectory = topLevelDirectories[0].uri; - } else { - console.log("** Error ** Cannot get directory listing"); - defaultSaveDirectory = ""; - } - } - - // Set the input field to the correct directory - this.fileInputField.newFileDirectory.value = defaultSaveDirectory; - } - }, - didDraw: { value: function() { this.fileInputField.selectDirectory = true; diff --git a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js index 11b322fe..aaf39005 100644 --- a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js +++ b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js @@ -47,14 +47,36 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C enumerable:false, value:"0 px" }, - willDraw: { - enumerable: false, - value: function() {} - }, - draw: { - enumerable: false, - value: function() {} + + // Populating the directory input field with the default save location or the last stored location. + prepareForDraw: { + value: function() { + var defaultSaveDirectory; + + // Using session storage location + if(window.sessionStorage) { + var storedFolder = window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection"); + if(storedFolder) defaultSaveDirectory = decodeURI(window.sessionStorage.getItem("lastOpenedFolderURI_folderSelection")); + } + + // Use default if none found in session storage + if(!defaultSaveDirectory) { + var driveData = this.application.ninja.coreIoApi.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); + if(driveData.success){ + var topLevelDirectories = (JSON.parse(driveData.content)).children; + defaultSaveDirectory = topLevelDirectories[0].uri; + } else { + console.log("** Error ** Cannot get directory listing"); + defaultSaveDirectory = ""; + } + } + + // Set the input field to the correct directory + this.newFileLocation.fileInputField.newFileDirectory.value = defaultSaveDirectory; + this.newFileDirectory = defaultSaveDirectory; + } }, + didDraw: { enumerable: false, value: function() { -- cgit v1.2.3 From 27589634d3e8ea52abe8623f8f2cc48ce0aa04c9 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 12:05:13 -0800 Subject: Improving temp CSS loading fix Adding logic to parse the entire DOM and insert the style tag loading the link element content directly above. --- js/document/html-document.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/js/document/html-document.js b/js/document/html-document.js index bd41bc46..02e9918f 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -377,6 +377,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { value: function(event){ //TODO: Clean up, using for prototyping save this._templateDocument = {}; + this._templateDocument.html = this.iframe.contentWindow.document; this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead"); this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); //TODO: Remove, also for prototyping @@ -390,7 +391,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; //Inserting user's document into template this._templateDocument.head.innerHTML = this._userDocument.content.head; - //this._templateDocument.body.innerHTML = this._userDocument.content.body; + this._templateDocument.body.innerHTML = this._userDocument.content.body; //Adding a handler for the main user document reel to finish loading this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); @@ -411,36 +412,42 @@ exports.HTMLDocument = Montage.create(TextDocument, { for (var i in this._document.styleSheets) { //If rules are null, assuming cross-origin issue if(this._document.styleSheets[i].rules === null) { - //Disabling style sheet to reload via inserting in style tag - this._document.styleSheets[i].disabled = 'true'; //TODO: Revisit URLs and URI creation logic, very hack right now - var fileUri, cssUrl, cssData, tag; + var fileUri, cssUrl, cssData, tag, query; if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) { //Getting the url of the CSS file cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1]; - //Creating the URI of the file + //Creating the URI of the file (this is wrong should not be splitting cssUrl) fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1]; //Loading the data from the file cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); //Creating tag with file content - tag = document.createElement('style'); - tag.ninjauri = fileUri; + tag = this.iframe.contentWindow.document.createElement('style'); + tag.setAttribute('ninjauri', fileUri); + tag.setAttribute('ninjafileurl', cssUrl); tag.innerHTML = cssData.content; - this._templateDocument.head.appendChild(tag); + //Looping through DOM to insert style tag at location of link element + query = this._templateDocument.html.querySelectorAll(['link']); + for (var j in query) { + if (query[j].href === this._document.styleSheets[i].href) { + //Disabling style sheet to reload via inserting in style tag + query[j].setAttribute('disabled', 'true'); + //Inserting tag + this._templateDocument.head.insertBefore(tag, query[j]); + } + } } } } //TODO: Revisit this logic - this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; + this._styles = this._document.styleSheets[1]; this._stylesheets = this._document.styleSheets; // Entire stlyesheets array + console.log(this._document.styleSheets); - this._templateDocument.body.innerHTML = this._userDocument.content.body; - - - - + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// //TODO Finish this implementation once we start caching Core Elements // Assign a model to the UserContent and add the ViewPort reference to it. -- cgit v1.2.3 From 5da4627fe899c03e885d10a77a5e33bb15875504 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 13:38:09 -0800 Subject: Removed css not needed in Ninja Template --- js/document/html-document.js | 1 + js/document/templates/montage-html/index.html | 1 - js/document/templates/montage-html/styles.css | 5 ----- 3 files changed, 1 insertion(+), 6 deletions(-) delete mode 100755 js/document/templates/montage-html/styles.css diff --git a/js/document/html-document.js b/js/document/html-document.js index 02e9918f..ba5eea79 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -425,6 +425,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { tag = this.iframe.contentWindow.document.createElement('style'); tag.setAttribute('ninjauri', fileUri); tag.setAttribute('ninjafileurl', cssUrl); + tag.setAttribute('ninjafilename', cssUrl.split('/')[cssUrl.split('/').length-1]); tag.innerHTML = cssData.content; //Looping through DOM to insert style tag at location of link element query = this._templateDocument.html.querySelectorAll(['link']); diff --git a/js/document/templates/montage-html/index.html b/js/document/templates/montage-html/index.html index 8b3d73bb..edfab2b0 100755 --- a/js/document/templates/montage-html/index.html +++ b/js/document/templates/montage-html/index.html @@ -12,7 +12,6 @@ Ninja Prototype - diff --git a/js/document/templates/montage-html/styles.css b/js/document/templates/montage-html/styles.css deleted file mode 100755 index 0441c1cf..00000000 --- a/js/document/templates/montage-html/styles.css +++ /dev/null @@ -1,5 +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. -
*/ \ No newline at end of file -- cgit v1.2.3 From 3524a22fa0745bb223ab6bcc312ca970a001157f Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 16:45:19 -0800 Subject: Logic to save