Skip to content

Commit

Permalink
prevent editing of attachments + add preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale Harvey committed Jun 30, 2011
1 parent 40ce74e commit bff9197
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
18 changes: 16 additions & 2 deletions _attachments/index.html
Expand Up @@ -101,12 +101,17 @@ <h1 id="title">CouchDB</h1>
<ul>
<li class="header">JSON</li>
{{#keys}}
{{#canedit}}
<li><a href="#/db/{{db}}/{{doc}}/rev/{{rev}}/{{url}}/">
{{key}}: <span class="jsonval">{{value}}</span></a>
</li>
{{key}}: <span class="jsonval">{{value}}</span></a></li>
{{/canedit}}
{{^canedit}}
<li class="selectwrapper">{{key}}: <span class="jsonval">{{value}}</span></li>
{{/canedit}}
{{/keys}}
</ul>

{{#canedit}}
<form action="#addkey" id="addkeyform">
<input type="hidden" name="db" value="{{db}}" />
<input type="hidden" name="doc" value="{{doc}}">
Expand All @@ -117,6 +122,15 @@ <h1 id="title">CouchDB</h1>
<a class="button" id="addkey">Add Key</a>
</div>
</form>
{{/canedit}}

{{#preview}}
<ul>
<li class="header">Preview</li>
<li class="selectwrapper" style="text-align:center;">{{{preview}}}</li>
</ul>
{{/preview}}


{{#hasrevisions}}
<ul>
Expand Down
21 changes: 13 additions & 8 deletions _attachments/js/mobile.futon.js
Expand Up @@ -288,7 +288,19 @@ var MobileFuton = (function () {
, keys: keys});

} else {
var canedit = true
, preview = ""
, tmp = key.split(":");
if (tmp[0] === "_attachments" && tmp.length > 1) {
canedit = false;
if (/(image\/png|image\/jpeg|image\/jpg)/.test(data.content_type)) {
preview = '<img src="/' + db + '/' + docId + '/' +
decodeURIComponent(tmp[1]).replace(":", "/") + '" />';
}
}
renderer.render('document_tpl', { db: db
, canedit: canedit
, preview: preview
, doc:doc
, rev: rev
, key: key
Expand Down Expand Up @@ -322,6 +334,7 @@ var MobileFuton = (function () {
, url: obj});
});
renderer.render('document_tpl', { db: db
, canedit: true
, doc:doc
, keys: keys
, rev: rev
Expand Down Expand Up @@ -502,11 +515,6 @@ var MobileFuton = (function () {
});


router.post('#addkey', function (e, form) {
console.log(form);
});


router.post('#delete_database', function (e, form) {
$.couch.db(form.db).drop().then(function() {
location.href = "#/db/";
Expand Down Expand Up @@ -717,10 +725,7 @@ var MobileFuton = (function () {


function addDocEvents(tpl) {
console.log("hello");
$("#addkey", tpl).bind('mousedown', function() {
console.log("wtf");

if ($("#addkeylist").children().length === 0) {
$("#addkeylist").append('<li class="header">New JSON<li>');
$("#addkeyform").append('<input type="submit" value="Save" id="addkeybtn" />');
Expand Down

0 comments on commit bff9197

Please sign in to comment.