1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

More tw5dropbox updates

The "new wiki" button works now
This commit is contained in:
Jeremy Ruston 2012-10-12 08:22:44 +01:00
parent 60eeca5893
commit aba6fb5ffd
8 changed files with 138 additions and 9 deletions

View File

@ -8,6 +8,7 @@ node ../../core/boot.js \
--verbose \
--savetiddler $:/core/templates/tw5dropbox.template.js ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/tw5dropbox.js text/plain [!is[shadow]] \
--savetiddler $:/core/templates/index.template.html ../../../../../Apps/TiddlyWiki5/My\ TiddlyWiki/index.html text/plain [!is[shadow]] \
--savetiddler $:/core/templates/index.template.html ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/apptemplate.html text/plain [!is[shadow]] \
--savetiddler $:/core/templates/styles.template.css ../../../../../Apps/Static\ Web\ Apps/TiddlyWiki5/public/styles.css text/plain [!is[shadow]] \
|| exit 1

View File

@ -32,6 +32,14 @@
"module-type": "macro"
}
},
{
"file": "../../plugins/newwikimacro.js",
"fields": {
"title": "$:/plugins/dropbox/newwikimacro.js",
"type": "application/javascript",
"module-type": "macro"
}
},
{
"file": "dropbox-app.js",
"fields": {

View File

@ -32,6 +32,14 @@
"module-type": "macro"
}
},
{
"file": "../../plugins/newwikimacro.js",
"fields": {
"title": "$:/plugins/dropbox/newwikimacro.js",
"type": "application/javascript",
"module-type": "macro"
}
},
{
"file": "dropbox-main.js",
"fields": {

View File

@ -1,17 +1,15 @@
title: TiddlyWiki5 in the Sky with Dropbox
Welcome to TiddlyWiki5 in the Sky with Dropbox.
This app enables you to edit [[TiddlyWikis|TiddlyWiki]] in your [[Dropbox]].
<<reveal state:[[$:/plugins/dropbox/LoadedWikis]] type:nomatch text:yes><
Loading your wikis from Dropbox
>>
<<reveal state:[[$:/plugins/dropbox/LoadedWikis]] type:match text:yes><
! Your ~TiddlyWikis
!!! Your ~TiddlyWikis
<<transclude filter:[tag[wiki]] templateTitle:WikiTemplate emptyMessage:"You haven't created any wikis yet">>
<<dropbox.newwiki>>
>>
! Create new ~TiddlyWiki
+

View File

@ -1,4 +1,4 @@
title: WikiTemplate
<div class="alert"><<view title>> - <<link throughField:urlView><View>> <<link throughField:urlEdit><Edit>>
<div class="alert"><<view wikiName>> - <<link throughField:urlView><View>> <<link throughField:urlEdit><Edit>>
</div>

View File

@ -0,0 +1,11 @@
{
"tiddlers": [
{
"file": "../../../../../../../Apps/Static Web Apps/TiddlyWiki5/public/apptemplate.html",
"fields": {
"title": "$:/plugins/dropbox/apptemplate.html",
"type": "text/html"
}
}
]
}

View File

@ -18,7 +18,8 @@ var apiKey = "m+qwjj8wFRA=|1TSoitGS9Nz2RTwv+jrUJnsAj0yy57NhQJ4TkZ/+Hw==";
// Tiddler titles
var titleIsLoggedIn = "$:/plugins/dropbox/IsLoggedIn",
titleUserName = "$:/plugins/dropbox/UserName",
titlePublicAppUrl = "$:/plugins/dropbox/PublicAppUrl";
titlePublicAppUrl = "$:/plugins/dropbox/PublicAppUrl",
titleAppTemplateHtml = "$:/plugins/dropbox/apptemplate.html";
// Query string marker for forcing authentication
var queryLoginMarker = "login=true";
@ -92,7 +93,7 @@ $tw.plugins.dropbox.loadWikiFiles = function(path,callback) {
var stat = stats[s];
if(!stat.isFile && stat.isFolder) {
var url = $tw.plugins.dropbox.userInfo.publicAppUrl + stat.path + "/index.html";
$tw.wiki.addTiddler({title: stat.name, text: "wiki", tags: ["wiki"], urlView: url, urlEdit: url + "?login=true"});
$tw.wiki.addTiddler({title: "'" + stat.name + "'", text: "wiki", tags: ["wiki"], wikiName: stat.name, urlView: url, urlEdit: url + "?login=true"});
}
}
callback();
@ -225,6 +226,46 @@ $tw.plugins.dropbox.forceLogin = function() {
}
};
// Create a new empty TiddlyWiki
$tw.plugins.dropbox.createWiki = function(wikiName) {
// Remove any dodgy characters from the wiki name
wikiName = wikiName.replace(/[\$\:\?\#\/\\]/g,"");
// Check that the name isn't now empty
if(wikiName.length === 0) {
return alert("Bad wiki name");
}
// Create the wiki
async.series([
function(callback) {
// First create the wiki folder
$tw.plugins.dropbox.client.mkdir(wikiName,function(error,stat) {
callback(error);
});
},
function(callback) {
// Second create the tiddlers folder
$tw.plugins.dropbox.client.mkdir(wikiName + "/tiddlers",function(error,stat) {
callback(error);
});
},
function(callback) {
// Third save the template app HTML file
var tiddler = $tw.wiki.getTiddler(titleAppTemplateHtml);
if(!tiddler) {
callback("Cannot find app template tiddler");
} else {
$tw.plugins.dropbox.client.writeFile(wikiName + "/index.html",tiddler.fields.text,function(error,stat) {
callback(error);
});
}
}
],
// optional callback
function(err,results) {
alert("Created wiki " + wikiName + " error " + err);
});
};
exports.startup = function() {
if(!$tw.browser) {
return;

View File

@ -0,0 +1,62 @@
/*\
title: $:/plugins/dropbox/newwikimacro.js
type: application/javascript
module-type: macro
Dropbox new wiki plugin
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.info = {
name: "dropbox.newwiki",
params: {}
};
exports.handleEvent = function (event) {
if(event.type === "click") {
var wikiName = this.child.children[0].domNode.value;
$tw.plugins.dropbox.createWiki(wikiName);
}
event.preventDefault();
return false;
};
exports.executeMacro = function() {
// Create the link
var child = $tw.Tree.Element(
"form",
{
"class": "form-inline"
},
[
$tw.Tree.Element(
"input",
{
type: "text"
},
null
),
$tw.Tree.Element(
"button",
{
type: "submit",
"class": "btn"
},
[
$tw.Tree.Text("New")
],
{
events: ["click"],
eventHandler: this
})
]);
child.execute(this.parents,this.tiddlerTitle);
return child;
};
})();