1 /** 2 * Creates a new SaveDocumentView. This view renders a dialog where the user can 3 * save the mind map. 4 * 5 * @constructor 6 */ 7 mindmaps.SaveDocumentView = function() { 8 var self = this; 9 10 var $dialog = $("#template-save").tmpl().dialog({ 11 autoOpen : false, 12 modal : true, 13 zIndex : 5000, 14 width : 550, 15 close : function() { 16 // remove dialog from DOM 17 $(this).dialog("destroy"); 18 $(this).remove(); 19 } 20 }); 21 22 var $localSorageButton = $("#button-save-localstorage").button().click( 23 function() { 24 if (self.localStorageButtonClicked) { 25 self.localStorageButtonClicked(); 26 } 27 }); 28 29 var $hddSaveButton = $("#button-save-hdd").button().downloadify({ 30 filename : function() { 31 if (self.fileNameRequested) { 32 return self.fileNameRequested(); 33 } 34 }, 35 data : function() { 36 if (self.fileContentsRequested) { 37 return self.fileContentsRequested(); 38 } 39 }, 40 onComplete : function() { 41 if (self.saveToHddComplete) { 42 self.saveToHddComplete(); 43 } 44 }, 45 onError : function() { 46 console.log("error while saving to hdd"); 47 }, 48 swf : 'media/downloadify.swf', 49 downloadImage : 'img/transparent.png', 50 width : 65, 51 height : 29, 52 append : true 53 }); 54 55 this.showSaveDialog = function() { 56 $dialog.dialog("open"); 57 }; 58 59 this.hideSaveDialog = function() { 60 $dialog.dialog("close"); 61 }; 62 }; 63 64 /** 65 * Creates a new SaveDocumentPresenter. The presenter can store documents in the 66 * local storage or to a hard disk. 67 * 68 * @constructor 69 * @param {mindmaps.EventBus} eventBus 70 * @param {mindmaps.MindMapModel} mindmapModel 71 * @param {mindmaps.SaveDocumentView} view 72 */ 73 mindmaps.SaveDocumentPresenter = function(eventBus, mindmapModel, view) { 74 /** 75 * View callback when local storage button was clicked. Saves the document 76 * in the local storage. 77 * 78 * @ignore 79 */ 80 view.localStorageButtonClicked = function() { 81 // update modified date 82 var doc = mindmapModel.getDocument(); 83 doc.dates.modified = new Date(); 84 // set title 85 doc.title = mindmapModel.getMindMap().getRoot().getCaption(); 86 var success = mindmaps.LocalDocumentStorage.saveDocument(doc); 87 if (success) { 88 eventBus.publish(mindmaps.Event.DOCUMENT_SAVED, doc); 89 view.hideSaveDialog(); 90 } else { 91 // TODO display error hint 92 } 93 }; 94 95 /** 96 * View callback: Returns the filename for the document for saving on hard 97 * drive. 98 * 99 * @ignore 100 * @returns {String} 101 */ 102 view.fileNameRequested = function() { 103 return mindmapModel.getMindMap().getRoot().getCaption() + ".json"; 104 }; 105 106 /** 107 * View callback: Returns the serialized document. 108 * 109 * @ignore 110 * @returns {String} 111 */ 112 view.fileContentsRequested = function() { 113 var doc = mindmapModel.getDocument(); 114 doc.dates.modified = new Date(); 115 return doc.serialize(); 116 }; 117 118 /** 119 * View callback: Saving to the hard drive was sucessful. 120 * 121 * @ignore 122 */ 123 view.saveToHddComplete = function() { 124 var doc = mindmapModel.getDocument(); 125 eventBus.publish(mindmaps.Event.DOCUMENT_SAVED, doc); 126 view.hideSaveDialog(); 127 }; 128 129 this.go = function() { 130 view.showSaveDialog(); 131 }; 132 };