diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 3264541b..2514ddce 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -12,6 +12,7 @@ const ACTION_TYPES = [ const PROFILE_FIELDS = [ 'name', + 'user_avatar', 'date_of_birth', 'title', 'locale', diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 56fe9529..1afb1683 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -20,7 +20,7 @@ export default Ember.Component.extend({ @computed() presetChoices() { - return [ + let presets = [ { id: 'categories', name: I18n.t('admin.wizard.field.choices_preset.categories') @@ -32,6 +32,13 @@ export default Ember.Component.extend({ name: I18n.t('admin.wizard.field.choices_preset.tags') } ]; + if (Discourse.SiteSettings.nationalflag_enabled) { + presets.push({ + id: 'flags', + name: I18n.t('admin.wizard.field.choices_preset.flags') + }) + } + return presets; }, @on('didInsertElement') diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 824030bd..9f69294c 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -143,6 +143,17 @@ {{/if}} {{#if sendMessage}} +
+
+

{{i18n 'admin.wizard.required'}}

+
+
+ {{combo-box content=availableFields + nameProperty='label' + none='admin.wizard.select_field' + value=action.required}} +
+

{{i18n "admin.wizard.action.send_message.recipient"}}

diff --git a/assets/javascripts/wizard/components/wizard-field-upload.js.es6 b/assets/javascripts/wizard/components/wizard-field-upload.js.es6 index f7f82faf..ee969eef 100644 --- a/assets/javascripts/wizard/components/wizard-field-upload.js.es6 +++ b/assets/javascripts/wizard/components/wizard-field-upload.js.es6 @@ -3,7 +3,9 @@ import { getToken } from "wizard/lib/ajax"; export default Ember.Component.extend({ classNames: ["wizard-field-upload"], + classNameBindings: ["isImage"], uploading: false, + isImage: false, didInsertElement() { this._super(); @@ -30,6 +32,11 @@ export default Ember.Component.extend({ "field.value": response.result, "uploading": false }); + if ( Discourse.SiteSettings.wizard_recognised_image_upload_formats.split('|').includes(response.result.extension)) { + this.setProperties({ + "isImage": true + }) + } }); $upload.on("fileuploadfail", (e, response) => { diff --git a/assets/javascripts/wizard/initializers/custom.js.es6 b/assets/javascripts/wizard/initializers/custom.js.es6 index d2154467..b7a89bd7 100644 --- a/assets/javascripts/wizard/initializers/custom.js.es6 +++ b/assets/javascripts/wizard/initializers/custom.js.es6 @@ -1,3 +1,5 @@ +import { default as computed } from 'ember-addons/ember-computed-decorators'; + export default { name: 'custom-routes', @@ -16,6 +18,20 @@ export default { const autocomplete = requirejs('discourse/lib/autocomplete').default; const cook = requirejs('discourse/plugins/discourse-custom-wizard/wizard/lib/text-lite').cook; const Singleton = requirejs("discourse/mixins/singleton").default; + const WizardFieldDropdown = requirejs('wizard/components/wizard-field-dropdown').default; + + WizardFieldDropdown.reopen({ + tagName: 'span', + classNames: ['wizard-select-value'], + + @computed + isFlagSelector() { + const field = this.get('field'); + //TODO improve the way this detects a flag dropdown (currently it relies on the string 'Nation', e.g. 'Nationality' or 'National Flag' appearing in label) + return (field.label.includes('Nation')) ? true : false; + } + }); + // IE11 Polyfill - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill if (!Object.entries) @@ -240,6 +256,8 @@ export default { valid = val; } else if (type === 'category') { valid = val && val.toString().length > 0; + } else if (type === 'upload') { + valid = val && val.id > 0; } else if (StandardFieldValidation.indexOf(type) > -1) { valid = val && val.length > 0; } diff --git a/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs index f92000e0..011a2e3f 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs @@ -5,3 +5,6 @@ none=(hash id="__none__" label=field.dropdown_none) nameProperty="label" tabindex="9"}} +{{#if isFlagSelector}} + +{{/if}} diff --git a/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs b/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs index 0e24849a..10e6b0dd 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs @@ -11,6 +11,10 @@ {{#if field.value}} - {{field.value.original_filename}} + {{#unless isImage}} + {{field.value.original_filename}} + {{else}} + + {{/unless}} {{/if}} diff --git a/assets/stylesheets/wizard/wizard_custom.scss b/assets/stylesheets/wizard/wizard_custom.scss index 5209b8e9..853d371a 100644 --- a/assets/stylesheets/wizard/wizard_custom.scss +++ b/assets/stylesheets/wizard/wizard_custom.scss @@ -229,8 +229,27 @@ margin: 20px 0; } - .wizard-image-row .wizard-btn-upload { - margin: 0; + .wizard-image-row { + + .wizard-btn-upload { + margin: 0; + } + + } + + .wizard-image-preview { + max-width: 200px; + max-height: 200px; + overflow: hidden; + + img { + max-width:100%; + max-height:100%; + } + } + + .wizard-select-value img { + vertical-align: middle; } .wizard-field-upload { @@ -415,8 +434,9 @@ div.ac-wrap { width: 98.5% !important; - overflow: auto; + overflow: visible; max-height: 150px; + min-height: 34px; background-color: white; border: 1px solid #e9e9e9; padding: 5px 4px 1px 4px; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1c0bd172..9372570c 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -101,6 +101,7 @@ en: categories: "Categories" groups: "Groups" tags: "Tags" + flags: "Flags" filter: "Preset Filter" choice: value: "Value" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index d1c42401..e2c2d856 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -22,3 +22,4 @@ en: site_settings: wizard_redirect_exclude_paths: "Routes excluded from wizard redirects." + wizard_recognised_image_upload_formats: "File types which will result in upload displaying an image preview" diff --git a/config/national_flags.yml b/config/national_flags.yml new file mode 100644 index 00000000..9621e37d --- /dev/null +++ b/config/national_flags.yml @@ -0,0 +1,259 @@ +none: none.png +ad: ad.png +ae: ae.png +af: af.png +ag: ag.png +ai: ai.png +al: al.png +am: am.png +ao: ao.png +aq: aq.png +ar: ar.png +as: as.png +at: at.png +au: au.png +aw: aw.png +ax: ax.png +az: az.png +ba: ba.png +bb: bb.png +bd: bd.png +be: be.png +bf: bf.png +bg: bg.png +bh: bh.png +bi: bi.png +bj: bj.png +bl: bl.png +bm: bm.png +bn: bn.png +bo: bo.png +bq: bq.png +br: br.png +bs: bs.png +bt: bt.png +bv: bv.png +bw: bw.png +by: by.png +bz: bz.png +ca: ca.png +cc: cc.png +cd: cd.png +cf: cf.png +cg: cg.png +ch: ch.png +ci: ci.png +ck: ck.png +cl: cl.png +cm: cm.png +cn: cn.png +co: co.png +cr: cr.png +cu: cu.png +cv: cv.png +cw: cw.png +cx: cx.png +cy: cy.png +cz: cz.png +de: de.png +de-at: de-at.png +dj: dj.png +dk: dk.png +dm: dm.png +do: do.png +dz: dz.png +ec: ec.png +ee: ee.png +eg: eg.png +eh: eh.png +er: er.png +es: es.png +et: et.png +eu: eu.png +fi: fi.png +fj: fj.png +fk: fk.png +fm: fm.png +fo: fo.png +fr: fr.png +fr-br: fr-br.png +ga: ga.png +gb-eng: gb-eng.png +gb-nir: gb-nir.png +gb-sct: gb-sct.png +gb-wls: gb-wls.png +gb: gb.png +gd: gd.png +ge: ge.png +gf: gf.png +gg: gg.png +gh: gh.png +gi: gi.png +gl: gl.png +gm: gm.png +gn: gn.png +gp: gp.png +gq: gq.png +gr: gr.png +gs: gs.png +gt: gt.png +gu: gu.png +gw: gw.png +gy: gy.png +hk: hk.png +hm: hm.png +hn: hn.png +hr: hr.png +ht: ht.png +hu: hu.png +id: id.png +ie: ie.png +il: il.png +im: im.png +in: in.png +io: io.png +iq: iq.png +ir: ir.png +is: is.png +it: it.png +je: je.png +jm: jm.png +jo: jo.png +jp: jp.png +ke: ke.png +kg: kg.png +kh: kh.png +ki: ki.png +km: km.png +kn: kn.png +kp: kp.png +kr: kr.png +kw: kw.png +ky: ky.png +kz: kz.png +la: la.png +lb: lb.png +lc: lc.png +li: li.png +lk: lk.png +lr: lr.png +ls: ls.png +lt: lt.png +lu: lu.png +lv: lv.png +ly: ly.png +ma: ma.png +mc: mc.png +md: md.png +me: me.png +mf: mf.png +mg: mg.png +mh: mh.png +mk: mk.png +ml: ml.png +mm: mm.png +mn: mn.png +mo: mo.png +mp: mp.png +mq: mq.png +mr: mr.png +ms: ms.png +mt: mt.png +mu: mu.png +mv: mv.png +mw: mw.png +mx: mx.png +my: my.png +mz: mz.png +na: na.png +nc: nc.png +ne: ne.png +nf: nf.png +ng: ng.png +ni: ni.png +nl: nl.png +no: no.png +np: np.png +nr: nr.png +nu: nu.png +nz: nz.png +om: om.png +pa: pa.png +pe: pe.png +pf: pf.png +pg: pg.png +ph: ph.png +pk: pk.png +pl: pl.png +pm: pm.png +pn: pn.png +pr: pr.png +ps: ps.png +pt: pt.png +pw: pw.png +py: py.png +qa: qa.png +re: re.png +ro: ro.png +rs: rs.png +ru: ru.png +rw: rw.png +sa: sa.png +sb: sb.png +sc: sc.png +sd: sd.png +se: se.png +sg: sg.png +sh: sh.png +si: si.png +sj: sj.png +sk: sk.png +sl: sl.png +sm: sm.png +sn: sn.png +so: so.png +sr: sr.png +ss: ss.png +st: st.png +sv: sv.png +sx: sx.png +sy: sy.png +sz: sz.png +tc: tc.png +td: td.png +tf: tf.png +tg: tg.png +th: th.png +tj: tj.png +tk: tk.png +tl: tl.png +tm: tm.png +tn: tn.png +to: to.png +tr: tr.png +tt: tt.png +tv: tv.png +tw: tw.png +tz: tz.png +ua: ua.png +ug: ug.png +um: um.png +un: un.png +us: us.png +us-at: us-at.png +uy: uy.png +uz: uz.png +va: va.png +vc: vc.png +ve: ve.png +vg: vg.png +vi: vi.png +vn: vn.png +vu: vu.png +wf: wf.png +ws: ws.png +ye: ye.png +yt: yt.png +za: za.png +zm: zm.png +zw: zw.png diff --git a/config/settings.yml b/config/settings.yml index 703f541e..2185676a 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -6,3 +6,9 @@ plugins: choices: - admin - privacy + wizard_recognised_image_upload_formats: + client: true + default: "jpg|jpeg|png|gif" + refresh: true + type: list + list_type: compact diff --git a/lib/builder.rb b/lib/builder.rb index 1d3a80b2..ee29c549 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -199,7 +199,7 @@ class CustomWizard::Builder type: field_template['type'], required: field_template['required'] } - + params[:label] = field_template['label'] if field_template['label'] params[:description] = field_template['description'] if field_template['description'] params[:image] = field_template['image'] if field_template['image'] @@ -291,6 +291,10 @@ class CustomWizard::Builder objects = Tag.top_tags(guardian: guardian).map { |tag| TagStruct.new(tag,tag) } end + if field_template['choices_preset'] === 'flags' + objects = CustomWizard::Flags.list + end + if field_template['choices_filters'] && field_template['choices_filters'].length > 0 field_template['choices_filters'].each do |f| objects.reject! do |o| @@ -420,7 +424,16 @@ class CustomWizard::Builder end def send_message(user, action, data) - title = data[action['title']] + + if action['required'].present? && data[action['required']].blank? + return + end + + if action['custom_title_enabled'] + title = CustomWizard::Builder.fill_placeholders(action['custom_title'], user, data) + else + title = data[action['title']] + end if action['post_builder'] post = CustomWizard::Builder.fill_placeholders(action['post_template'], user, data) @@ -474,13 +487,20 @@ class CustomWizard::Builder custom_fields[user_field || custom_field] = data[key] else updater_key = value - if ['profile_background', 'card_background'].include?(value) updater_key = "#{value}_upload_url" end - attributes[updater_key.to_sym] = data[key] if updater_key end + + if ['user_avatar'].include?(value) + this_upload_id = data[key][:id] + user.create_user_avatar unless user.user_avatar + user.user_avatar.custom_upload_id = this_upload_id + user.uploaded_avatar_id = this_upload_id + user.save! + user.user_avatar.save! + end end if custom_fields.present? diff --git a/lib/flags.rb b/lib/flags.rb new file mode 100644 index 00000000..00f29866 --- /dev/null +++ b/lib/flags.rb @@ -0,0 +1,31 @@ +class CustomWizard::Flag + def initialize(id, name) + @id = id + @name = name + end + + def id + @id + end + + def name + @name + end +end + +class CustomWizard::Flags + + def self.list + raw_flags = YAML.safe_load(File.read(File.join(Rails.root, 'plugins', 'discourse-custom-wizard', 'config', 'national_flags.yml'))) + + flagscollection = [] + + raw_flags.map do |name, pic| + # This is super hacky. Adding the trailing space actually stops search breaking in the dropdown! (and doesn't compromise the view!) + # Feeding just name, name will break search + flagscollection << CustomWizard::Flag.new(name, "#{name} ") + end + + flagscollection + end +end diff --git a/lib/wizard_edits.rb b/lib/wizard_edits.rb index 11aa7ed8..9c834808 100644 --- a/lib/wizard_edits.rb +++ b/lib/wizard_edits.rb @@ -89,6 +89,10 @@ end def name object.name end + + def include_name? + object.respond_to?(:name) + end def background object.background diff --git a/plugin.rb b/plugin.rb index dab47964..4ce2932e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -52,7 +52,6 @@ after_initialize do put ':wizard_id/steps/:step_id' => 'steps#update' end - require_dependency 'admin_constraint' Discourse::Application.routes.append do mount ::CustomWizard::Engine, at: 'w' post 'wizard/authorization/callback' => "custom_wizard/authorization#callback" @@ -76,7 +75,6 @@ after_initialize do delete 'admin/wizards/apis/logs/:name' => 'api#clearlogs' get 'admin/wizards/apis/:name/redirect' => 'api#redirect' get 'admin/wizards/apis/:name/authorize' => 'api#authorize' - #transfer code get 'admin/wizards/transfer' => 'transfer#index' get 'admin/wizards/transfer/export' => 'transfer#export' post 'admin/wizards/transfer/import' => 'transfer#import' @@ -87,6 +85,7 @@ after_initialize do load File.expand_path('../jobs/set_after_time_wizard.rb', __FILE__) load File.expand_path('../lib/builder.rb', __FILE__) load File.expand_path('../lib/field.rb', __FILE__) + load File.expand_path('../lib/flags.rb', __FILE__) load File.expand_path('../lib/step_updater.rb', __FILE__) load File.expand_path('../lib/template.rb', __FILE__) load File.expand_path('../lib/wizard.rb', __FILE__)