Commit 280a3d53 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Add dedicated page to add documents

parent a4bfc088
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>CribJS Header</title>
<!-- renderjs -->
<script src="../lib/rsvp.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<script src="../lib/jio-latest.js" type="text/javascript"></script>
<script src="../lib/mimetype.js" type="text/javascript"></script>
<script src="./gadget_global.js" type="text/javascript"></script>
<!-- Custom -->
<script src="./gadget_cribjs_page_add.js" type="text/javascript"></script>
</head>
<body>
<div class="nav_content editor">
<div class="container">
<h3>Edit</h3>
<div class="row">
<form class="crib-add form-inline">
<div class="form-group">
<label>URL:
<input name="url" class="url form-control" type="text" size="50" value=""
placeholder="Enter the new URL">
</label>
</div>
<div class="form-group">
<label>File:
<input name="file" class="file form-control" type="file">
</label>
</div>
<div class="form-group">
<button type="submit" name="add" class="btn btn-default">Add</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
/*global window, RSVP, console */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener, jIO, mimeType) {
"use strict";
function addContent(gadget, event, logFunction) {
var url = gadget.props.element.querySelector("form.crib-add .url").value,
file_list = gadget.props.element.querySelector("form.crib-add .file")
.files,
promise_list = [],
file;
if (logFunction === undefined) {
logFunction = console.log;
}
if (file_list.length === 0) {
logFunction("No File to Load");
if (!url) {
logFunction("Please Provide a File");
}
promise_list.push(
gadget.crib_sw_put(url,
{
content: [],
type: mimeType.lookup(url, false, "application/octet-stream")
})
);
} else {
if (!url) {
url = file_list[0].name;
}
promise_list.push(
gadget.crib_sw_put(url,
{
content: file_list[0],
type: mimeType.lookup(url, false, "application/octet-stream")
})
);
}
return RSVP.Queue()
.push(function () {
return RSVP.all(promise_list);
})
.push(function () {
return gadget.redirect({page: "editor", url: url});
});
}
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.start_deferred = RSVP.defer();
});
})
.declareAcquiredMethod("crib_sw_put", "crib_sw_put")
.declareAcquiredMethod("redirect", "redirect")
.declareMethod('render', function (options) {
var gadget = this;
if (options === undefined)
options = {};
gadget.props.options = options;
if (options.url !== undefined) {
gadget.props.element.querySelector("form.crib-add .url")
.value = options.url;
}
return new RSVP.Queue()
.push(function () {
return gadget.props.start_deferred.resolve();
});
})
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.props.start_deferred.promise;
})
.push(function () {
var promise_list = [];
// promise to get content from URL
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".crib-add"),
'submit',
false,
function (event) {
return addContent(gadget, event);
}
));
return RSVP.all(promise_list);
});
});
}(window, rJS, loopEventListener, jIO, mimeType));
\ No newline at end of file
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<input name="search-pattern" class="search-pattern form-control" type="text" size="50" value=""> <input name="search-pattern" class="search-pattern form-control" type="text" size="50" value="">
</label> </label>
<button type="submit" name="list-contents" class="btn btn-default">Search</button> <button type="submit" name="list-contents" class="btn btn-default">Search</button>
<button type="submit" name="add" class="btn btn-info">Add</button>
</div> </div>
<table class="table table-striped table-condensed"> <table class="table table-striped table-condensed">
<thead> <thead>
......
...@@ -136,7 +136,14 @@ ...@@ -136,7 +136,14 @@
'submit', 'submit',
false, false,
function (event) { function (event) {
gadget.redirect({ if (event.submitter.name === "add") {
return gadget.redirect({
page: "add",
url: gadget.props.element.querySelector(".search-pattern")
.value
});
}
return gadget.redirect({
page: "url_list", page: "url_list",
pattern: gadget.props.element.querySelector(".search-pattern") pattern: gadget.props.element.querySelector(".search-pattern")
.value .value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment