Intermediate commit before switching to React
parent
48073c0a0c
commit
4dd5bf7d59
@ -0,0 +1,47 @@
|
||||
notification-box
|
||||
notification(each="{notification in notifications}", notification="{notification}")
|
||||
|
||||
script.
|
||||
const defaultValue = require("default-value");
|
||||
|
||||
Object.assign(this, {
|
||||
notifications: [{
|
||||
title: "Foo bar!",
|
||||
//message: "Bar bar baz foo. Bar.",
|
||||
type: "info",
|
||||
icon: "info-circle"
|
||||
}, {
|
||||
title: "Whoopteedoo",
|
||||
//message: "Boop boop woop whoop toop boop!",
|
||||
type: "error",
|
||||
icon: "exclamation-circle"
|
||||
}],
|
||||
add: function addNotification(title, options = {}) {
|
||||
let notificationObject = {
|
||||
title: title,
|
||||
message: options.message,
|
||||
type: defaultValue(options.type, "info"),
|
||||
icon: options.icon,
|
||||
options: options
|
||||
};
|
||||
|
||||
this.notifications.push(notificationObject);
|
||||
|
||||
if (options.timeout != null) {
|
||||
setTimeout(() => {
|
||||
this.remove(notificationObject);
|
||||
}, options.timeout);
|
||||
}
|
||||
|
||||
this.update();
|
||||
},
|
||||
remove: function removeNotification(notificationObject) {
|
||||
let notificationIndex = this.notifications.indexOf(notificationObject);
|
||||
|
||||
// TODO: Fade/collapse animation?
|
||||
if (notificationIndex !== -1) {
|
||||
this.notifications.splice(notificationIndex, 1);
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
})
|
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
require("../notification");
|
||||
|
||||
require("./component");
|
@ -0,0 +1,88 @@
|
||||
notification(class="type-{opts.notification.type}")
|
||||
.contents
|
||||
.header
|
||||
button.close: i.fa.fa-times
|
||||
i.icon.fa(class="fa-{opts.notification.icon}")
|
||||
| { opts.notification.title }
|
||||
|
||||
.message(if="{opts.notification.message != null}") { opts.notification.message }
|
||||
|
||||
style(type="scss").
|
||||
:scope {
|
||||
display: block;
|
||||
text-align: right;
|
||||
|
||||
.close {
|
||||
display: none; // FIXME
|
||||
float: right;
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 1px 3px;
|
||||
font-size: 12px;
|
||||
color: rgb(190, 190, 190);
|
||||
border: 1px solid rgb(190, 190, 190);
|
||||
border-radius: 4px;
|
||||
|
||||
&:hover {
|
||||
color: white;
|
||||
border-color: white;
|
||||
}
|
||||
}
|
||||
|
||||
.contents {
|
||||
text-align: left;
|
||||
display: inline-block;
|
||||
border-radius: 6px;
|
||||
margin-right: 19px;
|
||||
margin-top: 10px;
|
||||
padding: 9px 14px;
|
||||
color: white;
|
||||
font-size: 15px;
|
||||
filter: alpha(opacity=85);
|
||||
opacity: 0.85;
|
||||
width: auto;
|
||||
background-color: black;
|
||||
|
||||
.header {
|
||||
margin-right: 6px;
|
||||
font-weight: bold;
|
||||
|
||||
.icon {
|
||||
font-size: 19px;
|
||||
margin-right: 9px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.message {
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
&.type-error {
|
||||
.contents {
|
||||
background-color: #371B1B;
|
||||
|
||||
.header .icon {
|
||||
color: #FFD2D2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.type-info {
|
||||
.contents {
|
||||
background-color: #2D2D2D;
|
||||
|
||||
.header .icon {
|
||||
color: #CBCAFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* From old code, but purpose unclear:
|
||||
.notification-popup ul, .error-popup ul
|
||||
{
|
||||
margin: 4px 0px;
|
||||
padding-left: 48px;
|
||||
}
|
||||
*/
|
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
require("./component");
|
@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
function isObject(value) {
|
||||
return (value === Object(value));
|
||||
}
|
||||
|
||||
function makeArrayKey(key) {
|
||||
if (key.length > 2 && key.lastIndexOf('[]') === key.length - 2) {
|
||||
return key
|
||||
} else {
|
||||
return key + '[]'
|
||||
}
|
||||
}
|
||||
|
||||
function generateKey(prefix, key) {
|
||||
if (prefix == null || prefix.length === 0) {
|
||||
return key;
|
||||
} else {
|
||||
return `${prefix}[${key}]`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function deconstructFormObject(object, prefix) {
|
||||
return Object.keys(object).reduce((items, key) => {
|
||||
let value = object[key];
|
||||
let newItems = [];
|
||||
|
||||
function transformValue(value, isInArray) {
|
||||
let valueKey;
|
||||
|
||||
if (isInArray) {
|
||||
valueKey = makeArrayKey(generateKey(prefix, key));
|
||||
} else {
|
||||
valueKey = generateKey(prefix, key);
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((arrayItem) => {
|
||||
transformValue(arrayItem, true);
|
||||
});
|
||||
} else if (isObject(value)) {
|
||||
newItems = newItems.concat(deconstructFormObject(value, valueKey));
|
||||
} else {
|
||||
newItems.push({
|
||||
name: valueKey,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
transformValue(value);
|
||||
|
||||
return items.concat(newItems);
|
||||
}, []);
|
||||
};
|
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const Promise = require("bluebird");
|
||||
const stateRouter = require("../riot/state-router");
|
||||
|
||||
module.exports = function createRouter() {
|
||||
let router = stateRouter();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
let text;
|
||||
|
||||
if (req.query.target != null) {
|
||||
text = req.query.target;
|
||||
} else {
|
||||
text = "World";
|
||||
}
|
||||
|
||||
res.render("sample", {
|
||||
text: `Hello ${text}!`
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/nodes/create", (req, res) => {
|
||||
res.render("node-create");
|
||||
});
|
||||
|
||||
router.post("/nodes/create", (req, res) => {
|
||||
return Promise.try(() => {
|
||||
return req.pass();
|
||||
}).then((response) => {
|
||||
console.log(response.body);
|
||||
});
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const deconstructFormObject = require("./deconstruct-form-object");
|
||||
|
||||
module.exports = function objectToFormData(object) {
|
||||
let formData = new FormData();
|
||||
|
||||
deconstructFormObject(object).forEach((item) => {
|
||||
formData.append(item.name, item.value)
|
||||
});
|
||||
|
||||
return formData;
|
||||
};
|
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const deconstructFormObject = require("./deconstruct-form-object");
|
||||
|
||||
module.exports = function objectToURLSearchParams(object) {
|
||||
let params = new URLSearchParams();
|
||||
|
||||
deconstructFormObject(object).forEach((item) => {
|
||||
params.append(item.name, item.value)
|
||||
});
|
||||
|
||||
return params;
|
||||
};
|
Binary file not shown.
Loading…
Reference in New Issue