1
0
Fork 0

Merge branch 'master' into add_group_field

Dieser Commit ist enthalten in:
Angus McLeod 2020-03-31 15:53:00 +11:00
Commit 9a489f3b9b
10 geänderte Dateien mit 48 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -16,7 +16,7 @@ export default Ember.Component.extend({
categoryPropertyTypes: generateSelectKitContent(['id', 'slug']), categoryPropertyTypes: generateSelectKitContent(['id', 'slug']),
@computed('field.type') @computed('field.type')
isInput: (type) => type === 'text' || type === 'textarea', isInput: (type) => type === 'text' || type === 'textarea' || type === 'url',
@computed('field.type') @computed('field.type')
isCategoryOrTag: (type) => type === 'tag' || type === 'category', isCategoryOrTag: (type) => type === 'tag' || type === 'category',

Datei anzeigen

@ -4,6 +4,4 @@ Wizard.SiteSettings = {};
Wizard.RAW_TEMPLATES = {}; Wizard.RAW_TEMPLATES = {};
Discourse.__widget_helpers = {}; Discourse.__widget_helpers = {};
Discourse.RAW_TEMPLATES = {}; Discourse.RAW_TEMPLATES = {};
Discourse.SiteSettings = Wizard.SiteSettings; Discourse.SiteSettings = Wizard.SiteSettings;
Discourse.Model = Ember.Object.extend();
Discourse.Site = Ember.Object.extend();

Datei anzeigen

@ -31,9 +31,12 @@
//= require discourse/lib/key-value-store //= require discourse/lib/key-value-store
//= require discourse/lib/settings //= require discourse/lib/settings
//= require discourse/lib/user-presence //= require discourse/lib/user-presence
//= require discourse/lib/hash
//= require discourse/mixins/singleton //= require discourse/mixins/singleton
//= require discourse/adapters/rest
//= require discourse/models/login-method //= require discourse/models/login-method
//= require discourse/models/permission-type //= require discourse/models/permission-type
//= require discourse/models/archetype //= require discourse/models/archetype

Datei anzeigen

@ -5,7 +5,8 @@ export default {
initialize(app) { initialize(app) {
if (window.location.pathname.indexOf('/w/') < 0) return; if (window.location.pathname.indexOf('/w/') < 0) return;
const EmberObject = requirejs('@ember/object').default;
const Router = requirejs('wizard/router').default; const Router = requirejs('wizard/router').default;
const ApplicationRoute = requirejs('wizard/routes/application').default; const ApplicationRoute = requirejs('wizard/routes/application').default;
const ajax = requirejs('wizard/lib/ajax').ajax; const ajax = requirejs('wizard/lib/ajax').ajax;
@ -22,7 +23,10 @@ export default {
const Store = requirejs("discourse/models/store").default; const Store = requirejs("discourse/models/store").default;
const registerRawHelpers = requirejs("discourse-common/lib/raw-handlebars-helpers").registerRawHelpers; const registerRawHelpers = requirejs("discourse-common/lib/raw-handlebars-helpers").registerRawHelpers;
const RawHandlebars = requirejs("discourse-common/lib/raw-handlebars").default; const RawHandlebars = requirejs("discourse-common/lib/raw-handlebars").default;
const Site = requirejs("discourse/models/site").default;
const RestAdapter = requirejs("discourse/adapters/rest").default;
Discourse.Model = EmberObject.extend();
Discourse.__container__ = app.__container__; Discourse.__container__ = app.__container__;
Discourse.getURLWithCDN = getUrl; Discourse.getURLWithCDN = getUrl;
Discourse.getURL = getUrl; Discourse.getURL = getUrl;
@ -51,16 +55,16 @@ export default {
app.register("service:store", Store); app.register("service:store", Store);
targets.forEach(t => app.inject(t, "store", "service:store")); targets.forEach(t => app.inject(t, "store", "service:store"));
const site = Discourse.Site;
app.register("site:main", site);
targets.forEach(t => app.inject(t, "site", "site:main"));
targets.forEach(t => app.inject(t, "appEvents", "service:app-events")); targets.forEach(t => app.inject(t, "appEvents", "service:app-events"));
site.reopenClass(Singleton); app.register("adapter:rest", RestAdapter);
site.currentProp('can_create_tag', false);
const site = Site.current();
app.register("site:main", site, { instantiate: false });
targets.forEach(t => app.inject(t, "site", "site:main"));
site.set('can_create_tag', false);
Router.reopen({ Router.reopen({
rootURL: getUrl('/w/') rootURL: getUrl('/w/')
}); });
@ -214,13 +218,14 @@ export default {
inputComponentName: function() { inputComponentName: function() {
const type = this.get('field.type'); const type = this.get('field.type');
const id = this.get('field.id'); const id = this.get('field.id');
if (type === 'text-only') return false; if (['text-only'].includes(type)) return false;
return (type === 'component') ? Ember.String.dasherize(id) : `wizard-field-${type}`; return (type === 'component') ? Ember.String.dasherize(id) : `wizard-field-${type}`;
}.property('field.type', 'field.id') }.property('field.type', 'field.id')
}); });
const StandardFieldValidation = [ const StandardFieldValidation = [
'text', 'text',
'number',
'textarea', 'textarea',
'dropdown', 'dropdown',
'tag', 'tag',
@ -253,15 +258,15 @@ export default {
} else { } else {
const val = this.get('value'); const val = this.get('value');
const type = this.get('type'); const type = this.get('type');
console.log(val, type)
if (type === 'checkbox') { if (type === 'checkbox') {
valid = val; valid = val;
} else if (type === 'upload') { } else if (type === 'upload') {
valid = val && val.id > 0; valid = val && val.id > 0;
} else if (StandardFieldValidation.indexOf(type) > -1) { } else if (StandardFieldValidation.indexOf(type) > -1) {
valid = val && val.toString().length > 0; valid = val && val.toString().length > 0;
} else if (type === 'url') {
valid = true;
} }
} }

Datei anzeigen

@ -0,0 +1 @@
{{input type='number' step='0.01' id=field.id value=field.value}}

Datei anzeigen

@ -0,0 +1 @@
{{input type='text' id=field.id value=field.value}}

Datei anzeigen

@ -181,6 +181,14 @@
} }
} }
.url-field input {
width: 100%;
font-size: 1.1487em;
padding: 6px;
border: 1px solid #ccc;
transition: border-color 0.5s;
}
.control-group { .control-group {
display: inline-block; display: inline-block;
vertical-align: top; vertical-align: top;

Datei anzeigen

@ -9,6 +9,7 @@ en:
field: field:
too_short: "%{label} must be at least %{min} characters" too_short: "%{label} must be at least %{min} characters"
required: "%{label} is required." required: "%{label} is required."
not_url: "%{label} must be a valid url"
none: "We couldn't find a wizard at that address." none: "We couldn't find a wizard at that address."
no_skip: "Wizard can't be skipped" no_skip: "Wizard can't be skipped"
export: export:

Datei anzeigen

@ -300,6 +300,12 @@ class CustomWizard::Builder
) )
end end
if is_url_type(field)
if !check_if_url(value)
updater.errors.add(field['id'].to_s, I18n.t('wizard.field.not_url', label: label))
end
end
## ensure all checkboxes are booleans ## ensure all checkboxes are booleans
if field['type'] === 'checkbox' if field['type'] === 'checkbox'
updater.fields[field['id']] = standardise_boolean(value) updater.fields[field['id']] = standardise_boolean(value)
@ -316,6 +322,14 @@ class CustomWizard::Builder
['text', 'textarea'].include? field['type'] ['text', 'textarea'].include? field['type']
end end
def is_url_type(field)
['url'].include? field['type']
end
def check_if_url(value)
value =~ URI::regexp
end
def standardise_boolean(value) def standardise_boolean(value)
ActiveRecord::Type::Boolean.new.cast(value) ActiveRecord::Type::Boolean.new.cast(value)
end end

Datei anzeigen

@ -1,6 +1,6 @@
class CustomWizard::Field class CustomWizard::Field
def self.types def self.types
@types ||= ['checkbox', 'composer', 'dropdown', 'tag', 'category', 'group', 'image', 'text', 'textarea', 'text-only', 'upload', 'user-selector'] @types ||= ['checkbox', 'composer', 'dropdown', 'tag', 'category', 'group', 'image', 'text', 'textarea', 'text-only', 'number', 'upload', 'user-selector', 'url']
end end
def self.require_assets def self.require_assets