Commit 66f0ae9b authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

JSLint Javascript Code

parent dff89c6d
......@@ -26,7 +26,7 @@ if ('serviceWorker' in navigator) {
//jio = jIO.createJIO({type: "indexeddb", database: "cribjs"});
jio = jIO.createJIO({type:"dav", url: "https://cedriclendav.node.vifib.com/toto", basic_login: btoa("cedriclen:foo")})
jio = jIO.createJIO({type:"dav", url: "https://cedriclendav.node.vifib.com/toto", basic_login: btoa("cedriclen:foo")});
function setStatus(statusMessage) {
document.querySelector('#status').textContent = statusMessage;
......@@ -52,7 +52,7 @@ function showCommands() {
}).then(function() {
// If the promise resolves, just display a success message.
setStatus('Added to cache: ' + url + ' at ' + Date());
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error.
}, setStatus);
});
document.querySelector('#delete').addEventListener('click', function() {
......@@ -62,7 +62,7 @@ function showCommands() {
}).then(function() {
// If the promise resolves, just display a success message.
setStatus('Deleted from cache.');
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error.
}, setStatus); // If the promise rejects, then setStatus will be called with the error.
});
document.querySelector('#list-contents').addEventListener('click', function() {
......@@ -84,7 +84,7 @@ function showCommands() {
liElement.innerHTML = aElement.outerHTML;
contentsElement.appendChild(liElement);
});
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error.
}, setStatus); // If the promise rejects, then setStatus will be called with the error.
});
document.querySelector('#get').addEventListener('click', function() {
......@@ -95,15 +95,15 @@ function showCommands() {
document.querySelector('#information').value = this.responseText;
}
);
})
});
document.querySelector('#save-path').value = document.location.origin;
document.querySelector('#save-contents').addEventListener('click', function() {
console.log('asking for the keys');
var path_to_save, path_to_save_length, application_id;
path_to_save = document.querySelector('#save-path').value
application_id = document.querySelector('#save-id').value
path_to_save_length = path_to_save.length
path_to_save = document.querySelector('#save-path').value;
application_id = document.querySelector('#save-id').value;
path_to_save_length = path_to_save.length;
sendMessage({
command: 'keys'
}).then(function(data) {
......@@ -123,36 +123,36 @@ function showCommands() {
var promise_list = [],
i, i_len, url;
for (i = 0, i_len = data.urls.length; i < i_len; i += 1) {
url = new String(data.urls[i]);
url = String(data.urls[i]);
if (url.indexOf(path_to_save) === 0) {
promise_list.push(jIO.util.ajax({
'url': url,
dataType: "blob"
}));
}
};
return RSVP.all(promise_list)
}
return RSVP.all(promise_list);
})
.push(function(response_list) {
var promise_list = [],
i, i_len, url, response, extension;
for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
response = response_list[i];
url = response.target.responseURL.substr(path_to_save_length)
extension = getExtension(url)
url = response.target.responseURL.substr(path_to_save_length);
extension = getExtension(url);
console.log("Pushing attachment " + url + " to " + path_to_save);
promise_list.push(
jio.putAttachment("/" + application_id + ".attachment/", btoa(url) + extension,
response.target.response
)
);
};
return RSVP.all(promise_list)
}
return RSVP.all(promise_list);
})
.push(undefined, function(error) {
console.log(error);
});
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error.
}, setStatus); // If the promise rejects, then setStatus will be called with the error.
});
document.querySelector('#load-path').value = document.location.origin;
......@@ -160,11 +160,11 @@ function showCommands() {
console.log('asking for the keys');
var url_list = [],
application_id;
application_id = document.querySelector('#load-id').value
application_id = document.querySelector('#load-id').value;
return new RSVP.Queue()
.push(function() {
console.log("put");
return jio.allAttachments("/" + application_id + ".attachment/")
return jio.allAttachments("/" + application_id + ".attachment/");
})
.push(function(response) {
var promise_list = [],
......@@ -173,21 +173,21 @@ function showCommands() {
if (response.hasOwnProperty(key)) {
extension = getExtension(key);
console.log(key);
url_list.push(atob(key.substr(0, key.length - extension.length)))
url_list.push(atob(key.substr(0, key.length - extension.length)));
promise_list.push(jio.getAttachment("/" + application_id + ".attachment/", key));
}
};
return RSVP.all(promise_list)
}
return RSVP.all(promise_list);
})
.push(function(response_list) {
var promise_list = [],
i, i_len, url, index, response, location, location_len;
location = document.location.origin;
location_len = location.length
location_len = location.length;
console.log(url_list);
console.log(response_list);
for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
url = url_list[i]
url = url_list[i];
index = url.indexOf(location);
if (index != -1)
url = url.substr(index + location_len);
......@@ -195,7 +195,7 @@ function showCommands() {
command: 'add',
url: document.querySelector('#load-path').value + url,
information: response_list[i]
})
});
}
})
.push(undefined, function(error) {
......@@ -207,16 +207,11 @@ function showCommands() {
var url_list = document.querySelector('#mass-remove-list').value.match(/[^\r\n]+/g),
url_list_length = url_list.length,
i;
console.log(url_list)
for (i = 0; i < url_list_length; i += 1) {
console.log(url_list[i])
sendMessage({
command: 'delete',
url: url_list[i],
}).then(function() {
// If the promise resolves, just display a success message.
setStatus('Deleted from cache.');
}).catch(setStatus); // If the promise rejects, then setStatus will be called with the error.
url: url_list[i]
}); // If the promise rejects, then setStatus will be called with the error.
}
});
......
/*globals window, document, RSVP, rJS, Handlebars,
location, console*/
location, console, btoa, Blob, jIO, atob,
loopEventListener */
/*jslint indent: 2, maxlen: 80*/
(function (window, document, RSVP, rJS, Handlebars, location, console) {
(function (RSVP, rJS, Handlebars, jIO, loopEventListener) {
"use strict";
var CODE_CONTENT_KEY = "text_content";
......@@ -28,9 +29,13 @@
function createDAVJio(gadget, event) {
return createJio(gadget, {
type:"dav",
type: "dav",
url: gadget.props.element.querySelector('.form-use-jio-dav .url').value,
basic_login: btoa(gadget.props.element.querySelector(".form-use-jio-dav .credential").value)
basic_login: btoa(
gadget.props.element.querySelector(
".form-use-jio-dav .credential"
).value
)
});
}
......@@ -42,9 +47,11 @@
.push(function (crib_sw_gadget) {
return crib_sw_gadget.allDocs();
})
.push(function(data) {
var contentsElement = gadget.props.element.querySelector('.crib-url-list-content tbody'),
footer_element = gadget.props.element.querySelector('.crib-url-list-content tfoot'),
.push(function (data) {
var contentsElement = gadget.props.element.querySelector(
'.crib-url-list-content tbody'),
footer_element = gadget.props.element.querySelector(
'.crib-url-list-content tfoot'),
url_list = data.urls,
url_number = 0, cached_number = 0,
url, trElement, tdElement;
......@@ -52,16 +59,17 @@
while (contentsElement.firstChild) {
contentsElement.removeChild(contentsElement.firstChild);
}
console.log(url_list);
// Add each cached URL to the list, one by one.
for (url in url_list) {
if (url_list.hasOwnProperty(url)) {
var element;
cached_number = url_list[url].cached ? cached_number + 1 : cached_number;
cached_number = url_list[url].cached ?
cached_number + 1 : cached_number;
url_number += 1;
trElement = document.createElement('tr');
tdElement = document.createElement('td');
tdElement.innerHTML = (url_list[url].cached ? "<span>&#x2713;</span>" : "")
tdElement.innerHTML = (
url_list[url].cached ? "<span>&#x2713;</span>" : "");
trElement.appendChild(tdElement);
tdElement = document.createElement('td');
element = document.createElement('a');
......@@ -79,7 +87,7 @@
trElement.appendChild(tdElement);
contentsElement.appendChild(trElement);
}
};
}
while (footer_element.firstChild) {
footer_element.removeChild(footer_element.firstChild);
}
......@@ -94,7 +102,7 @@
trElement.appendChild(tdElement);
footer_element.appendChild(trElement);
})
.fail(function(error) {
.fail(function (error) {
// XXX An Error Should be thrown
console.log(error);
throw error;
......@@ -103,8 +111,10 @@
function saveTextContent(gadget, event) {
var content,
url = gadget.props.element.querySelector("form.crib-editor-get .url").value,
mimetype = gadget.props.element.querySelector("form.crib-editor-save .mimetype").value;
url = gadget.props.element
.querySelector("form.crib-editor-get .url").value,
mimetype = gadget.props.element
.querySelector("form.crib-editor-save .mimetype").value;
console.log("saving content");
return new RSVP.Queue()
.push(function () {
......@@ -118,14 +128,17 @@
return gadget.getDeclaredGadget('crib_sw_gadget');
})
.push(function (crib_gadget) {
return crib_gadget.put(url, {content:content, type:mimetype});
return crib_gadget.put(url, {content: content, type: mimetype});
})
.push(function() {
gadget.props.element.querySelector(".crib-editor-save-status").textContent = "Saved " + url + " files at "+ Date ()
.push(function () {
gadget.props.element
.querySelector(".crib-editor-save-status").textContent = "Saved " +
url + " files at " + Date();
})
.fail(function(error) {
.fail(function (error) {
console.log(error);
gadget.props.element.querySelector(".crib-editor-save-status").textContent = error;
gadget.props.element
.querySelector(".crib-editor-save-status").textContent = error;
});
}
......@@ -137,18 +150,19 @@
})
.push(function (crib_gadget) {
return RSVP.all([crib_gadget.get(url),
gadget.getDeclaredGadget('codeeditor')])
gadget.getDeclaredGadget('codeeditor')]);
})
.push(function(data_list) {
//gadget.props.element.querySelector("form.crib-editor-save .content").value = data_list[0].responseText;
gadget.props.element.querySelector("form.crib-editor-save .mimetype").value = data_list[0].responseType;
.push(function (data_list) {
gadget.props.element
.querySelector("form.crib-editor-save .mimetype")
.value = data_list[0].responseType;
return data_list[1].render({
key: CODE_CONTENT_KEY,
value: data_list[0].responseText,
mode: data_list[0].responseType
});
})
.fail(function(error) {
.fail(function (error) {
console.log(error);
});
}
......@@ -156,66 +170,76 @@
function saveContentToJIO(gadget, event) {
var path_to_save, path_to_save_length, application_id, crib_sw_gadget,
jio_gadget, url_list = [], saved_number = 0;
path_to_save = gadget.props.element.querySelector('form.crib-save-to-jio .save-path').value
application_id = gadget.props.element.querySelector('form.crib-save-to-jio .save-id').value
path_to_save = gadget.props.element
.querySelector('form.crib-save-to-jio .save-path').value;
application_id = gadget.props.element
.querySelector('form.crib-save-to-jio .save-id').value;
path_to_save_length = path_to_save.length;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('crib_sw_gadget'),
gadget.getDeclaredGadget('jio_gadget')]);
gadget.getDeclaredGadget('jio_gadget')
]);
})
.push(function (gadget_list) {
crib_sw_gadget = gadget_list[0];
jio_gadget = gadget_list[1];
return crib_sw_gadget.allDocs({cached_only: true});
})
.push(function(data) {
.push(function (data) {
url_list = data.urls;
// This is buggy, it fails if the document already exists with dav storage
return RSVP.all(
[jio_gadget.put("/" + application_id + ".attachment/", {
// url: path_to_save
}),
jio_gadget.putAttachment("/", application_id, new Blob([JSON.stringify({url: path_to_save})],{type: "application/json"}))
return RSVP.all([
jio_gadget.put("/" + application_id + ".attachment/", {}),
jio_gadget.putAttachment(
"/", application_id,
new Blob(
[JSON.stringify({url: path_to_save})],
{type: "application/json"})
)
]);
})
.push(function() {
.push(function () {
var promise_list = [],
i, i_len, url;
for (i = 0, i_len = url_list.length; i < i_len; i += 1) {
url = new String(url_list[i]);
url = String(url_list[i]);
if (url.indexOf(path_to_save) === 0) {
saved_number += 1;
promise_list.push(jIO.util.ajax({
url: url,
dataType: "blob"
}));
};
};
}
}
return RSVP.all(promise_list);
})
.push(function(response_list) {
.push(function (response_list) {
var promise_list = [],
i, i_len, url, response, extension;
for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
response = response_list[i];
url = response.target.responseURL.substr(path_to_save_length)
extension = getExtension(url)
url = response.target.responseURL.substr(path_to_save_length);
extension = getExtension(url);
console.log("Will push attachment " + url + " to " + path_to_save);
promise_list.push(
jio_gadget.putAttachment("/" + application_id + ".attachment/", btoa(url) + extension,
jio_gadget.putAttachment(
"/" + application_id + ".attachment/", btoa(url) + extension,
response.target.response
)
);
};
return RSVP.all(promise_list)
}
return RSVP.all(promise_list);
})
.push(function() {
gadget.props.element.querySelector(".crib-save-to-jio-status").textContent = "Saved " + saved_number + " files at "+ Date ()
.push(function () {
gadget.props.element
.querySelector(".crib-save-to-jio-status")
.textContent = "Saved " + saved_number + " files at " + Date();
})
.fail(function(error) {
gadget.props.element.querySelector(".crib-save-to-jio-status").textContent = error;
.fail(function (error) {
gadget.props.element.querySelector(".crib-save-to-jio-status")
.textContent = error;
console.log(error);
});
}
......@@ -224,61 +248,69 @@
function loadContentFromJIO(gadget, event) {
var path_to_load, path_to_load_length, application_id, crib_sw_gadget,
jio_gadget, url_list = [];
path_to_load = gadget.props.element.querySelector('form.crib-load-from-jio .load-path').value
application_id = gadget.props.element.querySelector('form.crib-load-from-jio .load-id').value
path_to_load = gadget.props.element
.querySelector('form.crib-load-from-jio .load-path').value;
application_id = gadget.props.element
.querySelector('form.crib-load-from-jio .load-id').value;
path_to_load_length = path_to_load.length;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('crib_sw_gadget'),
gadget.getDeclaredGadget('jio_gadget')]);
gadget.getDeclaredGadget('jio_gadget')
]);
})
.push(function (gadget_list) {
crib_sw_gadget = gadget_list[0];
jio_gadget = gadget_list[1];
return jio_gadget.allAttachments("/" + application_id + ".attachment/");
})
.push(function(response) {
.push(function (response) {
var promise_list = [],
key, extension;
for (key in response) {
if (response.hasOwnProperty(key)) {
extension = getExtension(key);
console.log(key);
url_list.push(atob(key.substr(0, key.length - extension.length)))
promise_list.push(jio_gadget.getAttachment("/" + application_id + ".attachment/", key));
url_list.push(atob(key.substr(0, key.length - extension.length)));
promise_list.push(jio_gadget.getAttachment(
"/" + application_id + ".attachment/", key
));
}
}
};
return RSVP.all(promise_list)
return RSVP.all(promise_list);
})
.push(function(response_list) {
.push(function (response_list) {
var promise_list = [],
i, i_len, url, index, response, location, location_len;
location = document.location.origin;
location_len = location.length
location_len = location.length;
console.log(url_list);
console.log(response_list);
for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
url = url_list[i]
url = url_list[i];
index = url.indexOf(location);
if (index != -1)
url = url.substr(index + location_len);
promise_list.push(
crib_sw_gadget.put(path_to_load + url, {blob: response_list[i]})
)
);
}
})
.push(function() {
gadget.props.element.querySelector(".crib-load-from-jio-status").textContent = "Loaded " + url_list.length + " files at "+ Date ()
.push(function () {
gadget.props.element.querySelector(".crib-load-from-jio-status")
.textContent = "Loaded " + url_list.length + " files at " + Date();
})
.fail(function(error) {
gadget.props.element.querySelector(".crib-load-from-jio-status").textContent = error;
.fail(function (error) {
gadget.props.element.querySelector(".crib-load-from-jio-status")
.textContent = error;
console.log(error);
});
}
function massRemoveFromCache(gadget, event) {
var url_list = gadget.props.element.querySelector("form.crib-mass-remove textarea").value.match(/[^\r\n]+/g),
var url_list = gadget.props.element
.querySelector("form.crib-mass-remove textarea").value.match(/[^\r\n]+/g),
url_list_length = url_list.length;
return new RSVP.Queue()
.push(function () {
......@@ -288,24 +320,25 @@
var i,
promise_list = [];
for (i = 0; i < url_list_length; i += 1) {
console.log(url_list[i])
promise_list.push(crib_gadget.remove(url_list[i]));
};
}
return RSVP.all(promise_list);
})
.push(function() {
gadget.props.element.querySelector(".crib-mass-remove-status").textContent = "Removed " + url_list.length + " files at "+ Date ()
.push(function () {
gadget.props.element.querySelector(".crib-mass-remove-status")
.textContent = "Removed " + url_list.length + " files at " + Date();
})
.fail(function(error) {
gadget.props.element.querySelector(".crib-mass-remove-status").textContent = error;
.fail(function (error) {
gadget.props.element.querySelector(".crib-mass-remove-status")
.textContent = error;
console.log(error);
});
}
function displayTabContent(gadget, state) {
var tab_content_list = gadget.props.element.querySelectorAll('.nav_content');
console.log(tab_content_list.length);
for (var i = 0; i < tab_content_list.length; i += 1 ){
var tab_content_list = gadget.props.element
.querySelectorAll('.nav_content');
for (var i = 0; i < tab_content_list.length; i += 1) {
console.log('working with:');
console.log(tab_content_list[i]);
if (tab_content_list[i].getAttribute('class').indexOf(state) === -1) {
......@@ -333,13 +366,16 @@
.declareMethod('render', function (options) {
var promise_list = [],
gadget = this;
gadget.props.element.querySelector('form.crib-save-to-jio .save-path').value = document.location.origin;
gadget.props.element.querySelector('form.crib-load-from-jio .load-path').value = document.location.origin;
gadget.props.element.querySelector('form.crib-save-to-jio .save-path')
.value = document.location.origin;
gadget.props.element.querySelector('form.crib-load-from-jio .load-path')
.value = document.location.origin;
gadget.props.options = options;
// Add promise for list Cache content
if (options.url !== undefined) {
gadget.props.element.querySelector("form.crib-editor-get .url").value = options.url;
promise_list.push(getUrlTextContent(gadget, undefined, options.url))
gadget.props.element.querySelector("form.crib-editor-get .url")
.value = options.url;
promise_list.push(getUrlTextContent(gadget, undefined, options.url));
}
displayTabContent(gadget, options.view || 'cribjs');
promise_list.push(displayURLList(gadget, undefined));
......@@ -347,7 +383,7 @@
gadget.props.element.querySelector(".crib-url-list-content"),
'submit',
false,
function (event) {displayURLList(gadget, event)}
function (event) {displayURLList(gadget, event); }
));
// promise to get content from URL
promise_list.push(loopEventListener(
......@@ -355,7 +391,8 @@
'submit',
false,
function (event) {
var url = gadget.props.element.querySelector("form.crib-editor-get .url").value;
var url = gadget.props.element
.querySelector("form.crib-editor-get .url").value;
return getUrlTextContent(gadget, event, url);
}
));
......@@ -364,45 +401,47 @@
gadget.props.element.querySelector(".crib-editor-save"),
'submit',
false,
function (event) {saveTextContent(gadget, event)}
function (event) {saveTextContent(gadget, event); }
));
// promise to save content to jIO
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".crib-save-to-jio"),
'submit',
false,
function (event) {saveContentToJIO(gadget, event)}
function (event) {saveContentToJIO(gadget, event); }
));
// promise to load content from jIO
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".crib-load-from-jio"),
'submit',
false,
function (event) {loadContentFromJIO(gadget, event)}
function (event) {loadContentFromJIO(gadget, event); }
));
// promise to remove content from cache
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".crib-mass-remove"),
'submit',
false,
function (event) {massRemoveFromCache(gadget, event)}
function (event) {massRemoveFromCache(gadget, event); }
));
// promise to use dav storage for jIO
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".form-use-jio-dav"),
'submit',
false,
function (event) {createDAVJio(gadget, event)}
function (event) {createDAVJio(gadget, event); }
));
// promise to use local storage for jIO
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".form-use-jio-local"),
'submit',
false,
function (event) {createJio(gadget, {type: "indexeddb", database: "cribjs"})}
function (event) {
createJio(gadget, {type: "indexeddb", database: "cribjs"});
}
));
return RSVP.all(promise_list);
})
});
}(window, document, RSVP, rJS, Handlebars, location, console));
\ No newline at end of file
}(RSVP, rJS, Handlebars, jIO, loopEventListener));
\ No newline at end of file
/*global window, rJS, RSVP, URI, location,
loopEventListener*/
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP) {
"use strict";
function setERP5Configuration(gadget) {
var old_date = new Date(),
configuration = {};
// We are looking for documents modified in the past 3 month
old_date.setMonth(old_date - 2);
old_date.setDay(1);
configuration = {
type: "replicate",
// XXX This drop the signature lists...
query: {
query: 'portal_type:"Web Page" '
// XX Synchonizing the whole module is too much, here is a way to start quietly
// Supsended until modification_date is handled for synchronization
+ ' AND modification_date:>="'
+ today.toISOString(),
limit: [0, 1234567890]
},
use_remote_post: true,
conflict_handling: 1,
check_local_modification: true,
check_local_creation: true,
check_local_deletion: false,
check_remote_modification: true,
check_remote_creation: true,
check_remote_deletion: true,
local_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs"
}
}
},
remote_sub_storage: {
type: "erp5",
url: (new URI("hateoas"))
.absoluteTo(location.href)
.toString(),
default_view_reference: "jio_view"
}
};
return gadget.setSetting('jio_storage_description', configuration)
.push(function () {
return gadget.setSetting('jio_storage_name', "ERP5");
})
.push(function () {
return gadget.reload();
});
}
function setLocalConfiguration(gadget) {
var configuration = {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "officejs"
}
}
};
return gadget.setSetting('jio_storage_description', configuration)
.push(function () {
return gadget.reload();
});
}
function setDAVConfiguration(gadget) {
return gadget.redirect({page: 'jio_dav_configurator'});
}
var gadget_klass = rJS(window);
gadget_klass
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.deferred = RSVP.defer();
});
})
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("reload", "reload")
.declareAcquiredMethod("setSetting", "setSetting")
.declareMethod("render", function () {
var gadget = this;
return gadget.updateHeader({
title: "Storage Configuration"
}).push(function () {
return gadget.props.deferred.resolve();
});
})
/////////////////////////////////////////
// Form submit
/////////////////////////////////////////
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.props.deferred.promise;
})
.push(function () {
return RSVP.all([
loopEventListener(
gadget.props.element.querySelector('form.select-erp5-form'),
'submit',
true,
function () {
return setERP5Configuration(gadget);
}
),
loopEventListener(
gadget.props.element.querySelector('form.select-local-form'),
'submit',
true,
function () {
return setLocalConfiguration(gadget);
}
),
loopEventListener(
gadget.props.element.querySelector('form.select-dav-form'),
'submit',
true,
function () {
return setDAVConfiguration(gadget);
}
)
]);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
/*globals window, document, RSVP, rJS, Handlebars, console*/
/*jslint indent: 2, maxlen: 80*/
(function (window, document, RSVP, rJS, Handlebars, console) {
(function (RSVP, rJS, Handlebars) {
"use strict";
function callCribSWGadget(gadget, method, param_list) {
......@@ -53,7 +53,7 @@
.push(function (crib_ide_gadget) {
return crib_ide_gadget.render();
});
})
});
}(window, document, RSVP, rJS, console));
\ No newline at end of file
}(RSVP, rJS, Handlebars));
\ No newline at end of file
......@@ -41,15 +41,6 @@
});
}
/*
function initHeaderOptions(gadget) {
gadget.props.header_argument_list = {
panel_action: true,
title: gadget.props.application_title || "OfficeJS"
};
}
*/
function route(my_root_gadget, my_scope, my_method, my_param_list) {
return RSVP.Queue()
.push(function () {
......@@ -64,51 +55,10 @@ function initHeaderOptions(gadget) {
}
/*
function updateHeader(gadget) {
return gadget.getDeclaredGadget("header")
.push(function (header_gadget) {
return header_gadget.render(gadget.props.header_argument_list);
});
}
function increaseLoadingCounter(gadget) {
return new RSVP.Queue()
.push(function () {
gadget.props.loading_counter += 1;
if (gadget.props.loading_counter === 1) {
return gadget.getDeclaredGadget("header")
.push(function (header_gadget) {
return header_gadget.notifyLoading();
});
}
});
}
function decreaseLoadingCounter(gadget) {
return new RSVP.Queue()
.push(function () {
gadget.props.loading_counter -= 1;
if (gadget.props.loading_counter < 0) {
gadget.props.loading_counter = 0;
// throw new Error("Unexpected negative loading counter");
}
if (gadget.props.loading_counter === 0) {
return gadget.getDeclaredGadget("header")
.push(function (header_gadget) {
return header_gadget.notifyLoaded();
});
}
});
}
*/
function callJioGadget(gadget, method, param_list) {
var called = false;
return new RSVP.Queue()
.push(function () {
called = true;
return increaseLoadingCounter(gadget);
})
.push(function () {
return gadget.getDeclaredGadget("jio_gadget");
})
......@@ -116,17 +66,8 @@ function initHeaderOptions(gadget) {
return jio_gadget[method].apply(jio_gadget, param_list);
})
.push(function (result) {
return decreaseLoadingCounter(gadget)
.push(function () {
return result;
});
}, function (error) {
if (called) {
return decreaseLoadingCounter(gadget)
.push(function () {
throw error;
});
}
throw error;
});
}
......@@ -274,26 +215,6 @@ function initHeaderOptions(gadget) {
.toString()
);
})
// Configure jIO storage
/*.ready(function (g) {
var jio_gadget;
return g.getDeclaredGadget("jio_gadget")
.push(function (result) {
jio_gadget = result;
return getSetting(g, 'jio_storage_description');
})
.push(function (result) {
return jio_gadget.createJio(result);
});
})*/
/*
.ready(function (g) {
return g.getDeclaredGadget('panel')
.push(function (panel_gadget) {
return panel_gadget.render();
});
})
*/
.ready(function (g) {
return g.getDeclaredGadget('router')
.push(function (router_gadget) {
......@@ -316,33 +237,7 @@ function initHeaderOptions(gadget) {
.allowPublicAcquisition("setSetting", function (argument_list) {
return setSetting(this, argument_list[0], argument_list[1]);
})
/*
.allowPublicAcquisition("translateHtml", function (argument_list) {
return this.getDeclaredGadget("translation_gadget")
.push(function (translation_gadget) {
return translation_gadget.translateHtml(argument_list[0]);
});
})
// XXX Those methods may be directly integrated into the header,
// as it handles the submit triggering
.allowPublicAcquisition('notifySubmitting', function () {
return route(this, "header", 'notifySubmitting');
})
.allowPublicAcquisition('notifySubmitted', function () {
return route(this, "header", "notifySubmitted");
})
.allowPublicAcquisition('notifyChange', function () {
return route(this, "header", 'notifyChange');
})
.allowPublicAcquisition("translate", function (argument_list) {
return this.getDeclaredGadget("translation_gadget")
.push(function (translation_gadget) {
return translation_gadget.translate(argument_list[0]);
});
})
/**/
.allowPublicAcquisition("redirect", function (param_list) {
return this.getDeclaredGadget('router')
.push(function (router_gadget) {
......@@ -365,60 +260,6 @@ function initHeaderOptions(gadget) {
param_list);
});
})
/*
.allowPublicAcquisition("updateHeader", function (param_list) {
var gadget = this;
initHeaderOptions(gadget);
return this.getDeclaredGadget("translation_gadget")
.push(function (translation_gadget) {
var promise_list = [],
key;
for (key in param_list[0]) {
if (param_list[0].hasOwnProperty(key)) {
gadget.props.header_argument_list[key] = param_list[0][key];
}
}
promise_list.push(translation_gadget.translate(
gadget.props.header_argument_list.title
));
if (gadget.props.header_argument_list.hasOwnProperty('right_title')) {
promise_list.push(translation_gadget.translate(
gadget.props.header_argument_list.right_title
));
}
return RSVP.all(promise_list);
})
.push(function (result_list) {
gadget.props.header_argument_list.title = result_list[0];
if (result_list.length === 2) {
gadget.props.header_argument_list.right_title = result_list[1];
}
// XXX Sven hack: number of _url determine padding for
// subheader on ui-content
var key,
count = 0;
for (key in gadget.props.header_argument_list) {
if (gadget.props.header_argument_list.hasOwnProperty(key)) {
if (key.indexOf('_url') > -1) {
count += 1;
}
}
}
if (count > 2) {
gadget.props.sub_header_class = "ui-has-subheader";
}
});
})
.allowPublicAcquisition('triggerPanel', function () {
return route(this, "panel", "toggle");
})
.allowPublicAcquisition('renderEditorPanel', function (param_list) {
return route(this, "editor_panel", 'render', param_list);
})
/**/
.allowPublicAcquisition("jio_createJio", function (param_list) {
return callJioGadget(this, "createJio", param_list);
})
......@@ -487,21 +328,6 @@ function initHeaderOptions(gadget) {
// (ERP5 title by default + sidebar)
//initHeaderOptions(gadget);
return new RSVP.Queue()
/*.push(function () {
return increaseLoadingCounter(gadget);
})
.push(function () {
return gadget.getDeclaredGadget('panel');
})
.push(function (panel_gadget) {
return panel_gadget.close();
})
.push(function () {
return gadget.getDeclaredGadget('editor_panel');
})
.push(function (editor_panel) {
return editor_panel.close();
})/**/
.push(function () {
return gadget.getDeclaredGadget('router');
})
......@@ -522,10 +348,6 @@ function initHeaderOptions(gadget) {
.push(function (fragment) {
var element = gadget.props.content_element,
content_container = document.createElement("div");
//content_container.className = "ui-content " +
// (gadget.props.sub_header_class || "");
// reset subheader indicator
//delete gadget.props.sub_header_class;
// go to the top of the page
window.scrollTo(0, 0);
......@@ -545,14 +367,6 @@ function initHeaderOptions(gadget) {
});
}
})
/*.push(function () {
return decreaseLoadingCounter(gadget);
}, function (error) {
return decreaseLoadingCounter(gadget)
.push(function () {
throw error;
});
})/**/
.push(undefined, function (error) {
return displayError(gadget, error);
});
......
/*global window, rJS, RSVP */
/*global window, rJS, RSVP, XMLHttpRequest, MessageChannel,
console, navigator, Blob
*/
/*jslint indent: 2, maxerr: 3 */
(function(window, rJS, RSVP, jIO) {
(function (rJS, RSVP, jIO) {
"use strict";
/**
......@@ -20,10 +22,10 @@
*/
function ajax(param) {
var xhr = new XMLHttpRequest();
return new RSVP.Promise(function(resolve, reject, notify) {
return new RSVP.Promise(function (resolve, reject, notify) {
var k;
xhr.open(param.type || "GET", param.url, true);
xhr.addEventListener("load", function(e) {
xhr.addEventListener("load", function (e) {
var answer = {};
if (e.target.status >= 400) {
return reject(e);
......@@ -43,7 +45,7 @@
}
}
xhr.send();
}, function() {
}, function () {
xhr.abort();
});
}
......@@ -54,9 +56,9 @@
// contain an error, and reject with the error if it does. If you'd prefer, it's possible to call
// controller.postMessage() and set up the onmessage handler independently of a promise, but this is
// a convenient wrapper.
return new RSVP.Promise(function(resolve, reject, notify) {
return new RSVP.Promise(function (resolve, reject, notify) {
var messageChannel = new MessageChannel();
messageChannel.port1.onmessage = function(event) {
messageChannel.port1.onmessage = function (event) {
console.log(event);
if (event.data.error) {
reject(event.data.error);
......@@ -85,21 +87,22 @@
g.props.element = element;
});
})
.ready(function(gadget) {
.ready(function (gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
if ('serviceWorker' in navigator) {
// XXX Hack to not add a new service worker when one is already declared
if (!navigator.serviceWorker.controller) {
return new RSVP.Promise(function(resolve, reject, notify) {
return new RSVP.Promise(function (resolve, reject, notify) {
navigator.serviceWorker.register('/sw.js', {scope: '/'}).then(
function(){
function () {
if (navigator.serviceWorker.controller) {
resolve();
} else {
reject("Please reload this page to allow Service Worker to control this page");
}
}).catch(function(error) {
})
.then(undefined, function (error) {
reject(error);
});
});
......@@ -115,17 +118,17 @@
* @params {Object} Not taken into account
* @return {} Return the data url of the document
*/
.declareMethod('allDocs', function(params) {
.declareMethod('allDocs', function (params) {
if (params && params.cached_only) {
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'keys'
});
});
}
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'allDocs'
});
......@@ -139,7 +142,7 @@
* @url {string} url of the document to retrieve
* @return {data_url} Return the data url of the document
*/
.declareMethod('get', function(url) {
.declareMethod('get', function (url) {
return new RSVP.Queue()
.push(function () {
return ajax({
......@@ -147,12 +150,12 @@
});
})
.push(function (result) {
return new Blob([result.responseText], {type: result.responseType})
return new Blob([result.responseText], {type: result.responseType});
})
.push(function(result) {
.push(function (result) {
return jIO.util.readBlobAsDataURL(result);
})
.push(function(e) {
.push(function (e) {
return e.target.result;
});
})
......@@ -165,17 +168,17 @@
* @parameter {data_url} data url of the document to put, it will be transformed in a blob
* @return {data_url} Return the data url of the document
*/
.declareMethod('put', function(url, parameter) {
.declareMethod('put', function (url, parameter) {
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'add',
url: url,
information: jIO.util.dataURItoBlob(parameter)
});
}).push(function() {
}).push(function () {
// If the promise resolves, just display a success message.
console.log("Done adding "+ url);
console.log("Done adding " + url);
return 'Added to cache: ' + url + ' at ' + Date();
}).fail(setStatus);
})
......@@ -186,9 +189,9 @@
* @url {string} url of the document to remove
* @return {}
*/
.declareMethod('remove', function(url) {
.declareMethod('remove', function (url) {
return new RSVP.Queue()
.push(function() {
.push(function () {
return sendMessage({
command: 'delete',
url: url
......@@ -196,4 +199,4 @@
});
});
}(window, rJS, RSVP, jIO));
\ No newline at end of file
}(rJS, RSVP, jIO));
\ No newline at end of file
/*global window, rJS, RSVP */
/*global window, rJS, RSVP, Blob, console */
/*jslint indent: 2, maxerr: 3 */
(function(window, rJS, RSVP, jIO) {
(function (window, rJS, RSVP, jIO) {
"use strict";
function getStorageGadget(gadget) {
......@@ -22,7 +22,7 @@
});
});
} else {
gadget.props.storage_gadget_url = url
gadget.props.storage_gadget_url = url;
return gadget.dropGadget("storage")
.push(function () {}, function () {})
.push(function () {
......@@ -33,18 +33,19 @@
"sandbox": "iframe",
"element": gadget.props.element.querySelector('div')
});
})
});
}
})
.push(undefined, function (e) {
// Ugly Hack to reload page and make service worker available
if (e && e.indexOf("Please reload this page to allow Service Worker to control this page") > -1 ) {
if (e &&
e.indexOf("Please reload this page to allow Service Worker to control this page") > -1) {
console.log("reload");
window.location.reload(false);
throw(e);
throw (e);
} else {
console.log(e);
throw(e);
throw (e);
}
});
}
......@@ -56,40 +57,39 @@
.push(function (element) {
var getURL = window.location;
g.props.element = element;
getURL.protocol + "//" + getURL.host + "/crib-enable.html"
});
})
.ready(function(gadget) {
.ready(function (gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
return getStorageGadget(gadget);
})
.declareAcquiredMethod("getSetting", "getSetting")
.declareMethod('allDocs', function(params) {
.declareMethod('allDocs', function (params) {
return getStorageGadget(this)
.push(function (storage_gadget) {
return storage_gadget.allDocs(params)
return storage_gadget.allDocs(params);
});
})
.declareMethod('get', function(url) {
.declareMethod('get', function (url) {
return getStorageGadget(this)
.push(function (storage_gadget) {
return storage_gadget.get(url)
return storage_gadget.get(url);
})
.push(function (result) {
return jIO.util.dataURItoBlob(result);
});
})
.declareMethod('put', function(url, parameter) {
.declareMethod('put', function (url, parameter) {
var blob, gadget = this;
if (parameter.blob !== undefined) {
blob = parameter.blob;
} else {
blob = new Blob(
[parameter.content],
{type: parameter.type,}
{type: parameter.type}
);
}
return RSVP.Queue()
......@@ -106,10 +106,10 @@
;
})
.declareMethod('remove', function(url) {
.declareMethod('remove', function (url) {
return getStorageGadget(this)
.push(function (storage_gadget) {
return storage_gadget.remove(url)
return storage_gadget.remove(url);
});
});
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Codemirror Gadget</title>
<script src="../lib/rsvp.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<link rel="stylesheet" href="../lib/codemirror.css">
<link rel="stylesheet" href="../lib/codemirror/addon/dialog/dialog.css">
<link rel="stylesheet" href="../lib/codemirror/addon/search/matchesonscrollbar.css">
<script src="../lib/codemirror.js"></script>
<script src="../lib/codemirror/mode/css/css.js"></script>
<script src="../lib/codemirror/mode/xml/xml.js"></script>
<script src="../lib/codemirror/mode/javascript/javascript.js"></script>
<script src="../lib/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="../lib/codemirror/addon/dialog/dialog.js"></script>
<script src="../lib/codemirror/addon/search/searchcursor.js"></script>
<script src="../lib/codemirror/addon/search/search.js"></script>
<script src="../lib/codemirror/addon/scroll/annotatescrollbar.js"></script>
<script src="../lib/codemirror/addon/search/matchesonscrollbar.js"></script>
<script src="./gadget_codemirror.js" type="text/javascript"></script>
</head>
<body>
<div class="codemirror_gadget"><textarea name="code"></textarea></div>
</body>
</html>
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, CodeMirror */
(function (window, rJS, CodeMirror) {
"use strict";
rJS(window)
.declareAcquiredMethod("saveContent", "editor_saveContent")
.declareMethod('render', function (options) {
this.props.key = options.key || {};
this.props.editor.setOption("mode", options.mode || "htmlmixed");
this.props.editor.setValue(options.value || "");
})
.declareMethod('getContent', function () {
var result = {};
result[this.props.key || "text_content"] = this.props.editor.getValue();
return result;
})
.declareService(function () {
this.props.editor.refresh();
this.props.editor.focus();
})
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
CodeMirror.commands.save = function () {
return new RSVP.Queue()
.push(function () {
return g.saveContent()
})
};
g.props.editor = CodeMirror.fromTextArea(g.props.element.querySelector("textarea"), {
lineNumbers: true,
mode: "text/html", /*{
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
},*/
// fullScreen: true,
matchBrackets: true,
showCursorWhenSelecting: true,
extraKeys: {"Alt-F": "findPersistent"}
});
// XXX custom styling for CribJS, should be put somewhere else
g.props.element.querySelector('.CodeMirror').setAttribute('style', 'height: calc(100vh - 270px);')
});
});
}(window, rJS, CodeMirror));
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, Handlebars, document, loopEventListener, RSVP */
(function (window, rJS, Handlebars, document, loopEventListener, RSVP) {
(function (rJS, Handlebars, loopEventListener, RSVP) {
"use strict";
/////////////////////////////////////////////////////////////////
......@@ -54,11 +54,6 @@
g.props.title_element = element.querySelector("h1");
});
})
/*
.ready(function (g) {
return g.render(g.stats.options);
})
*/
//////////////////////////////////////////////
// acquired methods
//////////////////////////////////////////////
......@@ -70,21 +65,6 @@
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
/*
.declareMethod('notifyError', function () {
this.stats.loaded = true;
this.stats.submitted = true;
this.stats.error = true;
var gadget = this;
return this.render(this.stats.options)
.push(function () {
gadget.stats.error = false;
});
})
.declareMethod('notifyUpdate', function () {
return this.render(this.stats.options);
})
*/
.declareMethod('notifyLoading', function () {
if (this.stats.loaded) {
this.stats.loaded = false;
......@@ -97,28 +77,6 @@
return this.render(this.stats.options);
}
})
/*
.declareMethod('notifyChange', function () {
if (!this.stats.modified) {
this.stats.modified = true;
return this.render(this.stats.options);
}
})
.declareMethod('notifySubmitting', function () {
if (this.stats.submitted) {
this.stats.submitted = false;
return this.render(this.stats.options);
}
})
.declareMethod('notifySubmitted', function () {
if (!this.stats.submitted) {
this.stats.submitted = true;
// Change modify here, to allow user to redo some modification and being correctly notified
this.stats.modified = false;
return this.render(this.stats.options);
}
})
*/
.declareMethod('render', function (options) {
var gadget = this,
page_list = ["cribjs_home", "select_site", "url_list", "editor", "save_load", "tools", "mass_remove"],
......@@ -126,8 +84,8 @@
gadget.stats.options = options;
page_list.forEach(function (page) {
promise_list.push(gadget.getUrlFor({page: page}))
})
promise_list.push(gadget.getUrlFor({page: page}));
});
// Handle main title
return new RSVP.Queue()
.push(function () {
......@@ -135,7 +93,7 @@
})
.push(function (link_list) {
for (var i = 0; i < link_list.length; i++) {
gadget.props.element.querySelector("." + page_list[i]).href = link_list[i]
gadget.props.element.querySelector("." + page_list[i]).href = link_list[i];
}
});
})
......@@ -167,4 +125,4 @@
);
});
}(window, rJS, Handlebars, document, loopEventListener, RSVP));
\ No newline at end of file
}(rJS, Handlebars, loopEventListener, RSVP));
\ No newline at end of file
......@@ -26,8 +26,8 @@
promise_list = [];
page_list.forEach(function (page) {
promise_list.push(gadget.getUrlFor({page: page}))
})
promise_list.push(gadget.getUrlFor({page: page}));
});
// Handle main title
return new RSVP.Queue()
.push(function () {
......@@ -35,10 +35,10 @@
})
.push(function (link_list) {
for (var i = 0; i < link_list.length; i++) {
gadget.props.element.querySelector("." + page_list[i]).href = link_list[i]
gadget.props.element.querySelector("." + page_list[i]).href = link_list[i];
}
});
})
});
}(window, rJS, document, RSVP));
\ No newline at end of file
/*global window, rJS, loopEventListener */
/*global window, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener, jIO) {
"use strict";
......@@ -18,18 +18,19 @@
})
.push(function (data) {
content = data[CODE_CONTENT_KEY] || "";
return gadget.crib_sw_put(url, {content:content, type:mimetype});
})
.push(function() {
gadget.props.element.querySelector(".crib-editor-save-status").textContent = "Saved " + url + " files at "+ Date ()
return gadget.crib_sw_put(url, {content: content, type: mimetype});
})
.push(function () {
gadget.props.element.querySelector(".crib-editor-save-status")
.textContent = "Saved " + url + " files at " + Date();
});
}
function getUrlTextContent(gadget, event, url) {
var type;
return new RSVP.Queue()
.push(function () {
return gadget.crib_sw_get(url)
return gadget.crib_sw_get(url);
})
.push(function (data) {
type = data.type;
......@@ -38,10 +39,10 @@
.push(function (evt) {
return RSVP.all([
evt.target.result,
gadget.getDeclaredGadget('codeeditor')]);
gadget.getDeclaredGadget('codeeditor')
]);
})
.push(function(data_list) {
//gadget.props.element.querySelector("form.crib-editor-save .content").value = data_list[0].responseText;
.push(function (data_list) {
gadget.props.element.querySelector("form.crib-editor-save .mimetype").value = type;
return data_list[1].render({
key: CODE_CONTENT_KEY,
......@@ -64,7 +65,7 @@
return saveTextContent(this, undefined);
})
.allowPublicAcquisition("notifyChange", function () {
return ;
return;
})
.declareAcquiredMethod("crib_sw_get", "crib_sw_get")
.declareAcquiredMethod("crib_sw_put", "crib_sw_put")
......@@ -73,24 +74,24 @@
.declareMethod('render', function (options) {
var gadget = this;
if (options === undefined)
options = {}
options = {};
gadget.props.options = options;
return new RSVP.Queue()
.push(function () {
if (gadget.props.options.crib_enable_url !== undefined) {
return gadget.setSetting("site_editor_gadget_url", gadget.props.options.crib_enable_url);
}
return ;
return;
})
.push(function () {
if (options.url !== undefined) {
gadget.props.element.querySelector("form.crib-editor-get .url").value = options.url;
return getUrlTextContent(gadget, undefined, options.url)
return getUrlTextContent(gadget, undefined, options.url);
}
})
.push(function () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -115,9 +116,9 @@
gadget.props.element.querySelector(".crib-editor-save"),
'submit',
false,
function (event) {saveTextContent(gadget, event)}
function (event) {saveTextContent(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(window, rJS, loopEventListener, jIO));
\ No newline at end of file
/*global window, rJS, loopEventListener */
/*global window, rJS, loopEventListener, RSVP, console */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener) {
"use strict";
......@@ -12,13 +12,14 @@
promise_list = [];
for (i = 0; i < url_list_length; i += 1) {
promise_list.push(gadget.crib_sw_remove(url_list[i]));
};
}
return RSVP.all(promise_list);
})
.push(function() {
gadget.props.element.querySelector(".crib-mass-remove-status").textContent = "Removed " + url_list.length + " files at "+ Date ()
.push(function () {
gadget.props.element.querySelector(".crib-mass-remove-status")
.textContent = "Removed " + url_list.length + " files at " + Date();
})
.fail(function(error) {
.fail(function (error) {
gadget.props.element.querySelector(".crib-mass-remove-status").textContent = error;
console.log(error);
});
......@@ -42,7 +43,7 @@
return new RSVP.Queue()
.push(function () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -57,9 +58,9 @@
gadget.props.element.querySelector(".crib-mass-remove"),
'submit',
false,
function (event) {massRemoveFromCache(gadget, event)}
function (event) {massRemoveFromCache(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(window, rJS, loopEventListener));
\ No newline at end of file
/*global window, rJS, loopEventListener */
/*global window, rJS, loopEventListener, RSVP, console, document, saveAs */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener, JSZip, FileSaver) {
"use strict";
......@@ -15,25 +15,26 @@
function saveContentToZIP(gadget, event) {
var path_to_save, path_to_save_length, application_id, crib_sw_gadget,
jio_gadget, url_list = [], saved_number = 0, zip;
path_to_save = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-path').value
application_id = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-id').value
path_to_save = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-path').value;
application_id = gadget.props.element.querySelector('form.crib-save-to-zip .save-zip-id').value;
path_to_save_length = path_to_save.length;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('jio_gadget')]);
gadget.getDeclaredGadget('jio_gadget')
]);
})
.push(function (gadget_list) {
jio_gadget = gadget_list[0];
return gadget.crib_sw_allDocs({cached_only: true});
})
.push(function(data) {
.push(function (data) {
var promise_list = [],
i, i_len, url;
if ( data.hasOwnProperty("urls") ) {
if (data.hasOwnProperty("urls")) {
data = data.urls;
} else {
data = data
data = data;
}
if (Array.isArray(data)) {
url_list = data;
......@@ -41,58 +42,60 @@
url_list = Object.keys(data);
}
for (i = 0, i_len = url_list.length; i < i_len; i += 1) {
url = new String(url_list[i]);
url = String(url_list[i]);
if (url.indexOf(path_to_save) === 0) {
saved_number += 1;
promise_list.push(gadget.crib_sw_get(url));
};
};
}
}
return RSVP.all(promise_list);
})
.push(function(response_list) {
.push(function (response_list) {
var promise_list = [],
i, i_len, url, response, extension, zip;
zip = new JSZip();
for (i = 0, i_len = response_list.length; i < i_len; i += 1) {
response = response_list[i];
url = url_list[i].substr(path_to_save_length)
if ( url.endsWith("//") ) {
url = url_list[i].substr(path_to_save_length);
if (url.endsWith("//")) {
url = url.substr(0, url.length - 1);
}
if ( url.endsWith("/./") ) {
if (url.endsWith("/./")) {
url = url.substr(0, url.length - 2);
}
if ( url.endsWith("/") ) {
if (url.endsWith("/")) {
url = url + "index.html";
}
if ( url.startsWith("./") ) {
if (url.startsWith("./")) {
url = url.substr(1);
}
zip.file(url, response)
};
return zip.generateAsync({type:"blob"});
zip.file(url, response);
}
return zip.generateAsync({type: "blob"});
})
.push(function(content) {
return saveAs(content, application_id)
.push(function (content) {
return saveAs(content, application_id);
})
.push(function() {
gadget.props.element.querySelector(".crib-save-to-zip-status").textContent = "Saved " + saved_number + " files at "+ Date ()
.push(function () {
gadget.props.element.querySelector(".crib-save-to-zip-status")
.textContent = "Saved " + saved_number + " files at " + Date();
})
.push(console.log, console.log)
.push(console.log, console.log);
}
function loadContentFromZIP(gadget, event) {
var path_to_load, path_to_load_length, file_list, crib_sw_gadget,
jio_gadget, url_list = [], file, url_number = 0;
path_to_load = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-path').value
file_list = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-file').files
path_to_load = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-path').value;
file_list = gadget.props.element.querySelector('form.crib-load-from-zip .load-zip-file').files;
if (file_list.length === 0) {
gadget.props.element.querySelector(".crib-load-from-zip-status").textContent = "Please put a Zip at "+ Date ()
return
gadget.props.element.querySelector(".crib-load-from-zip-status")
.textContent = "Please put a Zip at " + Date();
return;
}
path_to_load_length = path_to_load.length;
file = file_list[0]
file = file_list[0];
return new RSVP.Queue()
.push(function () {
return JSZip.loadAsync(file);
......@@ -102,42 +105,43 @@
zip.forEach(function (relativePath, zipEntry) {
var end_url;
url_number += 1;
if ( zipEntry.dir ) {
return
if (zipEntry.dir) {
return;
}
if (!relativePath.startsWith("/") && !path_to_load.endsWith("/")) {
end_url = path_to_load + "/" + relativePath
end_url = path_to_load + "/" + relativePath;
} else if (relativePath.startsWith("/") && path_to_load.endsWith("/")) {
end_url = path_to_load + relativePath.substring(1);
} else {
end_url = path_to_load + relativePath
end_url = path_to_load + relativePath;
}
promise_list.push(
new RSVP.Queue().
push(function () {
new RSVP.Queue()
.push(function () {
return zipEntry.async('blob');
})
.push(function (result) {
if ( end_url.endsWith(".js") ) {
if (end_url.endsWith(".js")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "application/javascript")
} else if ( end_url.endsWith(".html") ) {
result = result.slice(0, result.size, "application/javascript");
} else if (end_url.endsWith(".html")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html")
} else if ( end_url.endsWith(".css") ) {
result = result.slice(0, result.size, "text/html");
} else if (end_url.endsWith(".css")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/css")
result = result.slice(0, result.size, "text/css");
}
return gadget.crib_sw_put(end_url, {blob: result})
})
)
return gadget.crib_sw_put(end_url, {blob: result});
})
return RSVP.all(promise_list)
);
});
return RSVP.all(promise_list);
})
.push(function() {
gadget.props.element.querySelector(".crib-load-from-zip-status").textContent = "Loaded " + url_number + " files at "+ Date ()
.push(function () {
gadget.props.element.querySelector(".crib-load-from-zip-status")
.textContent = "Loaded " + url_number + " files at " + Date();
})
.push(console.log, console.log)
.push(console.log, console.log);
}
rJS(window)
.ready(function (g) {
......@@ -161,7 +165,7 @@
return new RSVP.Queue()
.push(function () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -176,16 +180,16 @@
gadget.props.element.querySelector(".crib-save-to-zip"),
'submit',
false,
function (event) {saveContentToZIP(gadget, event)}
function (event) {saveContentToZIP(gadget, event); }
));
// promise to load content from ZIP
promise_list.push(loopEventListener(
gadget.props.element.querySelector(".crib-load-from-zip"),
'submit',
false,
function (event) {loadContentFromZIP(gadget, event)}
function (event) {loadContentFromZIP(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(window, rJS, loopEventListener, JSZip, FileSaver));
\ No newline at end of file
/*global window, rJS, loopEventListener */
/*global window, rJS, loopEventListener, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener) {
"use strict";
function setSiteGadgetUrl(gadget, event) {
var site_editor_gadget_url;
site_editor_gadget_url = gadget.props.element.querySelector('form.site-editor-gadget-url .url').value
site_editor_gadget_url = gadget.props.element.querySelector('form.site-editor-gadget-url .url').value;
return gadget.setSetting("site_editor_gadget_url", site_editor_gadget_url)
.push(function () {
gadget.props.element.querySelector(".crib-site-save-status").textContent = "Saved " + site_editor_gadget_url + " files at "+ Date ()
})
gadget.props.element.querySelector(".crib-site-save-status")
.textContent = "Saved " + site_editor_gadget_url + " files at " + Date();
});
}
rJS(window)
......@@ -34,12 +35,12 @@
return gadget.getSetting(
"site_editor_gadget_url",
getURL.protocol + "//" + getURL.host + "/crib-enable.html"
)
);
})
.push(function (site_editor_gadget_url) {
gadget.props.element.querySelector('form.site-editor-gadget-url .url').value = site_editor_gadget_url;
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -54,9 +55,9 @@
gadget.props.element.querySelector(".site-editor-gadget-url"),
'submit',
false,
function (event) {setSiteGadgetUrl(gadget, event)}
function (event) {setSiteGadgetUrl(gadget, event); }
));
return RSVP.all(promise_list);
});
})
});
}(window, rJS, loopEventListener));
\ No newline at end of file
/*global window, rJS, loopEventListener */
/*global window, rJS, loopEventListener, RSVP, console, document */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener) {
"use strict";
......@@ -7,15 +7,15 @@
var url_list;
return new RSVP.Queue()
.push(function () {
return gadget.crib_sw_allDocs()
return gadget.crib_sw_allDocs();
})
.push(function (data) {
var promise_list = [],
url;
if ( data.hasOwnProperty("urls") ) {
if (data.hasOwnProperty("urls")) {
url_list = data.urls;
} else {
url_list = data
url_list = data;
}
for (url in url_list) {
if (url_list.hasOwnProperty(url)) {
......@@ -24,7 +24,7 @@
}
return RSVP.all(promise_list);
})
.push(function(url_link_list) {
.push(function (url_link_list) {
var contentsElement = gadget.props.element.querySelector('.crib-url-list-content tbody'),
footer_element = gadget.props.element.querySelector('.crib-url-list-content tfoot'),
url_number = 0, cached_number = 0,
......@@ -40,7 +40,7 @@
var element;
trElement = document.createElement('tr');
tdElement = document.createElement('td');
tdElement.innerHTML = (url_list[url].cached ? "<span>&#x2713;</span>" : "")
tdElement.innerHTML = (url_list[url].cached ? "<span>&#x2713;</span>" : "");
trElement.appendChild(tdElement);
tdElement = document.createElement('td');
element = document.createElement('a');
......@@ -60,7 +60,7 @@
cached_number = url_list[url].cached ? cached_number + 1 : cached_number;
url_number += 1;
}
};
}
while (footer_element.firstChild) {
footer_element.removeChild(footer_element.firstChild);
}
......@@ -74,7 +74,7 @@
tdElement = document.createElement('td');
trElement.appendChild(tdElement);
footer_element.appendChild(trElement);
})
});
}
rJS(window)
......@@ -91,7 +91,7 @@
.declareMethod('render', function (options) {
var gadget = this;
if (options === undefined)
options = {}
options = {};
gadget.props.options = options;
return new RSVP.Queue()
.push(function () {
......@@ -99,7 +99,7 @@
})
.push(function () {
return gadget.props.start_deferred.resolve();
})
});
})
.declareService(function () {
var gadget = this;
......@@ -112,8 +112,8 @@
gadget.props.element.querySelector(".crib-url-list-content"),
'submit',
false,
function (event) {displayURLList(gadget, event)}
)
function (event) {displayURLList(gadget, event); }
);
});
});
})
}(window, rJS, loopEventListener));
\ No newline at end of file
/*global window, rJS */
/*global window, rJS, document, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS) {
(function (window, rJS, loopEventListener) {
"use strict";
var gadget_klass = rJS(window),
......@@ -54,7 +54,7 @@
};
})
.declareMethod("getCommandUrlFor", function(options) {
.declareMethod("getCommandUrlFor", function (options) {
var prefix = '',
result,
key;
......@@ -116,9 +116,9 @@
);
}
return {
url: MAIN_PAGE_PREFIX + "jio_"
+ base_portal_type
+ "_" + args.page + ".html",
url: MAIN_PAGE_PREFIX + "jio_" +
base_portal_type +
"_" + args.page + ".html",
options: sub_options
};
});
......@@ -140,4 +140,4 @@
});
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, loopEventListener));
\ No newline at end of file
/*globals window, document, RSVP, rJS,
location, console*/
/*jslint indent: 2, maxlen: 80*/
/*jslint browser: true, indent: 2, maxlen: 80*/
/*globals RSVP, rJS,
location, console, fetch, Promise*/
(function (window, document, RSVP, rJS, location, console, JSZip) {
"use strict";
......@@ -13,8 +13,9 @@
}
function getSetting(gadget, key, default_value) {
if ( key === "site_editor_gadget_url" ) {
return window.location.protocol + "//" + window.location.host + "/crib-enable.html"
if (key === "site_editor_gadget_url") {
return window.location.protocol + "//" + window.location.host +
"/crib-enable.html";
}
return default_value;
}
......@@ -24,41 +25,41 @@
zip.forEach(function (relativePath, zipEntry) {
var end_url;
url_number += 1;
if ( zipEntry.dir ) {
return
if (zipEntry.dir) {
return;
}
if ( !relativePath.startsWith(from_path) ) {
return
if (!relativePath.startsWith(from_path)) {
return;
}
relativePath = relativePath.substring(from_path.length);
if (!relativePath.startsWith("/") && !path_to_load.endsWith("/")) {
end_url = path_to_load + "/" + relativePath
end_url = path_to_load + "/" + relativePath;
} else if (relativePath.startsWith("/") && path_to_load.endsWith("/")) {
end_url = path_to_load + relativePath.substring(1);
} else {
end_url = path_to_load + relativePath
end_url = path_to_load + relativePath;
}
promise_list.push(
new RSVP.Queue().
push(function () {
new RSVP.Queue()
.push(function () {
return zipEntry.async('blob');
})
.push(function (result) {
if ( end_url.endsWith(".js") ) {
if (end_url.endsWith(".js")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "application/javascript")
} else if ( end_url.endsWith(".html") ) {
result = result.slice(0, result.size, "application/javascript");
} else if (end_url.endsWith(".html")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html")
} else if ( end_url.endsWith(".css") ) {
result = result.slice(0, result.size, "text/html");
} else if (end_url.endsWith(".css")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/css")
result = result.slice(0, result.size, "text/css");
}
return crib_sw_gadget.put(end_url, {blob: result})
})
)
return crib_sw_gadget.put(end_url, {blob: result});
})
return RSVP.all(promise_list)
);
});
return RSVP.all(promise_list);
}
function loadContentFromZIPFile(gadget, options) {
......@@ -76,9 +77,11 @@
]);
})
.push(function (result_list) {
return loadZipIntoCrib(result_list[0], result_list[1], from_path, path_to_load);
return loadZipIntoCrib(
result_list[0], result_list[1], from_path, path_to_load
);
})
.push(console.log, console.log)
.push(console.log, console.log);
}
......@@ -105,7 +108,7 @@
.push(function (zip) {
return loadZipIntoCrib(crib_sw_gadget, zip, from_path, path_to_load);
})
.push(console.log, console.log)
.push(console.log, console.log);
}
rJS(window)
......@@ -120,6 +123,6 @@
})
.allowPublicAcquisition("getSetting", function (argument_list) {
return getSetting(this, argument_list[0], argument_list[1]);
})
});
}(window, document, RSVP, rJS, location, console, JSZip));
\ No newline at end of file
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