voom-presenters 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/.ruby-version +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +104 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/ROADMAP.md +21 -0
- data/Rakefile +6 -0
- data/app/demo/component_status.pom +76 -0
- data/app/demo/components.pom +19 -0
- data/app/demo/components/badges.pom +25 -0
- data/app/demo/components/buttons.pom +51 -0
- data/app/demo/components/cards.pom +79 -0
- data/app/demo/components/chips.pom +91 -0
- data/app/demo/components/dialogs.pom +27 -0
- data/app/demo/components/drawers.pom +34 -0
- data/app/demo/components/expansion_panels.pom +21 -0
- data/app/demo/components/fabs-mini.pom +18 -0
- data/app/demo/components/fabs.pom +16 -0
- data/app/demo/components/footers.pom +36 -0
- data/app/demo/components/forms.pom +30 -0
- data/app/demo/components/headers.pom +37 -0
- data/app/demo/components/hidden_fields.pom +20 -0
- data/app/demo/components/icons.pom +94 -0
- data/app/demo/components/layouts.pom +44 -0
- data/app/demo/components/lists.pom +124 -0
- data/app/demo/components/menus.pom +43 -0
- data/app/demo/components/nav/drawer.pom +5 -0
- data/app/demo/components/nav/menu.pom +15 -0
- data/app/demo/components/selects.pom +30 -0
- data/app/demo/components/snackbar.pom +24 -0
- data/app/demo/components/snackbar_attached.pom +6 -0
- data/app/demo/components/tables.pom +39 -0
- data/app/demo/components/text_areas.pom +19 -0
- data/app/demo/components/text_fields.pom +57 -0
- data/app/demo/components/toggles.pom +29 -0
- data/app/demo/components/tooltips.pom +120 -0
- data/app/demo/event/actions.rb +86 -0
- data/app/demo/event/actions/dialog/show_dialog.pom +9 -0
- data/app/demo/event/actions/dialog/trigger.pom +86 -0
- data/app/demo/event/actions/nav/drawer.pom +5 -0
- data/app/demo/event/actions/nav/menu.pom +19 -0
- data/app/demo/event/autocomplete.pom +27 -0
- data/app/demo/event/field_level.pom +22 -0
- data/app/demo/event/form_level.pom +26 -0
- data/app/demo/event/nav/drawer.pom +5 -0
- data/app/demo/event/nav/menu.pom +14 -0
- data/app/demo/event/new_text.pom +6 -0
- data/app/demo/events.pom +98 -0
- data/app/demo/helpers/indented_grid.rb +14 -0
- data/app/demo/index.pom +19 -0
- data/app/demo/markdown.pom +73 -0
- data/app/demo/nav/top_nav.pom +42 -0
- data/app/demo/shared/code.pom +20 -0
- data/app/demo/shared/context_list.pom +29 -0
- data/app/demo/shared/debug.pom +17 -0
- data/app/demo/styles.pom +26 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/component-status.yml +219 -0
- data/config.ru +21 -0
- data/lib/voom-presenters.rb +9 -0
- data/lib/voom/container_methods.rb +40 -0
- data/lib/voom/logger_methods.rb +11 -0
- data/lib/voom/parameters.rb +73 -0
- data/lib/voom/presenters-engine.rb +40 -0
- data/lib/voom/presenters.rb +13 -0
- data/lib/voom/presenters/api/app.rb +53 -0
- data/lib/voom/presenters/api/router.rb +94 -0
- data/lib/voom/presenters/app.rb +55 -0
- data/lib/voom/presenters/container_item.rb +16 -0
- data/lib/voom/presenters/demo/echo.rb +29 -0
- data/lib/voom/presenters/demo/search-terms.yml +50 -0
- data/lib/voom/presenters/demo/search.rb +29 -0
- data/lib/voom/presenters/dsl.rb +60 -0
- data/lib/voom/presenters/dsl/components/action.rb +35 -0
- data/lib/voom/presenters/dsl/components/avatar.rb +27 -0
- data/lib/voom/presenters/dsl/components/badge.rb +21 -0
- data/lib/voom/presenters/dsl/components/base.rb +78 -0
- data/lib/voom/presenters/dsl/components/button.rb +49 -0
- data/lib/voom/presenters/dsl/components/card.rb +119 -0
- data/lib/voom/presenters/dsl/components/checkbox.rb +16 -0
- data/lib/voom/presenters/dsl/components/chip.rb +48 -0
- data/lib/voom/presenters/dsl/components/content.rb +33 -0
- data/lib/voom/presenters/dsl/components/date_time.rb +17 -0
- data/lib/voom/presenters/dsl/components/dialog.rb +50 -0
- data/lib/voom/presenters/dsl/components/drawer.rb +40 -0
- data/lib/voom/presenters/dsl/components/event.rb +101 -0
- data/lib/voom/presenters/dsl/components/event_base.rb +20 -0
- data/lib/voom/presenters/dsl/components/expansion_panel.rb +46 -0
- data/lib/voom/presenters/dsl/components/footer.rb +25 -0
- data/lib/voom/presenters/dsl/components/form.rb +42 -0
- data/lib/voom/presenters/dsl/components/grid.rb +64 -0
- data/lib/voom/presenters/dsl/components/header.rb +33 -0
- data/lib/voom/presenters/dsl/components/hidden_field.rb +25 -0
- data/lib/voom/presenters/dsl/components/icon.rb +21 -0
- data/lib/voom/presenters/dsl/components/icon_base.rb +24 -0
- data/lib/voom/presenters/dsl/components/icon_toggle.rb +21 -0
- data/lib/voom/presenters/dsl/components/image.rb +36 -0
- data/lib/voom/presenters/dsl/components/input.rb +19 -0
- data/lib/voom/presenters/dsl/components/list.rb +39 -0
- data/lib/voom/presenters/dsl/components/lists/action.rb +72 -0
- data/lib/voom/presenters/dsl/components/lists/line.rb +83 -0
- data/lib/voom/presenters/dsl/components/lists/separator.rb +16 -0
- data/lib/voom/presenters/dsl/components/menu.rb +66 -0
- data/lib/voom/presenters/dsl/components/mixins/append.rb +20 -0
- data/lib/voom/presenters/dsl/components/mixins/attaches.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/avatar.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/buttons.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/chips.rb +21 -0
- data/lib/voom/presenters/dsl/components/mixins/common.rb +50 -0
- data/lib/voom/presenters/dsl/components/mixins/content.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/dialogs.rb +19 -0
- data/lib/voom/presenters/dsl/components/mixins/event.rb +19 -0
- data/lib/voom/presenters/dsl/components/mixins/expansion_panels.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/grids.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/helpers.rb +20 -0
- data/lib/voom/presenters/dsl/components/mixins/icons.rb +17 -0
- data/lib/voom/presenters/dsl/components/mixins/images.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/menus.rb +15 -0
- data/lib/voom/presenters/dsl/components/mixins/selects.rb +17 -0
- data/lib/voom/presenters/dsl/components/mixins/snackbars.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/text_fields.rb +35 -0
- data/lib/voom/presenters/dsl/components/mixins/toggles.rb +40 -0
- data/lib/voom/presenters/dsl/components/mixins/tooltips.rb +18 -0
- data/lib/voom/presenters/dsl/components/mixins/typography.rb +37 -0
- data/lib/voom/presenters/dsl/components/page.rb +29 -0
- data/lib/voom/presenters/dsl/components/radio_button.rb +14 -0
- data/lib/voom/presenters/dsl/components/select.rb +64 -0
- data/lib/voom/presenters/dsl/components/snackbar.rb +32 -0
- data/lib/voom/presenters/dsl/components/switch.rb +14 -0
- data/lib/voom/presenters/dsl/components/table.rb +102 -0
- data/lib/voom/presenters/dsl/components/text_area.rb +20 -0
- data/lib/voom/presenters/dsl/components/text_field.rb +74 -0
- data/lib/voom/presenters/dsl/components/toggle_base.rb +26 -0
- data/lib/voom/presenters/dsl/components/tooltip.rb +25 -0
- data/lib/voom/presenters/dsl/components/typography.rb +25 -0
- data/lib/voom/presenters/dsl/definer.rb +13 -0
- data/lib/voom/presenters/dsl/definition.rb +31 -0
- data/lib/voom/presenters/dsl/invalid_presenter.rb +8 -0
- data/lib/voom/presenters/dsl/lockable.rb +15 -0
- data/lib/voom/presenters/dsl/user_interface.rb +135 -0
- data/lib/voom/presenters/errors/parameter_validation.rb +10 -0
- data/lib/voom/presenters/errors/unprocessable.rb +8 -0
- data/lib/voom/presenters/helpers.rb +18 -0
- data/lib/voom/presenters/helpers/currency.rb +14 -0
- data/lib/voom/presenters/helpers/date.rb +22 -0
- data/lib/voom/presenters/helpers/errors.rb +11 -0
- data/lib/voom/presenters/helpers/inflector.rb +16 -0
- data/lib/voom/presenters/helpers/rails.rb +60 -0
- data/lib/voom/presenters/helpers/route.rb +11 -0
- data/lib/voom/presenters/helpers/time.rb +27 -0
- data/lib/voom/presenters/settings.rb +35 -0
- data/lib/voom/presenters/version.rb +5 -0
- data/lib/voom/presenters/web_client/app.rb +128 -0
- data/lib/voom/presenters/web_client/markdown_render.rb +16 -0
- data/lib/voom/presenters/web_client/router.rb +96 -0
- data/lib/voom/serializer.rb +43 -0
- data/lib/voom/symbol/to_str.rb +29 -0
- data/lib/voom/trace.rb +19 -0
- data/presenters.gemspec +37 -0
- data/public/.gitignore +2 -0
- data/public/bundle.css +11413 -0
- data/public/bundle.js +16456 -0
- data/public/dialog-polyfill.js +738 -0
- data/public/favicon.ico +0 -0
- data/public/img/demo/dog.png +0 -0
- data/public/img/demo/image_card.jpg +0 -0
- data/public/img/demo/rx.png +0 -0
- data/public/img/demo/welcome_card.jpg +0 -0
- data/public/img/settings/blue.png +0 -0
- data/public/img/settings/green.png +0 -0
- data/public/img/settings/orange.png +0 -0
- data/public/img/settings/purple.png +0 -0
- data/public/img/settings/red.png +0 -0
- data/public/img/settings/teal.png +0 -0
- data/public/img/settings/white.png +0 -0
- data/public/img/settings/yellow.png +0 -0
- data/public/scripts.js +289 -0
- data/public/style-bundle.js +73 -0
- data/public/styles.css +16 -0
- data/views/mdc/.gitignore +1 -0
- data/views/mdc/assets/js/app.js +10 -0
- data/views/mdc/assets/js/components/base-component.js +5 -0
- data/views/mdc/assets/js/components/button.js +15 -0
- data/views/mdc/assets/js/components/cards.js +3 -0
- data/views/mdc/assets/js/components/checkboxes.js +15 -0
- data/views/mdc/assets/js/components/chips.js +12 -0
- data/views/mdc/assets/js/components/date-time.js +6 -0
- data/views/mdc/assets/js/components/dialogs.js +32 -0
- data/views/mdc/assets/js/components/events.js +151 -0
- data/views/mdc/assets/js/components/events/autocomplete.js +96 -0
- data/views/mdc/assets/js/components/events/base.js +41 -0
- data/views/mdc/assets/js/components/events/dialog.js +25 -0
- data/views/mdc/assets/js/components/events/errors.js +142 -0
- data/views/mdc/assets/js/components/events/loads.js +22 -0
- data/views/mdc/assets/js/components/events/navigates.js +17 -0
- data/views/mdc/assets/js/components/events/posts.js +99 -0
- data/views/mdc/assets/js/components/events/replaces.js +82 -0
- data/views/mdc/assets/js/components/events/selects.js +28 -0
- data/views/mdc/assets/js/components/events/snackbar.js +23 -0
- data/views/mdc/assets/js/components/events/toggle_visiblity.js +19 -0
- data/views/mdc/assets/js/components/forms.js +57 -0
- data/views/mdc/assets/js/components/icon-toggles.js +21 -0
- data/views/mdc/assets/js/components/initialize.js +34 -0
- data/views/mdc/assets/js/components/lists.js +4 -0
- data/views/mdc/assets/js/components/menus.js +31 -0
- data/views/mdc/assets/js/components/mixins/event-handler.js +13 -0
- data/views/mdc/assets/js/components/selects.js +45 -0
- data/views/mdc/assets/js/components/snackbar.js +32 -0
- data/views/mdc/assets/js/components/text-fields.js +77 -0
- data/views/mdc/assets/js/dialog-polyfill.js +738 -0
- data/views/mdc/assets/js/material.js +3996 -0
- data/views/mdc/assets/js/utils/urls.js +54 -0
- data/views/mdc/assets/scss/app.scss +31 -0
- data/views/mdc/assets/scss/components/avatar.scss +41 -0
- data/views/mdc/assets/scss/components/button.scss +47 -0
- data/views/mdc/assets/scss/components/card.scss +54 -0
- data/views/mdc/assets/scss/components/checkbox.scss +5 -0
- data/views/mdc/assets/scss/components/chip.scss +30 -0
- data/views/mdc/assets/scss/components/datetime.scss +0 -0
- data/views/mdc/assets/scss/components/dialog.scss +3 -0
- data/views/mdc/assets/scss/components/expansion-panel.scss +153 -0
- data/views/mdc/assets/scss/components/fab.scss +8 -0
- data/views/mdc/assets/scss/components/grid.scss +10 -0
- data/views/mdc/assets/scss/components/icon-toggles.scss +9 -0
- data/views/mdc/assets/scss/components/icon.scss +34 -0
- data/views/mdc/assets/scss/components/image.scss +24 -0
- data/views/mdc/assets/scss/components/list.scss +9 -0
- data/views/mdc/assets/scss/components/menu.scss +17 -0
- data/views/mdc/assets/scss/components/select.scss +16 -0
- data/views/mdc/assets/scss/components/snackbar.scss +5 -0
- data/views/mdc/assets/scss/components/switch.scss +6 -0
- data/views/mdc/assets/scss/components/table-pagination.scss +65 -0
- data/views/mdc/assets/scss/components/textfield.scss +1 -0
- data/views/mdc/assets/scss/components/typography.scss +25 -0
- data/views/mdc/assets/scss/material.blue_grey-orange.min.css +8 -0
- data/views/mdc/assets/scss/styles.scss +11 -0
- data/views/mdc/assets/scss/theme.scss +5 -0
- data/views/mdc/body/drawer.erb +18 -0
- data/views/mdc/body/drawers/menu.erb +25 -0
- data/views/mdc/body/footer.erb +1 -0
- data/views/mdc/body/footers/large.erb +27 -0
- data/views/mdc/body/footers/menu_item.erb +6 -0
- data/views/mdc/body/footers/small.erb +14 -0
- data/views/mdc/body/header.erb +25 -0
- data/views/mdc/body/snackbar.erb +10 -0
- data/views/mdc/components/avatar.erb +24 -0
- data/views/mdc/components/badge.erb +2 -0
- data/views/mdc/components/body.erb +2 -0
- data/views/mdc/components/button.erb +17 -0
- data/views/mdc/components/buttons/button.erb +20 -0
- data/views/mdc/components/buttons/fab.erb +22 -0
- data/views/mdc/components/buttons/icon.erb +24 -0
- data/views/mdc/components/card.erb +49 -0
- data/views/mdc/components/checkbox.erb +22 -0
- data/views/mdc/components/chip.erb +31 -0
- data/views/mdc/components/content.erb +11 -0
- data/views/mdc/components/date_time.erb +30 -0
- data/views/mdc/components/dialog.erb +27 -0
- data/views/mdc/components/display.erb +2 -0
- data/views/mdc/components/event.erb +18 -0
- data/views/mdc/components/expansion_panel.erb +11 -0
- data/views/mdc/components/form.erb +15 -0
- data/views/mdc/components/grid.erb +24 -0
- data/views/mdc/components/headline.erb +2 -0
- data/views/mdc/components/hidden_field.erb +1 -0
- data/views/mdc/components/icon.erb +30 -0
- data/views/mdc/components/icon_toggle.erb +15 -0
- data/views/mdc/components/image.erb +7 -0
- data/views/mdc/components/link.erb +14 -0
- data/views/mdc/components/list.erb +14 -0
- data/views/mdc/components/list/actions.erb +6 -0
- data/views/mdc/components/list/actions/button.erb +1 -0
- data/views/mdc/components/list/actions/checkbox.erb +1 -0
- data/views/mdc/components/list/actions/icon.erb +1 -0
- data/views/mdc/components/list/actions/icon_toggle.erb +1 -0
- data/views/mdc/components/list/actions/radio_button.erb +1 -0
- data/views/mdc/components/list/actions/switch.erb +1 -0
- data/views/mdc/components/list/avatar.erb +5 -0
- data/views/mdc/components/list/checkbox.erb +5 -0
- data/views/mdc/components/list/icon.erb +5 -0
- data/views/mdc/components/list/info.erb +1 -0
- data/views/mdc/components/list/line.erb +34 -0
- data/views/mdc/components/list/menu.erb +23 -0
- data/views/mdc/components/list/separator.erb +1 -0
- data/views/mdc/components/menu.erb +29 -0
- data/views/mdc/components/modal.erb +15 -0
- data/views/mdc/components/radio_button.erb +11 -0
- data/views/mdc/components/render.erb +4 -0
- data/views/mdc/components/select.erb +22 -0
- data/views/mdc/components/snackbar.erb +17 -0
- data/views/mdc/components/static.erb +7 -0
- data/views/mdc/components/subheading.erb +2 -0
- data/views/mdc/components/switch.erb +13 -0
- data/views/mdc/components/table.erb +13 -0
- data/views/mdc/components/table/header.erb +7 -0
- data/views/mdc/components/table/pagination.erb +24 -0
- data/views/mdc/components/table/row.erb +14 -0
- data/views/mdc/components/text_area.erb +8 -0
- data/views/mdc/components/text_field.erb +27 -0
- data/views/mdc/components/title.erb +4 -0
- data/views/mdc/components/tooltip.erb +5 -0
- data/views/mdc/components/typography.erb +13 -0
- data/views/mdc/init-depends.sh +2 -0
- data/views/mdc/layout.erb +50 -0
- data/views/mdc/package-lock.json +11524 -0
- data/views/mdc/package.json +39 -0
- data/views/mdc/web.erb +1 -0
- data/views/mdc/webpack.config.js +47 -0
- metadata +539 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
import {VUrls} from '../../utils/urls';
|
2
|
+
|
3
|
+
export class VLoads extends VUrls{
|
4
|
+
constructor(options, url, params, event) {
|
5
|
+
super();
|
6
|
+
this.options = options;
|
7
|
+
this.params = params;
|
8
|
+
this.url = url;
|
9
|
+
this.event = event;
|
10
|
+
}
|
11
|
+
|
12
|
+
call(results) {
|
13
|
+
var url = this.buildURL(this.url, this.params);
|
14
|
+
var promiseObj = new Promise(function (resolve) {
|
15
|
+
console.log("Loading page: " + url);
|
16
|
+
results.push({action:'loads', statusCode: 200});
|
17
|
+
resolve(results);
|
18
|
+
window.location = url;
|
19
|
+
});
|
20
|
+
return promiseObj;
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export class VNavigates {
|
2
|
+
constructor(options, params, event) {
|
3
|
+
this.target = options.target;
|
4
|
+
this.params = params;
|
5
|
+
this.event = event;
|
6
|
+
}
|
7
|
+
|
8
|
+
call(results) {
|
9
|
+
var promiseObj = new Promise(function (resolve) {
|
10
|
+
console.log("Navigating back");
|
11
|
+
results.push({action: 'navigates', statusCode: 200});
|
12
|
+
history.back();
|
13
|
+
resolve(results);
|
14
|
+
});
|
15
|
+
return promiseObj;
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import {VSnackbar} from '../snackbar';
|
2
|
+
import {VBase} from './base';
|
3
|
+
|
4
|
+
// Replaces a given element with the contents of the call to the url.
|
5
|
+
// parameters are appended.
|
6
|
+
export class VPosts extends VBase {
|
7
|
+
constructor(options, url, params, method, event) {
|
8
|
+
super(options);
|
9
|
+
this.url = url;
|
10
|
+
this.params = params;
|
11
|
+
this.method = method;
|
12
|
+
this.event = event;
|
13
|
+
}
|
14
|
+
|
15
|
+
call(results) {
|
16
|
+
this.clearErrors();
|
17
|
+
let errors = this.validate();
|
18
|
+
let method = this.method;
|
19
|
+
if (errors.length > 0) {
|
20
|
+
return new Promise(function (_, reject) {
|
21
|
+
results.push({
|
22
|
+
action: 'posts',
|
23
|
+
method: method,
|
24
|
+
statusCode: 400,
|
25
|
+
contentType: 'v/errors',
|
26
|
+
content: errors
|
27
|
+
});
|
28
|
+
reject(results);
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
var FD = null;
|
33
|
+
var form = this.form();
|
34
|
+
if (form) {
|
35
|
+
FD = new FormData(form);
|
36
|
+
} else {
|
37
|
+
FD = new FormData();
|
38
|
+
}
|
39
|
+
// Add params from presenter
|
40
|
+
for (var name in this.params) {
|
41
|
+
FD.append(name, this.params[name]);
|
42
|
+
}
|
43
|
+
|
44
|
+
var inputValues = this.inputValues(form);
|
45
|
+
for (var input of inputValues) {
|
46
|
+
FD.append(input[0], input[1]);
|
47
|
+
}
|
48
|
+
|
49
|
+
var httpRequest = new XMLHttpRequest();
|
50
|
+
var url = this.url;
|
51
|
+
if (!httpRequest) {
|
52
|
+
throw new Error('Cannot talk to server! Please upgrade your browser to one that supports XMLHttpRequest.');
|
53
|
+
}
|
54
|
+
return new Promise(function (resolve, reject) {
|
55
|
+
httpRequest.onreadystatechange = function (event) {
|
56
|
+
if (httpRequest.readyState === XMLHttpRequest.DONE) {
|
57
|
+
console.log(httpRequest.status + ':' + this.getResponseHeader('content-type'));
|
58
|
+
if (httpRequest.status >= 200 && httpRequest.status < 300) {
|
59
|
+
results.push({
|
60
|
+
action: 'posts',
|
61
|
+
method: this.method,
|
62
|
+
statusCode: httpRequest.status,
|
63
|
+
contentType: this.getResponseHeader('content-type'),
|
64
|
+
content: httpRequest.responseText,
|
65
|
+
responseURL: httpRequest.responseURL
|
66
|
+
});
|
67
|
+
resolve(results);
|
68
|
+
} else {
|
69
|
+
results.push({
|
70
|
+
action: 'posts',
|
71
|
+
method: this.method,
|
72
|
+
statusCode: httpRequest.status,
|
73
|
+
contentType: this.getResponseHeader('content-type'),
|
74
|
+
content: httpRequest.responseText
|
75
|
+
});
|
76
|
+
reject(results);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
};
|
80
|
+
// Set up our request
|
81
|
+
httpRequest.open(method, url);
|
82
|
+
console.log(method + ':' + url);
|
83
|
+
// Send our FormData object; HTTP headers are set automatically
|
84
|
+
httpRequest.send(FD);
|
85
|
+
});
|
86
|
+
}
|
87
|
+
|
88
|
+
isForm() {
|
89
|
+
var parentElement = this.parentElement();
|
90
|
+
return parentElement && parentElement.elements;
|
91
|
+
}
|
92
|
+
|
93
|
+
form() {
|
94
|
+
if (this.isForm()) {
|
95
|
+
return this.parentElement();
|
96
|
+
}
|
97
|
+
return null;
|
98
|
+
}
|
99
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import {VSnackbar} from '../snackbar';
|
2
|
+
import {VBase} from './base';
|
3
|
+
import {initialize} from '../initialize';
|
4
|
+
|
5
|
+
// Replaces a given element with the contents of the call to the url.
|
6
|
+
// parameters are appended.
|
7
|
+
export class VReplaces extends VBase {
|
8
|
+
constructor(options, url, params, event) {
|
9
|
+
super(options);
|
10
|
+
this.element_id = options.target;
|
11
|
+
this.url = url;
|
12
|
+
this.params = params;
|
13
|
+
this.event = event;
|
14
|
+
}
|
15
|
+
|
16
|
+
call(results) {
|
17
|
+
this.clearErrors();
|
18
|
+
console.log('The event: '+this.event);
|
19
|
+
var httpRequest = new XMLHttpRequest();
|
20
|
+
if (!httpRequest) {
|
21
|
+
throw new Error('Cannot talk to server! Please upgrade your browser to one that supports XMLHttpRequest.');
|
22
|
+
}
|
23
|
+
var elementId = this.element_id;
|
24
|
+
var parentElement = this.parentElement();
|
25
|
+
var url = this.buildURL(this.url, this.params, this.inputValues(), [['grid_nesting', this.options.grid_nesting]]);
|
26
|
+
|
27
|
+
let delayAmt = this.event instanceof InputEvent ? 500 : 0;
|
28
|
+
|
29
|
+
var promiseObj = new Promise(function (resolve, reject) {
|
30
|
+
clearTimeout(parentElement.vTimeout);
|
31
|
+
parentElement.vTimeout = setTimeout(function(){
|
32
|
+
httpRequest.onreadystatechange = function () {
|
33
|
+
if (httpRequest.readyState === XMLHttpRequest.DONE) {
|
34
|
+
console.log(httpRequest.status + ':' + this.getResponseHeader('content-type'));
|
35
|
+
if (httpRequest.status === 200) {
|
36
|
+
var nodeToReplace = document.getElementById(elementId);
|
37
|
+
if (!nodeToReplace) {
|
38
|
+
let msg = 'Unable to located node: \'' + elementId + '\'' +
|
39
|
+
' This usually the result of issuing a replaces action and specifying a element id that does not currently exist on the page.';
|
40
|
+
console.error(msg);
|
41
|
+
results.push({
|
42
|
+
action: 'replaces',
|
43
|
+
statusCode: 500,
|
44
|
+
contentType: 'v/errors',
|
45
|
+
content: {exception: msg}
|
46
|
+
});
|
47
|
+
reject(results);
|
48
|
+
} else {
|
49
|
+
nodeToReplace.outerHTML = httpRequest.responseText;
|
50
|
+
var newNode = document.getElementById(elementId);
|
51
|
+
initialize(newNode);
|
52
|
+
|
53
|
+
results.push({
|
54
|
+
action: 'replaces',
|
55
|
+
statusCode: httpRequest.status,
|
56
|
+
contentType: this.getResponseHeader('content-type'),
|
57
|
+
content: httpRequest.responseText
|
58
|
+
});
|
59
|
+
resolve(results);
|
60
|
+
}
|
61
|
+
} else {
|
62
|
+
results.push({
|
63
|
+
action: 'replaces',
|
64
|
+
statusCode: httpRequest.status,
|
65
|
+
contentType: this.getResponseHeader('content-type'),
|
66
|
+
content: httpRequest.responseText
|
67
|
+
});
|
68
|
+
reject(results);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
console.log('GET:' + url);
|
73
|
+
httpRequest.open('GET', url, true);
|
74
|
+
httpRequest.setRequestHeader('X-NO-LAYOUT', true);
|
75
|
+
httpRequest.send();
|
76
|
+
}, delayAmt);
|
77
|
+
|
78
|
+
});
|
79
|
+
return promiseObj;
|
80
|
+
}
|
81
|
+
|
82
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
export class VSelects {
|
2
|
+
constructor(options, params, event) {
|
3
|
+
this.target = options.target;
|
4
|
+
this.params = params;
|
5
|
+
this.event = event;
|
6
|
+
}
|
7
|
+
|
8
|
+
call(results) {
|
9
|
+
let targetFields =document.querySelectorAll('input[name="'+this.target+'"]');
|
10
|
+
let checked = this.event.target.checked;
|
11
|
+
new Promise(function (resolve) {
|
12
|
+
if (targetFields) {
|
13
|
+
if (checked) {
|
14
|
+
for (let i = 0; i < targetFields.length; i++) {
|
15
|
+
console.log(i);
|
16
|
+
targetFields[i].checked = true;
|
17
|
+
}
|
18
|
+
} else {
|
19
|
+
for (let i = 0; i < targetFields.length; i++) {
|
20
|
+
targetFields[i].checked = false;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
results.push({action:'selects', statusCode: 200});
|
25
|
+
resolve(results);
|
26
|
+
});
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import {VSnackbar} from '../snackbar.js';
|
2
|
+
|
3
|
+
export class VSnackbarEvent {
|
4
|
+
constructor(options, params, event) {
|
5
|
+
this.options = options;
|
6
|
+
this.params = params;
|
7
|
+
this.event = event;
|
8
|
+
let snackbarElem = document.querySelector('.mdc-snackbar');
|
9
|
+
this.snackbar = snackbarElem.vComponent;
|
10
|
+
}
|
11
|
+
|
12
|
+
call(results) {
|
13
|
+
let message = this.params.text;
|
14
|
+
let snackbar = this.snackbar;
|
15
|
+
let promiseObj = new Promise(function (resolve) {
|
16
|
+
console.log("Showing snackbar");
|
17
|
+
snackbar.display(message);
|
18
|
+
results.push({action:'snackbar', statusCode: 200});
|
19
|
+
resolve(results);
|
20
|
+
});
|
21
|
+
return promiseObj;
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export class VToggleVisiblity {
|
2
|
+
constructor(options, params, event) {
|
3
|
+
this.targetId = options.target;
|
4
|
+
this.params = params;
|
5
|
+
this.event = event;
|
6
|
+
}
|
7
|
+
|
8
|
+
call(results) {
|
9
|
+
var targetId = this.targetId;
|
10
|
+
var promiseObj = new Promise(function (resolve) {
|
11
|
+
console.log("Toggling visiblity on: " + targetId);
|
12
|
+
var elem = document.getElementById(targetId);
|
13
|
+
elem.classList.toggle("v-hidden");
|
14
|
+
results.push({action:'toggle_visiblity', statusCode: 200});
|
15
|
+
resolve(results);
|
16
|
+
});
|
17
|
+
return promiseObj;
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
export function initForms() {
|
2
|
+
console.log('\tForms');
|
3
|
+
|
4
|
+
var components = document.querySelectorAll('.v-form');
|
5
|
+
for (var i = 0; i < components.length; i++) {
|
6
|
+
var component = components[i];
|
7
|
+
if (!component.vComponent) {
|
8
|
+
component.vComponent = new VForm(component);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
export class VForm {
|
14
|
+
constructor(element) {
|
15
|
+
this.element = element;
|
16
|
+
}
|
17
|
+
|
18
|
+
// Called whenever a form is about to be submitted.
|
19
|
+
// returns true on success
|
20
|
+
// returns on failure return an error object that can be processed by VErrors:
|
21
|
+
// { email: ["email must be filled", "email must be from your domain"] }
|
22
|
+
// { :page: ["must be filled"] }
|
23
|
+
validate(form, params) {
|
24
|
+
console.log("Form validate", form, params);
|
25
|
+
var errors = [];
|
26
|
+
for (let input of this.inputs()) {
|
27
|
+
if (input.vComponent) {
|
28
|
+
var result = input.vComponent.validate(form, params);
|
29
|
+
if (result !== true) {
|
30
|
+
errors.push(result);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
return errors;
|
35
|
+
}
|
36
|
+
|
37
|
+
inputs() {
|
38
|
+
return this.element.querySelectorAll('input');
|
39
|
+
}
|
40
|
+
|
41
|
+
// Called to collect data for submission
|
42
|
+
prepareSubmit(form, params) {
|
43
|
+
for (let input of this.inputs()) {
|
44
|
+
if (input.vComponent) {
|
45
|
+
input.vComponent.prepareSubmit(form, params);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
initEventListener(eventName, eventHandler) {
|
51
|
+
for (let input of this.inputs()) {
|
52
|
+
if (input.vComponent && input.vComponent.initEventListener) {
|
53
|
+
input.vComponent.initEventListener(eventName, eventHandler);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import {MDCIconToggle} from '@material/icon-toggle';
|
2
|
+
|
3
|
+
export function initIconToggles() {
|
4
|
+
console.log('\tIcon Toggles');
|
5
|
+
|
6
|
+
var components = document.querySelectorAll('.mdc-icon-toggle');
|
7
|
+
for (var i = 0; i < components.length; i++) {
|
8
|
+
var component = components[i];
|
9
|
+
if (!component.mdcComponent) {
|
10
|
+
component.mdcComponent = new MDCIconToggle(component);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
// TODO: Add event handler
|
16
|
+
// var addToFavorites = document.getElementById('add-to-favorites');
|
17
|
+
// var favoritedStatus = document.getElementById('favorited-status');
|
18
|
+
// addToFavorites.addEventListener('MDCIconToggle:change', function(evt) {
|
19
|
+
// var newStatus = evt.detail.isOn ? 'yes' : 'no';
|
20
|
+
// favoritedStatus.textContent = newStatus;
|
21
|
+
// });
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import {initButtons} from './button';
|
2
|
+
import {initDialogs} from './dialogs';
|
3
|
+
import {initTextFields} from './text-fields';
|
4
|
+
import {initEvents} from './events';
|
5
|
+
import {initLists} from './lists';
|
6
|
+
import {initIconToggles} from './icon-toggles';
|
7
|
+
import {initMenus} from './menus';
|
8
|
+
import {initSelects} from './selects';
|
9
|
+
import {initChips} from './chips';
|
10
|
+
import {initCards} from './cards';
|
11
|
+
import {initForms} from './forms';
|
12
|
+
import {initSnackbar} from './snackbar';
|
13
|
+
import {initCheckboxes} from './checkboxes';
|
14
|
+
import {initDateTime} from './date-time';
|
15
|
+
|
16
|
+
export function initialize(){
|
17
|
+
console.log('Initializing');
|
18
|
+
initButtons();
|
19
|
+
initDialogs();
|
20
|
+
initTextFields();
|
21
|
+
initLists();
|
22
|
+
initIconToggles();
|
23
|
+
initMenus();
|
24
|
+
initSelects();
|
25
|
+
initChips();
|
26
|
+
initCards();
|
27
|
+
initForms();
|
28
|
+
initSnackbar();
|
29
|
+
initCheckboxes();
|
30
|
+
initDateTime();
|
31
|
+
// This needs to be last, because it relies on the components installed above.
|
32
|
+
initEvents();
|
33
|
+
// componentHandler.upgradeAllRegistered();
|
34
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import {MDCMenu} from '@material/menu';
|
2
|
+
import {Corner} from '@material/menu';
|
3
|
+
|
4
|
+
|
5
|
+
function createMenuHandler(menu, element) {
|
6
|
+
return function () {
|
7
|
+
var offset = parseInt(element.dataset.rightOffset);
|
8
|
+
menu.setAnchorMargin({left: offset});
|
9
|
+
menu.open = !menu.open;
|
10
|
+
};
|
11
|
+
}
|
12
|
+
|
13
|
+
export function initMenus() {
|
14
|
+
console.log('\tMenus');
|
15
|
+
|
16
|
+
var components = document.querySelectorAll('.v-menu');
|
17
|
+
if (components) {
|
18
|
+
for (var i = 0; i < components.length; i++) {
|
19
|
+
var component = components[i];
|
20
|
+
if (!component.mdcComponent) {
|
21
|
+
component.mdcComponent = new MDCMenu(component);
|
22
|
+
var anchor = component.closest('.mdc-menu-anchor');
|
23
|
+
if (anchor) {
|
24
|
+
var menulink = anchor.querySelector('.v-menu-click');
|
25
|
+
menulink.addEventListener('click', createMenuHandler(component.mdcComponent, component));
|
26
|
+
}
|
27
|
+
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|