Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 18:50:27 +01:00
Merge pull request #198 from paviliondev/move_custom_wizard_into_main_app
Move custom wizard into main app
Dieser Commit ist enthalten in:
Commit
72a1f9f2c2
212 geänderte Dateien mit 2597 neuen und 33745 gelöschten Zeilen
43
.github/workflows/plugin-linting.yml
gevendort
43
.github/workflows/plugin-linting.yml
gevendort
|
@ -3,51 +3,52 @@ name: Linting
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- stable
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
concurrency:
|
||||
group: plugin-linting-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 14
|
||||
node-version: 16
|
||||
cache: yarn
|
||||
|
||||
- name: Yarn install
|
||||
run: yarn install
|
||||
|
||||
- name: Set up ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.7
|
||||
|
||||
- name: Setup bundler
|
||||
run: gem install bundler -v 2.1.4 --no-doc
|
||||
|
||||
- name: Setup gems
|
||||
run: bundle install --jobs 4
|
||||
|
||||
- name: Yarn install
|
||||
run: yarn install --dev
|
||||
bundler-cache: true
|
||||
|
||||
- name: ESLint
|
||||
run: yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern {test,assets}/javascripts/{discourse,wizard}
|
||||
if: ${{ always() }}
|
||||
run: yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern {test,assets}/javascripts
|
||||
|
||||
- name: Prettier
|
||||
if: ${{ always() }}
|
||||
shell: bash
|
||||
run: |
|
||||
yarn prettier -v
|
||||
if [ -d "assets" ]; then \
|
||||
yarn prettier --list-different "assets/javascripts/{discourse,wizard}/**/*.{scss,js,es6}" ; \
|
||||
if [ 0 -lt $(find assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
|
||||
yarn prettier --list-different "assets/**/*.{scss,js,es6}"
|
||||
fi
|
||||
if [ 0 -lt $(find test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
|
||||
yarn prettier --list-different "test/**/*.{js,es6}"
|
||||
fi
|
||||
|
||||
- name: Ember template lint
|
||||
run: yarn ember-template-lint assets/javascripts
|
||||
|
||||
- name: Rubocop
|
||||
if: ${{ always() }}
|
||||
run: bundle exec rubocop .
|
||||
|
|
132
.github/workflows/plugin-tests.yml
gevendort
132
.github/workflows/plugin-tests.yml
gevendort
|
@ -3,24 +3,25 @@ name: Plugin Tests
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- stable
|
||||
- master
|
||||
- main
|
||||
- stable
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 */12 * * *'
|
||||
|
||||
concurrency:
|
||||
group: plugin-tests-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{ matrix.build_type }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
container: discourse/discourse_test:slim${{ startsWith(matrix.build_type, 'frontend') && '-browsers' || '' }}
|
||||
timeout-minutes: 30
|
||||
|
||||
env:
|
||||
DISCOURSE_HOSTNAME: www.example.com
|
||||
RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072
|
||||
RAILS_ENV: test
|
||||
PGHOST: localhost
|
||||
PGUSER: discourse
|
||||
PGPASSWORD: discourse
|
||||
|
||||
|
@ -29,44 +30,17 @@ jobs:
|
|||
|
||||
matrix:
|
||||
build_type: ["backend", "frontend"]
|
||||
ruby: ["2.7"]
|
||||
postgres: ["12"]
|
||||
redis: ["6.x"]
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:${{ matrix.postgres }}
|
||||
ports:
|
||||
- 5432:5432
|
||||
env:
|
||||
POSTGRES_USER: discourse
|
||||
POSTGRES_PASSWORD: discourse
|
||||
options: >-
|
||||
--mount type=tmpfs,destination=/var/lib/postgresql/data
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
|
||||
steps:
|
||||
- uses: haya14busa/action-cond@v1
|
||||
id: discourse_branch
|
||||
with:
|
||||
cond: ${{ github.base_ref == 'stable' }}
|
||||
if_true: "stable"
|
||||
if_false: "tests-passed"
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: discourse/discourse
|
||||
ref: ${{ steps.discourse_branch.outputs.value }}
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Install plugin
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: plugins/${{ github.event.repository.name }}
|
||||
ref: "${{ github.head_ref }}"
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup Git
|
||||
|
@ -74,61 +48,89 @@ jobs:
|
|||
git config --global user.email "ci@ci.invalid"
|
||||
git config --global user.name "Discourse CI"
|
||||
|
||||
- name: Setup packages
|
||||
- name: Start redis
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -yqq install postgresql-client libpq-dev gifsicle jpegoptim optipng jhead
|
||||
wget -qO- https://raw.githubusercontent.com/discourse/discourse_docker/master/image/base/install-pngquant | sudo sh
|
||||
redis-server /etc/redis/redis.conf &
|
||||
|
||||
- name: Update imagemagick
|
||||
if: matrix.build_type == 'backend'
|
||||
- name: Start Postgres
|
||||
run: |
|
||||
wget https://raw.githubusercontent.com/discourse/discourse_docker/master/image/base/install-imagemagick
|
||||
chmod +x install-imagemagick
|
||||
sudo ./install-imagemagick
|
||||
chown -R postgres /var/run/postgresql
|
||||
sudo -E -u postgres script/start_test_db.rb
|
||||
sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';"
|
||||
|
||||
- name: Setup redis
|
||||
uses: shogo82148/actions-setup-redis@v1
|
||||
- name: Bundler cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
redis-version: ${{ matrix.redis }}
|
||||
path: vendor/bundle
|
||||
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gem-
|
||||
|
||||
- name: Setup ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: ${{ matrix.ruby }}
|
||||
bundler-cache: true
|
||||
- name: Setup gems
|
||||
run: |
|
||||
gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' Gemfile.lock)
|
||||
bundle config --local path vendor/bundle
|
||||
bundle config --local deployment true
|
||||
bundle config --local without development
|
||||
bundle install --jobs 4
|
||||
bundle clean
|
||||
|
||||
- name: Lint English locale
|
||||
if: matrix.build_type == 'backend'
|
||||
run: bundle exec ruby script/i18n_lint.rb "plugins/${{ steps.repo-name.outputs.value }}/locales/{client,server}.en.yml"
|
||||
run: bundle exec ruby script/i18n_lint.rb "plugins/${{ github.event.repository.name }}/locales/{client,server}.en.yml"
|
||||
|
||||
- name: Get yarn cache directory
|
||||
id: yarn-cache-dir
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
|
||||
- name: Yarn cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir.outputs.dir }}
|
||||
key: ${{ runner.os }}-${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ matrix.os }}-yarn-
|
||||
${{ runner.os }}-yarn-
|
||||
|
||||
- name: Yarn install
|
||||
run: yarn install --dev
|
||||
run: yarn install
|
||||
|
||||
- name: Migrate database
|
||||
- name: Fetch app state cache
|
||||
uses: actions/cache@v3
|
||||
id: app-cache
|
||||
with:
|
||||
path: tmp/app-cache
|
||||
key: >-
|
||||
${{ hashFiles('.github/workflows/tests.yml') }}-
|
||||
${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}-
|
||||
|
||||
- name: Restore database from cache
|
||||
if: steps.app-cache.outputs.cache-hit == 'true'
|
||||
run: psql -f tmp/app-cache/cache.sql postgres
|
||||
|
||||
- name: Restore uploads from cache
|
||||
if: steps.app-cache.outputs.cache-hit == 'true'
|
||||
run: rm -rf public/uploads && cp -r tmp/app-cache/uploads public/uploads
|
||||
|
||||
- name: Create and migrate database
|
||||
if: steps.app-cache.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
bin/rake db:create
|
||||
bin/rake db:migrate
|
||||
|
||||
- name: Plugin RSpec with Coverage
|
||||
- name: Dump database for cache
|
||||
if: steps.app-cache.outputs.cache-hit != 'true'
|
||||
run: mkdir -p tmp/app-cache && pg_dumpall > tmp/app-cache/cache.sql
|
||||
|
||||
- name: Dump uploads for cache
|
||||
if: steps.app-cache.outputs.cache-hit != 'true'
|
||||
run: rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads
|
||||
|
||||
- name: Plugin RSpec
|
||||
if: matrix.build_type == 'backend'
|
||||
run: |
|
||||
if [ -e plugins/${{ steps.repo-name.outputs.value }}/.simplecov ]
|
||||
then
|
||||
cp plugins/${{ steps.repo-name.outputs.value }}/.simplecov .simplecov
|
||||
export COVERAGE=1
|
||||
fi
|
||||
bin/rake plugin:spec[${{ steps.repo-name.outputs.value }}]
|
||||
run: bin/rake plugin:spec[${{ github.event.repository.name }}]
|
||||
|
||||
- name: Plugin QUnit
|
||||
if: matrix.build_type == 'frontend'
|
||||
run: QUNIT_EMBER_CLI=1 bundle exec rake plugin:qunit['${{ github.event.repository.name }}','1200000']
|
||||
timeout-minutes: 10
|
||||
|
|
|
@ -1,42 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
class CustomWizard::WizardController < ::ActionController::Base
|
||||
helper ApplicationHelper
|
||||
|
||||
include CurrentUser
|
||||
include CanonicalURL::ControllerExtensions
|
||||
include GlobalPath
|
||||
|
||||
prepend_view_path(Rails.root.join('plugins', 'discourse-custom-wizard', 'app', 'views'))
|
||||
layout :set_wizard_layout
|
||||
|
||||
before_action :preload_wizard_json
|
||||
class CustomWizard::WizardController < ::ApplicationController
|
||||
before_action :ensure_plugin_enabled
|
||||
before_action :ensure_logged_in, only: [:skip]
|
||||
around_action :with_resolved_locale
|
||||
|
||||
helper_method :wizard_page_title
|
||||
helper_method :wizard_theme_id
|
||||
helper_method :wizard_theme_lookup
|
||||
helper_method :wizard_theme_translations_lookup
|
||||
|
||||
def set_wizard_layout
|
||||
action_name === 'qunit' ? 'qunit' : 'wizard'
|
||||
end
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
def show
|
||||
if wizard.present?
|
||||
render json: CustomWizard::WizardSerializer.new(wizard, scope: guardian, root: false).as_json, status: 200
|
||||
else
|
||||
render json: { error: I18n.t('wizard.none') }
|
||||
end
|
||||
end
|
||||
format.html do
|
||||
render "default/empty"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def skip
|
||||
params.require(:wizard_id)
|
||||
|
@ -58,26 +31,8 @@ class CustomWizard::WizardController < ::ActionController::Base
|
|||
render json: result
|
||||
end
|
||||
|
||||
def qunit
|
||||
raise Discourse::InvalidAccess.new if Rails.env.production?
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
render "default/empty"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def ensure_logged_in
|
||||
raise Discourse::NotLoggedIn.new unless current_user.present?
|
||||
end
|
||||
|
||||
def guardian
|
||||
@guardian ||= Guardian.new(current_user, request)
|
||||
end
|
||||
|
||||
def wizard
|
||||
@wizard ||= begin
|
||||
builder = CustomWizard::Builder.new(params[:wizard_id].underscore, current_user)
|
||||
|
@ -88,41 +43,6 @@ class CustomWizard::WizardController < ::ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def wizard_page_title
|
||||
wizard ? (wizard.name || wizard.id) : I18n.t('wizard.custom_title')
|
||||
end
|
||||
|
||||
def wizard_theme_id
|
||||
wizard ? wizard.theme_id : nil
|
||||
end
|
||||
|
||||
def wizard_theme_lookup(name)
|
||||
Theme.lookup_field(wizard_theme_id, view_context.mobile_view? ? :mobile : :desktop, name)
|
||||
end
|
||||
|
||||
def wizard_theme_translations_lookup
|
||||
Theme.lookup_field(wizard_theme_id, :translations, I18n.locale)
|
||||
end
|
||||
|
||||
def preload_wizard_json
|
||||
return if request.xhr? || request.format.json?
|
||||
return if request.method != "GET"
|
||||
|
||||
store_preloaded("siteSettings", SiteSetting.client_settings_json)
|
||||
end
|
||||
|
||||
def store_preloaded(key, json)
|
||||
@preloaded ||= {}
|
||||
@preloaded[key] = json.gsub("</", "<\\/")
|
||||
end
|
||||
|
||||
## Simplified version of with_resolved_locale in ApplicationController
|
||||
def with_resolved_locale
|
||||
locale = current_user ? current_user.effective_locale : SiteSetting.default_locale
|
||||
I18n.ensure_all_loaded!
|
||||
I18n.with_locale(locale) { yield }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_plugin_enabled
|
||||
|
|
|
@ -9,13 +9,10 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
|
|||
:completed,
|
||||
:required,
|
||||
:permitted,
|
||||
:uncategorized_category_id,
|
||||
:categories,
|
||||
:resume_on_revisit
|
||||
|
||||
has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects
|
||||
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
|
||||
has_many :groups, serializer: ::BasicGroupSerializer, embed: :objects
|
||||
|
||||
def completed
|
||||
object.completed?
|
||||
|
@ -46,24 +43,4 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
|
|||
def include_steps?
|
||||
!include_completed?
|
||||
end
|
||||
|
||||
def include_categories?
|
||||
object.needs_categories
|
||||
end
|
||||
|
||||
def include_groups?
|
||||
object.needs_groups
|
||||
end
|
||||
|
||||
def uncategorized_category_id
|
||||
SiteSetting.uncategorized_category_id
|
||||
end
|
||||
|
||||
def include_uncategorized_category_id?
|
||||
object.needs_categories
|
||||
end
|
||||
|
||||
def categories
|
||||
object.categories.map { |c| c.to_h }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<%= discourse_color_scheme_stylesheets %>
|
||||
|
||||
<%= discourse_stylesheet_link_tag :wizard, theme_id: nil %>
|
||||
<%= discourse_stylesheet_link_tag :wizard_custom %>
|
||||
<%- if wizard_theme_id.present? %>
|
||||
<%= discourse_stylesheet_link_tag (mobile_view? ? :mobile_theme : :desktop_theme), theme_id: wizard_theme_id %>
|
||||
<%- end %>
|
||||
|
||||
<%= preload_script "locales/#{I18n.locale}" %>
|
||||
<%= preload_script "ember_jquery" %>
|
||||
<%= preload_script "wizard-vendor" %>
|
||||
<%= preload_script "wizard-custom" %>
|
||||
<%= preload_script "wizard-raw-templates" %>
|
||||
<%= preload_script "wizard-plugin" %>
|
||||
<%= preload_script "pretty-text-bundle" %>
|
||||
<%= preload_script_url ExtraLocalesController.url("wizard") %>
|
||||
<%= csrf_meta_tags %>
|
||||
|
||||
<%- unless customization_disabled? %>
|
||||
<%= wizard_theme_translations_lookup %>
|
||||
<%= raw wizard_theme_lookup("head_tag") %>
|
||||
<%- end %>
|
||||
|
||||
<%= server_plugin_outlet "custom_wizard" %>
|
||||
|
||||
<%= tag.meta id: 'data-discourse-setup', data: client_side_setup_data %>
|
||||
|
||||
<meta name="discourse_theme_id" content="<%= wizard_theme_id %>">
|
||||
<meta name="discourse-base-uri" content="<%= Discourse.base_path %>">
|
||||
|
||||
<%= render partial: "layouts/head" %>
|
||||
<title><%= wizard_page_title %></title>
|
||||
</head>
|
||||
|
||||
<body class='custom-wizard wizard'>
|
||||
<%- unless customization_disabled? %>
|
||||
<%= raw wizard_theme_lookup("header") %>
|
||||
<%- end %>
|
||||
|
||||
<div id='custom-wizard-main'></div>
|
||||
|
||||
<%- unless customization_disabled? %>
|
||||
<%= raw wizard_theme_lookup("body_tag") %>
|
||||
<%- end %>
|
||||
|
||||
<%- if current_user %>
|
||||
<%= preload_script 'wizard-custom-start' %>
|
||||
<%- else %>
|
||||
<%= preload_script 'wizard-custom-guest' %>
|
||||
<%- end %>
|
||||
|
||||
<div id="svg-sprites" style="display:none;">
|
||||
<div class="fontawesome">
|
||||
<%= raw SvgSprite.bundle %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hidden" id="data-preloaded-wizard" data-preloaded-wizard="<%= preloaded_json %>"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -3,8 +3,8 @@ import {
|
|||
observes,
|
||||
} from "discourse-common/utils/decorators";
|
||||
import { renderAvatar } from "discourse/helpers/user-avatar";
|
||||
import userSearch from "../lib/user-search";
|
||||
import WizardI18n from "../lib/wizard-i18n";
|
||||
import userSearch from "discourse/lib/user-search";
|
||||
import I18n from "I18n";
|
||||
import Handlebars from "handlebars";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import TextField from "@ember/component/text-field";
|
||||
|
@ -41,7 +41,7 @@ export default TextField.extend({
|
|||
|
||||
@computed("placeholderKey")
|
||||
placeholder(placeholderKey) {
|
||||
return placeholderKey ? WizardI18n(placeholderKey) : "";
|
||||
return placeholderKey ? I18n.t(placeholderKey) : "";
|
||||
},
|
||||
|
||||
@observes("usernames")
|
|
@ -3,17 +3,16 @@ import {
|
|||
default as discourseComputed,
|
||||
on,
|
||||
} from "discourse-common/utils/decorators";
|
||||
import { findRawTemplate } from "discourse/plugins/discourse-custom-wizard/legacy/raw-templates";
|
||||
import { findRawTemplate } from "discourse-common/lib/raw-templates";
|
||||
import { scheduleOnce } from "@ember/runloop";
|
||||
import { caretPosition, inCodeBlock } from "discourse/lib/utilities";
|
||||
import highlightSyntax from "discourse/lib/highlight-syntax";
|
||||
import { alias } from "@ember/object/computed";
|
||||
import Site from "../models/site";
|
||||
import Site from "discourse/models/site";
|
||||
import { uploadIcon } from "discourse/lib/uploads";
|
||||
import { dasherize } from "@ember/string";
|
||||
|
||||
export default ComposerEditor.extend({
|
||||
layoutName: "wizard/templates/components/wizard-composer-editor",
|
||||
classNameBindings: ["fieldClass"],
|
||||
allowUpload: true,
|
||||
showLink: false,
|
||||
|
@ -35,7 +34,7 @@ export default ComposerEditor.extend({
|
|||
if (this.siteSettings.enable_mentions) {
|
||||
$input.autocomplete({
|
||||
template: findRawTemplate("user-selector-autocomplete"),
|
||||
dataSource: (term) => this.userSearchTerm.call(this, term),
|
||||
dataSource: (term) => this._userSearchTerm.call(this, term),
|
||||
key: "@",
|
||||
transformComplete: (v) => v.username || v.name,
|
||||
afterComplete: (value) => {
|
|
@ -2,7 +2,6 @@ import Component from "@ember/component";
|
|||
|
||||
export default Component.extend({
|
||||
classNames: ["wizard-composer-hyperlink"],
|
||||
layoutName: "wizard/templates/components/wizard-composer-hyperlink",
|
||||
|
||||
actions: {
|
||||
addLink() {
|
|
@ -3,7 +3,6 @@ import discourseComputed from "discourse-common/utils/decorators";
|
|||
|
||||
export default DateInput.extend({
|
||||
useNativePicker: false,
|
||||
layoutName: "wizard/templates/components/wizard-date-input",
|
||||
|
||||
@discourseComputed()
|
||||
placeholder() {
|
|
@ -2,8 +2,6 @@ import DateTimeInput from "discourse/components/date-time-input";
|
|||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
export default DateTimeInput.extend({
|
||||
layoutName: "wizard/templates/components/wizard-date-time-input",
|
||||
|
||||
@discourseComputed("timeFirst", "tabindex")
|
||||
timeTabindex(timeFirst, tabindex) {
|
||||
return timeFirst ? tabindex : tabindex + 1;
|
|
@ -3,8 +3,6 @@ import Category from "discourse/models/category";
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-category",
|
||||
|
||||
didInsertElement() {
|
||||
const property = this.field.property || "id";
|
||||
const value = this.field.value;
|
|
@ -0,0 +1,3 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({});
|
|
@ -7,8 +7,6 @@ import { ajax } from "discourse/lib/ajax";
|
|||
import { on } from "discourse-common/utils/decorators";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-composer-preview",
|
||||
|
||||
@on("init")
|
||||
updatePreview() {
|
||||
if (this.isDestroyed) {
|
|
@ -6,8 +6,6 @@ import EmberObject from "@ember/object";
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-composer",
|
||||
|
||||
showPreview: false,
|
||||
classNameBindings: [
|
||||
":wizard-field-composer",
|
|
@ -2,8 +2,6 @@ import Component from "@ember/component";
|
|||
import { observes } from "discourse-common/utils/decorators";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-date-time",
|
||||
|
||||
@observes("dateTime")
|
||||
setValue() {
|
||||
this.set("field.value", this.dateTime.format(this.field.format));
|
|
@ -2,8 +2,6 @@ import Component from "@ember/component";
|
|||
import { observes } from "discourse-common/utils/decorators";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-date",
|
||||
|
||||
@observes("date")
|
||||
setValue() {
|
||||
this.set("field.value", this.date.format(this.field.format));
|
|
@ -1,8 +1,6 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-dropdown",
|
||||
|
||||
keyPress(e) {
|
||||
e.stopPropagation();
|
||||
},
|
|
@ -0,0 +1,3 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({});
|
|
@ -0,0 +1,3 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({});
|
|
@ -0,0 +1,3 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({});
|
|
@ -1,8 +1,6 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-text",
|
||||
|
||||
keyPress(e) {
|
||||
e.stopPropagation();
|
||||
},
|
|
@ -1,8 +1,6 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-textarea",
|
||||
|
||||
keyPress(e) {
|
||||
e.stopPropagation();
|
||||
},
|
|
@ -2,8 +2,6 @@ import Component from "@ember/component";
|
|||
import { observes } from "discourse-common/utils/decorators";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field-time",
|
||||
|
||||
@observes("time")
|
||||
setValue() {
|
||||
this.set("field.value", this.time.format(this.field.format));
|
|
@ -3,7 +3,6 @@ import Component from "@ember/component";
|
|||
import { computed } from "@ember/object";
|
||||
|
||||
export default Component.extend(UppyUploadMixin, {
|
||||
layoutName: "wizard/templates/components/wizard-field-upload",
|
||||
classNames: ["wizard-field-upload"],
|
||||
classNameBindings: ["isImage"],
|
||||
uploading: false,
|
|
@ -0,0 +1,3 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({});
|
|
@ -0,0 +1,3 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({});
|
|
@ -1,10 +1,9 @@
|
|||
import Component from "@ember/component";
|
||||
import { dasherize } from "@ember/string";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { cook } from "discourse/plugins/discourse-custom-wizard/wizard/lib/text-lite";
|
||||
import { cookAsync } from "discourse/lib/text";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-field",
|
||||
classNameBindings: [
|
||||
":wizard-field",
|
||||
"typeClasses",
|
||||
|
@ -12,6 +11,14 @@ export default Component.extend({
|
|||
"field.id",
|
||||
],
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
|
||||
cookAsync(this.field.translatedDescription).then((cookedDescription) => {
|
||||
this.set("cookedDescription", cookedDescription);
|
||||
});
|
||||
},
|
||||
|
||||
@discourseComputed("field.type", "field.id")
|
||||
typeClasses: (type, id) =>
|
||||
`${dasherize(type)}-field ${dasherize(type)}-${dasherize(id)}`,
|
||||
|
@ -24,12 +31,7 @@ export default Component.extend({
|
|||
if (["text_only"].includes(type)) {
|
||||
return false;
|
||||
}
|
||||
return dasherize(type === "component" ? id : `wizard-field-${type}`);
|
||||
},
|
||||
|
||||
@discourseComputed("field.translatedDescription")
|
||||
cookedDescription(description) {
|
||||
return cook(description);
|
||||
return dasherize(type === "component" ? id : `custom-wizard-field-${type}`);
|
||||
},
|
||||
|
||||
@discourseComputed("field.type")
|
|
@ -3,7 +3,6 @@ import { computed } from "@ember/object";
|
|||
import { makeArray } from "discourse-common/lib/helpers";
|
||||
|
||||
export default ComboBox.extend({
|
||||
layoutName: "wizard/templates/components/wizard-group-selector",
|
||||
content: computed("groups.[]", "field.content.[]", function () {
|
||||
const whitelist = makeArray(this.field.content);
|
||||
return this.groups
|
|
@ -1,11 +1,10 @@
|
|||
import CustomWizard from "../models/wizard";
|
||||
import CustomWizard from "../models/custom-wizard";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import Component from "@ember/component";
|
||||
import { dasherize } from "@ember/string";
|
||||
|
||||
export default Component.extend({
|
||||
classNameBindings: [":wizard-no-access", "reasonClass"],
|
||||
layoutName: "wizard/templates/components/wizard-no-access",
|
||||
|
||||
@discourseComputed("reason")
|
||||
reasonClass(reason) {
|
|
@ -4,7 +4,6 @@ import { observes } from "discourse-common/utils/decorators";
|
|||
|
||||
export default Component.extend({
|
||||
classNames: ["wizard-similar-topics"],
|
||||
layoutName: "wizard/templates/components/wizard-similar-topics",
|
||||
showTopics: true,
|
||||
|
||||
didInsertElement() {
|
|
@ -4,15 +4,15 @@ import I18n from "I18n";
|
|||
import getUrl from "discourse-common/lib/get-url";
|
||||
import { htmlSafe } from "@ember/template";
|
||||
import { schedule } from "@ember/runloop";
|
||||
import { cook } from "discourse/plugins/discourse-custom-wizard/wizard/lib/text-lite";
|
||||
import { updateCachedWizard } from "discourse/plugins/discourse-custom-wizard/wizard/models/wizard";
|
||||
import { cookAsync } from "discourse/lib/text";
|
||||
import CustomWizard, {
|
||||
updateCachedWizard,
|
||||
} from "discourse/plugins/discourse-custom-wizard/discourse/models/custom-wizard";
|
||||
import { alias, not } from "@ember/object/computed";
|
||||
import CustomWizard from "../models/wizard";
|
||||
|
||||
const alreadyWarned = {};
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/wizard-step",
|
||||
classNameBindings: [":wizard-step", "step.id"],
|
||||
saving: null,
|
||||
|
||||
|
@ -21,6 +21,17 @@ export default Component.extend({
|
|||
this.set("stylingDropdown", {});
|
||||
},
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
|
||||
cookAsync(this.step.translatedTitle).then((cookedTitle) => {
|
||||
this.set("cookedTitle", cookedTitle);
|
||||
});
|
||||
cookAsync(this.step.translatedDescription).then((cookedDescription) => {
|
||||
this.set("cookedDescription", cookedDescription);
|
||||
});
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
this.autoFocus();
|
||||
|
@ -32,16 +43,6 @@ export default Component.extend({
|
|||
showNextButton: not("step.final"),
|
||||
showDoneButton: alias("step.final"),
|
||||
|
||||
@discourseComputed("step.translatedTitle")
|
||||
cookedTitle(title) {
|
||||
return cook(title);
|
||||
},
|
||||
|
||||
@discourseComputed("step.translatedDescription")
|
||||
cookedDescription(description) {
|
||||
return cook(description);
|
||||
},
|
||||
|
||||
@discourseComputed(
|
||||
"step.index",
|
||||
"step.displayIndex",
|
|
@ -1,6 +1,6 @@
|
|||
import computed from "discourse-common/utils/decorators";
|
||||
import { isLTR, isRTL, siteDir } from "discourse/lib/text-direction";
|
||||
import WizardI18n from "../lib/wizard-i18n";
|
||||
import I18n from "I18n";
|
||||
import TextField from "@ember/component/text-field";
|
||||
|
||||
export default TextField.extend({
|
||||
|
@ -39,6 +39,6 @@ export default TextField.extend({
|
|||
|
||||
@computed("placeholderKey")
|
||||
placeholder(placeholderKey) {
|
||||
return placeholderKey ? WizardI18n(placeholderKey) : "";
|
||||
return placeholderKey ? I18n.t(placeholderKey) : "";
|
||||
},
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
import TimeInput from "discourse/components/time-input";
|
||||
|
||||
export default TimeInput.extend({});
|
|
@ -1,8 +1,6 @@
|
|||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
layoutName: "wizard/templates/components/field-validators",
|
||||
|
||||
actions: {
|
||||
perform() {
|
||||
this.appEvents.trigger("custom-wizard:validate");
|
|
@ -1,4 +1,4 @@
|
|||
import WizardFieldValidator from "../../wizard/components/validator";
|
||||
import WizardFieldValidator from "discourse/plugins/discourse-custom-wizard/discourse/components/validator";
|
||||
import { deepMerge } from "discourse-common/lib/object";
|
||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
||||
import { cancel, later } from "@ember/runloop";
|
||||
|
@ -10,7 +10,6 @@ import { dasherize } from "@ember/string";
|
|||
|
||||
export default WizardFieldValidator.extend({
|
||||
classNames: ["similar-topics-validator"],
|
||||
layoutName: "wizard/templates/components/similar-topics-validator",
|
||||
similarTopics: null,
|
||||
hasInput: notEmpty("field.value"),
|
||||
hasSimilarTopics: notEmpty("similarTopics"),
|
|
@ -1,12 +1,10 @@
|
|||
import Component from "@ember/component";
|
||||
import { equal } from "@ember/object/computed";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { getToken } from "../lib/ajax";
|
||||
import { ajax, getToken } from "discourse/lib/ajax";
|
||||
|
||||
export default Component.extend({
|
||||
classNames: ["validator"],
|
||||
classNameBindings: ["isValid", "isInvalid"],
|
||||
layoutName: "wizard/templates/components/validator",
|
||||
validMessageKey: null,
|
||||
invalidMessageKey: null,
|
||||
isValid: null,
|
|
@ -1,9 +1,9 @@
|
|||
import CustomWizard from "../../models/custom-wizard";
|
||||
import CustomWizardAdmin from "../../models/custom-wizard-admin";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
||||
export default {
|
||||
setupComponent(attrs, component) {
|
||||
CustomWizard.all()
|
||||
CustomWizardAdmin.all()
|
||||
.then((result) => {
|
||||
component.set("wizardList", result);
|
||||
})
|
||||
|
|
|
@ -149,7 +149,6 @@ export default Controller.extend({
|
|||
const api = this.get("api");
|
||||
const name = api.name;
|
||||
const authType = api.authType;
|
||||
let refreshList = false; // eslint-disable-line
|
||||
let error;
|
||||
|
||||
if (!name || !authType) {
|
||||
|
@ -164,11 +163,6 @@ export default Controller.extend({
|
|||
data["title"] = api.title;
|
||||
}
|
||||
|
||||
const originalTitle = this.get("api.originalTitle");
|
||||
if (api.get("isNew") || (originalTitle && api.title !== originalTitle)) {
|
||||
refreshList = true;
|
||||
}
|
||||
|
||||
if (api.get("isNew")) {
|
||||
data["new"] = true;
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ export default Controller.extend({
|
|||
const wizardId = this.get("wizard.id");
|
||||
window.location.href = getUrl(`/w/${wizardId}/steps/${nextStepId}`);
|
||||
} else {
|
||||
this.transitionToRoute("step", nextStepId);
|
||||
this.transitionToRoute("customWizardStep", nextStepId);
|
||||
}
|
||||
},
|
||||
|
||||
goBack() {
|
||||
this.transitionToRoute("step", this.get("step.previous"));
|
||||
this.transitionToRoute("customWizardStep", this.get("step.previous"));
|
||||
},
|
||||
|
||||
showMessage(message) {
|
12
assets/javascripts/discourse/custom-wizard-route-map.js.es6
Normale Datei
12
assets/javascripts/discourse/custom-wizard-route-map.js.es6
Normale Datei
|
@ -0,0 +1,12 @@
|
|||
export default function () {
|
||||
this.route(
|
||||
"customWizard",
|
||||
{ path: "/w/:wizard_id", resetNamespace: true },
|
||||
function () {
|
||||
this.route("customWizardStep", {
|
||||
path: "/steps/:step_id",
|
||||
resetNamespace: true,
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
import { registerUnbound } from "discourse-common/lib/helpers";
|
||||
import { dasherize } from "@ember/string";
|
||||
|
||||
registerUnbound("dasherize", function (string) {
|
||||
return dasherize(string);
|
||||
});
|
|
@ -38,6 +38,7 @@ export default {
|
|||
});
|
||||
|
||||
api.modifyClass("component:uppy-image-uploader", {
|
||||
pluginId: "custom-wizard",
|
||||
// Needed to ensure appEvents get registered when navigating between steps
|
||||
@observes("id")
|
||||
initOnStepChange() {
|
||||
|
|
|
@ -5,7 +5,7 @@ export default {
|
|||
after: "message-bus",
|
||||
|
||||
initialize: function (container) {
|
||||
const messageBus = container.lookup("message-bus:main");
|
||||
const messageBus = container.lookup("service:message-bus");
|
||||
const siteSettings = container.lookup("site-settings:main");
|
||||
|
||||
if (!siteSettings.custom_wizard_enabled || !messageBus) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import EmberObject from "@ember/object";
|
||||
import wizardSchema from "./wizard-schema";
|
||||
import I18n from "I18n";
|
||||
|
||||
function selectKitContent(content) {
|
||||
return content.map((i) => ({ id: i, name: i }));
|
||||
|
@ -33,6 +34,10 @@ function camelCase(string) {
|
|||
});
|
||||
}
|
||||
|
||||
function translationOrText(i18nKey, text) {
|
||||
return I18n.findTranslation(i18nKey) ? I18n.t(i18nKey) : text;
|
||||
}
|
||||
|
||||
const userProperties = [
|
||||
"name",
|
||||
"username",
|
||||
|
@ -121,4 +126,5 @@ export {
|
|||
notificationLevels,
|
||||
wizardFieldList,
|
||||
sentenceCase,
|
||||
translationOrText,
|
||||
};
|
||||
|
|
227
assets/javascripts/discourse/models/custom-wizard-admin.js.es6
Normale Datei
227
assets/javascripts/discourse/models/custom-wizard-admin.js.es6
Normale Datei
|
@ -0,0 +1,227 @@
|
|||
import EmberObject from "@ember/object";
|
||||
import { buildProperties, mapped, present } from "../lib/wizard-json";
|
||||
import { listProperties, snakeCase } from "../lib/wizard";
|
||||
import wizardSchema from "../lib/wizard-schema";
|
||||
import { Promise } from "rsvp";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
||||
const CustomWizardAdmin = EmberObject.extend({
|
||||
save(opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let wizard = this.buildJson(this, "wizard");
|
||||
|
||||
if (wizard.error) {
|
||||
reject(wizard);
|
||||
}
|
||||
|
||||
let data = {
|
||||
wizard,
|
||||
};
|
||||
|
||||
if (opts.create) {
|
||||
data.create = true;
|
||||
}
|
||||
|
||||
ajax(`/admin/wizards/wizard/${wizard.id}`, {
|
||||
type: "PUT",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
}).then((result) => {
|
||||
if (result.backend_validation_error) {
|
||||
reject(result);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
buildJson(object, type, result = {}) {
|
||||
let objectType = object.type || null;
|
||||
|
||||
if (wizardSchema[type].types) {
|
||||
if (!objectType) {
|
||||
result.error = {
|
||||
type: "required",
|
||||
params: { type, property: "type" },
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
for (let property of listProperties(type, { objectType })) {
|
||||
let value = object.get(property);
|
||||
|
||||
result = this.validateValue(property, value, object, type, result);
|
||||
|
||||
if (result.error) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (mapped(property, type)) {
|
||||
value = this.buildMappedJson(value);
|
||||
}
|
||||
|
||||
if (value !== undefined && value !== null) {
|
||||
result[property] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.error) {
|
||||
for (let arrayObjectType of Object.keys(
|
||||
wizardSchema[type].objectArrays
|
||||
)) {
|
||||
let arraySchema = wizardSchema[type].objectArrays[arrayObjectType];
|
||||
let objectArray = object.get(arraySchema.property);
|
||||
|
||||
if (arraySchema.required && !present(objectArray)) {
|
||||
result.error = {
|
||||
type: "required",
|
||||
params: { type, property: arraySchema.property },
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
result[arraySchema.property] = [];
|
||||
|
||||
for (let item of objectArray) {
|
||||
let itemProps = this.buildJson(item, arrayObjectType);
|
||||
|
||||
if (itemProps.error) {
|
||||
result.error = itemProps.error;
|
||||
break;
|
||||
} else {
|
||||
result[arraySchema.property].push(itemProps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
validateValue(property, value, object, type, result) {
|
||||
if (wizardSchema[type].required.indexOf(property) > -1 && !value) {
|
||||
result.error = {
|
||||
type: "required",
|
||||
params: { type, property },
|
||||
};
|
||||
}
|
||||
|
||||
let dependent = wizardSchema[type].dependent[property];
|
||||
if (dependent && value && !object[dependent]) {
|
||||
result.error = {
|
||||
type: "dependent",
|
||||
params: { property, dependent },
|
||||
};
|
||||
}
|
||||
|
||||
if (property === "api_body") {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {
|
||||
result.error = {
|
||||
type: "invalid",
|
||||
params: { type, property },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
buildMappedJson(value) {
|
||||
if (typeof value === "string" || Number.isInteger(value)) {
|
||||
return value;
|
||||
}
|
||||
if (!value || !value.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let inputs = value;
|
||||
let result = [];
|
||||
|
||||
inputs.forEach((inpt) => {
|
||||
let input = {
|
||||
type: inpt.type,
|
||||
};
|
||||
|
||||
if (inpt.connector) {
|
||||
input.connector = inpt.connector;
|
||||
}
|
||||
|
||||
if (present(inpt.output)) {
|
||||
input.output = inpt.output;
|
||||
input.output_type = snakeCase(inpt.output_type);
|
||||
input.output_connector = inpt.output_connector;
|
||||
}
|
||||
|
||||
if (present(inpt.pairs)) {
|
||||
input.pairs = [];
|
||||
|
||||
inpt.pairs.forEach((pr) => {
|
||||
if (present(pr.key) && present(pr.value)) {
|
||||
let pairParams = {
|
||||
index: pr.index,
|
||||
key: pr.key,
|
||||
key_type: snakeCase(pr.key_type),
|
||||
value: pr.value,
|
||||
value_type: snakeCase(pr.value_type),
|
||||
connector: pr.connector,
|
||||
};
|
||||
|
||||
input.pairs.push(pairParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
(input.type === "assignment" && present(input.output)) ||
|
||||
present(input.pairs)
|
||||
) {
|
||||
result.push(input);
|
||||
}
|
||||
});
|
||||
|
||||
if (!result.length) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
remove() {
|
||||
return ajax(`/admin/wizards/wizard/${this.id}`, {
|
||||
type: "DELETE",
|
||||
})
|
||||
.then(() => this.destroy())
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
});
|
||||
|
||||
CustomWizardAdmin.reopenClass({
|
||||
all() {
|
||||
return ajax("/admin/wizards/wizard", {
|
||||
type: "GET",
|
||||
})
|
||||
.then((result) => {
|
||||
return result.wizard_list;
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
submissions(wizardId) {
|
||||
return ajax(`/admin/wizards/submissions/${wizardId}`, {
|
||||
type: "GET",
|
||||
}).catch(popupAjaxError);
|
||||
},
|
||||
|
||||
create(wizardJson = {}) {
|
||||
const wizard = this._super.apply(this);
|
||||
wizard.setProperties(buildProperties(wizardJson));
|
||||
return wizard;
|
||||
},
|
||||
});
|
||||
|
||||
export default CustomWizardAdmin;
|
|
@ -1,7 +1,7 @@
|
|||
import EmberObject from "@ember/object";
|
||||
import ValidState from "discourse/plugins/discourse-custom-wizard/wizard/mixins/valid-state";
|
||||
import ValidState from "discourse/plugins/discourse-custom-wizard/discourse/mixins/valid-state";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { translatedText } from "discourse/plugins/discourse-custom-wizard/wizard/lib/wizard-i18n";
|
||||
import { translationOrText } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard";
|
||||
|
||||
const StandardFieldValidation = [
|
||||
"text",
|
||||
|
@ -34,17 +34,17 @@ export default EmberObject.extend(ValidState, {
|
|||
|
||||
@discourseComputed("i18nKey", "label")
|
||||
translatedLabel(i18nKey, label) {
|
||||
return translatedText(`${i18nKey}.label`, label);
|
||||
return translationOrText(`${i18nKey}.label`, label);
|
||||
},
|
||||
|
||||
@discourseComputed("i18nKey", "placeholder")
|
||||
translatedPlaceholder(i18nKey, placeholder) {
|
||||
return translatedText(`${i18nKey}.placeholder`, placeholder);
|
||||
return translationOrText(`${i18nKey}.placeholder`, placeholder);
|
||||
},
|
||||
|
||||
@discourseComputed("i18nKey", "description")
|
||||
translatedDescription(i18nKey, description) {
|
||||
return translatedText(`${i18nKey}.description`, description);
|
||||
return translationOrText(`${i18nKey}.description`, description);
|
||||
},
|
||||
|
||||
check() {
|
|
@ -1,9 +1,9 @@
|
|||
import EmberObject from "@ember/object";
|
||||
import ValidState from "discourse/plugins/discourse-custom-wizard/wizard/mixins/valid-state";
|
||||
import { ajax } from "../lib/ajax";
|
||||
import ValidState from "discourse/plugins/discourse-custom-wizard/discourse/mixins/valid-state";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { translatedText } from "discourse/plugins/discourse-custom-wizard/wizard/lib/wizard-i18n";
|
||||
import { later } from "@ember/runloop";
|
||||
import { translationOrText } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard";
|
||||
|
||||
export default EmberObject.extend(ValidState, {
|
||||
id: null,
|
||||
|
@ -15,12 +15,12 @@ export default EmberObject.extend(ValidState, {
|
|||
|
||||
@discourseComputed("i18nKey", "title")
|
||||
translatedTitle(i18nKey, title) {
|
||||
return translatedText(`${i18nKey}.title`, title);
|
||||
return translationOrText(`${i18nKey}.title`, title);
|
||||
},
|
||||
|
||||
@discourseComputed("i18nKey", "description")
|
||||
translatedDescription(i18nKey, description) {
|
||||
return translatedText(`${i18nKey}.description`, description);
|
||||
return translationOrText(`${i18nKey}.description`, description);
|
||||
},
|
||||
|
||||
@discourseComputed("index")
|
|
@ -1,227 +1,127 @@
|
|||
import { ajax } from "discourse/lib/ajax";
|
||||
import EmberObject from "@ember/object";
|
||||
import { buildProperties, mapped, present } from "../lib/wizard-json";
|
||||
import { listProperties, snakeCase } from "../lib/wizard";
|
||||
import wizardSchema from "../lib/wizard-schema";
|
||||
import { Promise } from "rsvp";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import getUrl from "discourse-common/lib/get-url";
|
||||
import CustomWizardField from "./custom-wizard-field";
|
||||
import CustomWizardStep from "./custom-wizard-step";
|
||||
|
||||
const CustomWizard = EmberObject.extend({
|
||||
save(opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let wizard = this.buildJson(this, "wizard");
|
||||
@discourseComputed("steps.length")
|
||||
totalSteps: (length) => length,
|
||||
|
||||
if (wizard.error) {
|
||||
reject(wizard);
|
||||
skip() {
|
||||
if (this.required && !this.completed && this.permitted) {
|
||||
return;
|
||||
}
|
||||
|
||||
let data = {
|
||||
wizard,
|
||||
};
|
||||
|
||||
if (opts.create) {
|
||||
data.create = true;
|
||||
}
|
||||
|
||||
ajax(`/admin/wizards/wizard/${wizard.id}`, {
|
||||
type: "PUT",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
}).then((result) => {
|
||||
if (result.backend_validation_error) {
|
||||
reject(result);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
CustomWizard.skip(this.id);
|
||||
},
|
||||
|
||||
buildJson(object, type, result = {}) {
|
||||
let objectType = object.type || null;
|
||||
|
||||
if (wizardSchema[type].types) {
|
||||
if (!objectType) {
|
||||
result.error = {
|
||||
type: "required",
|
||||
params: { type, property: "type" },
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
for (let property of listProperties(type, { objectType })) {
|
||||
let value = object.get(property);
|
||||
|
||||
result = this.validateValue(property, value, object, type, result);
|
||||
|
||||
if (result.error) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (mapped(property, type)) {
|
||||
value = this.buildMappedJson(value);
|
||||
}
|
||||
|
||||
if (value !== undefined && value !== null) {
|
||||
result[property] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.error) {
|
||||
for (let arrayObjectType of Object.keys(
|
||||
wizardSchema[type].objectArrays
|
||||
)) {
|
||||
let arraySchema = wizardSchema[type].objectArrays[arrayObjectType];
|
||||
let objectArray = object.get(arraySchema.property);
|
||||
|
||||
if (arraySchema.required && !present(objectArray)) {
|
||||
result.error = {
|
||||
type: "required",
|
||||
params: { type, property: arraySchema.property },
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
result[arraySchema.property] = [];
|
||||
|
||||
for (let item of objectArray) {
|
||||
let itemProps = this.buildJson(item, arrayObjectType);
|
||||
|
||||
if (itemProps.error) {
|
||||
result.error = itemProps.error;
|
||||
break;
|
||||
} else {
|
||||
result[arraySchema.property].push(itemProps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
validateValue(property, value, object, type, result) {
|
||||
if (wizardSchema[type].required.indexOf(property) > -1 && !value) {
|
||||
result.error = {
|
||||
type: "required",
|
||||
params: { type, property },
|
||||
};
|
||||
}
|
||||
|
||||
let dependent = wizardSchema[type].dependent[property];
|
||||
if (dependent && value && !object[dependent]) {
|
||||
result.error = {
|
||||
type: "dependent",
|
||||
params: { property, dependent },
|
||||
};
|
||||
}
|
||||
|
||||
if (property === "api_body") {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {
|
||||
result.error = {
|
||||
type: "invalid",
|
||||
params: { type, property },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
buildMappedJson(value) {
|
||||
if (typeof value === "string" || Number.isInteger(value)) {
|
||||
return value;
|
||||
}
|
||||
if (!value || !value.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let inputs = value;
|
||||
let result = [];
|
||||
|
||||
inputs.forEach((inpt) => {
|
||||
let input = {
|
||||
type: inpt.type,
|
||||
};
|
||||
|
||||
if (inpt.connector) {
|
||||
input.connector = inpt.connector;
|
||||
}
|
||||
|
||||
if (present(inpt.output)) {
|
||||
input.output = inpt.output;
|
||||
input.output_type = snakeCase(inpt.output_type);
|
||||
input.output_connector = inpt.output_connector;
|
||||
}
|
||||
|
||||
if (present(inpt.pairs)) {
|
||||
input.pairs = [];
|
||||
|
||||
inpt.pairs.forEach((pr) => {
|
||||
if (present(pr.key) && present(pr.value)) {
|
||||
let pairParams = {
|
||||
index: pr.index,
|
||||
key: pr.key,
|
||||
key_type: snakeCase(pr.key_type),
|
||||
value: pr.value,
|
||||
value_type: snakeCase(pr.value_type),
|
||||
connector: pr.connector,
|
||||
};
|
||||
|
||||
input.pairs.push(pairParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
(input.type === "assignment" && present(input.output)) ||
|
||||
present(input.pairs)
|
||||
) {
|
||||
result.push(input);
|
||||
}
|
||||
});
|
||||
|
||||
if (!result.length) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
remove() {
|
||||
return ajax(`/admin/wizards/wizard/${this.id}`, {
|
||||
type: "DELETE",
|
||||
})
|
||||
.then(() => this.destroy())
|
||||
.catch(popupAjaxError);
|
||||
restart() {
|
||||
CustomWizard.restart(this.id);
|
||||
},
|
||||
});
|
||||
|
||||
CustomWizard.reopenClass({
|
||||
all() {
|
||||
return ajax("/admin/wizards/wizard", {
|
||||
type: "GET",
|
||||
})
|
||||
skip(wizardId) {
|
||||
ajax({ url: `/w/${wizardId}/skip`, type: "PUT" })
|
||||
.then((result) => {
|
||||
return result.wizard_list;
|
||||
CustomWizard.finished(result);
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
submissions(wizardId) {
|
||||
return ajax(`/admin/wizards/submissions/${wizardId}`, {
|
||||
type: "GET",
|
||||
}).catch(popupAjaxError);
|
||||
restart(wizardId) {
|
||||
ajax({ url: `/w/${wizardId}/skip`, type: "PUT" })
|
||||
.then(() => {
|
||||
window.location.href = `/w/${wizardId}`;
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
create(wizardJson = {}) {
|
||||
const wizard = this._super.apply(this);
|
||||
wizard.setProperties(buildProperties(wizardJson));
|
||||
return wizard;
|
||||
finished(result) {
|
||||
let url = "/";
|
||||
if (result.redirect_on_complete) {
|
||||
url = result.redirect_on_complete;
|
||||
}
|
||||
window.location.href = getUrl(url);
|
||||
},
|
||||
|
||||
build(wizardJson) {
|
||||
if (!wizardJson) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!wizardJson.completed && wizardJson.steps) {
|
||||
wizardJson.steps = wizardJson.steps
|
||||
.map((step) => {
|
||||
const stepObj = CustomWizardStep.create(step);
|
||||
stepObj.wizardId = wizardJson.id;
|
||||
|
||||
stepObj.fields.sort((a, b) => {
|
||||
return parseFloat(a.number) - parseFloat(b.number);
|
||||
});
|
||||
|
||||
let tabindex = 1;
|
||||
stepObj.fields.forEach((f) => {
|
||||
f.tabindex = tabindex;
|
||||
|
||||
if (["date_time"].includes(f.type)) {
|
||||
tabindex = tabindex + 2;
|
||||
} else {
|
||||
tabindex++;
|
||||
}
|
||||
});
|
||||
|
||||
stepObj.fields = stepObj.fields.map((f) => {
|
||||
f.wizardId = wizardJson.id;
|
||||
f.stepId = stepObj.id;
|
||||
return CustomWizardField.create(f);
|
||||
});
|
||||
|
||||
return stepObj;
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return parseFloat(a.index) - parseFloat(b.index);
|
||||
});
|
||||
}
|
||||
return CustomWizard.create(wizardJson);
|
||||
},
|
||||
});
|
||||
|
||||
export function findCustomWizard(wizardId, params = {}) {
|
||||
let url = `/w/${wizardId}.json`;
|
||||
|
||||
let paramKeys = Object.keys(params).filter((k) => {
|
||||
if (k === "wizard_id") {
|
||||
return false;
|
||||
}
|
||||
return !!params[k];
|
||||
});
|
||||
|
||||
if (paramKeys.length) {
|
||||
url += "?";
|
||||
paramKeys.forEach((k, i) => {
|
||||
if (i > 0) {
|
||||
url += "&";
|
||||
}
|
||||
url += `${k}=${params[k]}`;
|
||||
});
|
||||
}
|
||||
|
||||
return ajax(url).then((result) => {
|
||||
return CustomWizard.build(result);
|
||||
});
|
||||
}
|
||||
|
||||
let _wizard_store;
|
||||
|
||||
export function updateCachedWizard(wizard) {
|
||||
_wizard_store = wizard;
|
||||
}
|
||||
|
||||
export function getCachedWizard() {
|
||||
return _wizard_store;
|
||||
}
|
||||
|
||||
export default CustomWizard;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import CustomWizard from "../models/custom-wizard";
|
||||
import CustomWizardAdmin from "../models/custom-wizard-admin";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
model() {
|
||||
return CustomWizard.all();
|
||||
return CustomWizardAdmin.all();
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import CustomWizard from "../models/custom-wizard";
|
||||
import CustomWizardAdmin from "../models/custom-wizard-admin";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
|
||||
const excludedMetaFields = ["route_to", "redirect_on_complete", "redirect_to"];
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
model(params) {
|
||||
return CustomWizard.submissions(params.wizardId);
|
||||
return CustomWizardAdmin.submissions(params.wizardId);
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import CustomWizard from "../models/custom-wizard";
|
||||
import CustomWizardAdmin from "../models/custom-wizard-admin";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import I18n from "I18n";
|
||||
|
@ -20,7 +20,9 @@ export default DiscourseRoute.extend({
|
|||
|
||||
setupController(controller, model) {
|
||||
const parentModel = this.modelFor("adminWizardsWizard");
|
||||
const wizard = CustomWizard.create(!model || model.create ? {} : model);
|
||||
const wizard = CustomWizardAdmin.create(
|
||||
!model || model.create ? {} : model
|
||||
);
|
||||
const fieldTypes = Object.keys(parentModel.field_types).map((type) => {
|
||||
return {
|
||||
id: type,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { getCachedWizard } from "../models/wizard";
|
||||
import { getCachedWizard } from "../models/custom-wizard";
|
||||
import Route from "@ember/routing/route";
|
||||
|
||||
export default Route.extend({
|
||||
|
@ -11,7 +11,7 @@ export default Route.extend({
|
|||
!wizard.completed &&
|
||||
wizard.start
|
||||
) {
|
||||
this.replaceWith("step", wizard.start);
|
||||
this.replaceWith("customWizardStep", wizard.start);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -19,10 +19,6 @@ export default Route.extend({
|
|||
return getCachedWizard();
|
||||
},
|
||||
|
||||
renderTemplate() {
|
||||
this.render("wizard/templates/wizard-index");
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
if (model && model.id) {
|
||||
const completed = model.get("completed");
|
|
@ -1,5 +1,5 @@
|
|||
import WizardI18n from "../lib/wizard-i18n";
|
||||
import { getCachedWizard } from "../models/wizard";
|
||||
import I18n from "I18n";
|
||||
import { getCachedWizard } from "../models/custom-wizard";
|
||||
import Route from "@ember/routing/route";
|
||||
|
||||
export default Route.extend({
|
||||
|
@ -25,10 +25,6 @@ export default Route.extend({
|
|||
return model.set("wizardId", this.wizard.id);
|
||||
},
|
||||
|
||||
renderTemplate() {
|
||||
this.render("wizard/templates/step");
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
let props = {
|
||||
step: model,
|
||||
|
@ -38,8 +34,7 @@ export default Route.extend({
|
|||
if (!model.permitted) {
|
||||
props["stepMessage"] = {
|
||||
state: "not-permitted",
|
||||
text:
|
||||
model.permitted_message || WizardI18n("wizard.step_not_permitted"),
|
||||
text: model.permitted_message || I18n.t("wizard.step_not_permitted"),
|
||||
};
|
||||
if (model.index > 0) {
|
||||
props["showReset"] = true;
|
|
@ -1,10 +1,13 @@
|
|||
import { findCustomWizard, updateCachedWizard } from "../models/wizard";
|
||||
import WizardI18n from "../lib/wizard-i18n";
|
||||
import Route from "@ember/routing/route";
|
||||
import { scheduleOnce } from "@ember/runloop";
|
||||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
import { findCustomWizard, updateCachedWizard } from "../models/custom-wizard";
|
||||
import I18n from "I18n";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
titleToken() {
|
||||
const wizard = this.modelFor("custom-wizard");
|
||||
return wizard ? wizard.name || wizard.id : I18n.t("wizard.custom_title");
|
||||
},
|
||||
|
||||
export default Route.extend({
|
||||
beforeModel(transition) {
|
||||
if (transition.intent.queryParams) {
|
||||
this.set("queryParams", transition.intent.queryParams);
|
||||
|
@ -16,7 +19,7 @@ export default Route.extend({
|
|||
},
|
||||
|
||||
showDialog(wizardModel) {
|
||||
const title = WizardI18n("wizard.incomplete_submission.title", {
|
||||
const title = I18n.t("wizard.incomplete_submission.title", {
|
||||
date: moment(wizardModel.submission_last_updated_at).format(
|
||||
"MMMM Do YYYY"
|
||||
),
|
||||
|
@ -24,14 +27,14 @@ export default Route.extend({
|
|||
|
||||
const buttons = [
|
||||
{
|
||||
label: WizardI18n("wizard.incomplete_submission.restart"),
|
||||
label: I18n.t("wizard.incomplete_submission.restart"),
|
||||
class: "btn btn-default",
|
||||
callback: () => {
|
||||
wizardModel.restart();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: WizardI18n("wizard.incomplete_submission.resume"),
|
||||
label: I18n.t("wizard.incomplete_submission.resume"),
|
||||
class: "btn btn-primary",
|
||||
},
|
||||
];
|
||||
|
@ -47,25 +50,12 @@ export default Route.extend({
|
|||
updateCachedWizard(model);
|
||||
},
|
||||
|
||||
renderTemplate() {
|
||||
this.render("wizard/templates/wizard");
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
const background = model ? model.get("background") : "";
|
||||
|
||||
scheduleOnce("afterRender", this, function () {
|
||||
$("body").css("background", background);
|
||||
|
||||
if (model && model.id) {
|
||||
$(getOwner(this).rootElement).addClass(model.id.dasherize());
|
||||
}
|
||||
});
|
||||
|
||||
controller.setProperties({
|
||||
customWizard: true,
|
||||
logoUrl: this.siteSettings.logo_small,
|
||||
reset: null,
|
||||
model,
|
||||
});
|
||||
|
||||
const stepModel = this.modelFor("step");
|
||||
|
@ -76,5 +66,24 @@ export default Route.extend({
|
|||
) {
|
||||
this.showDialog(model);
|
||||
}
|
||||
|
||||
const background = model.get("background");
|
||||
if (background) {
|
||||
document.body.style.background = background;
|
||||
}
|
||||
},
|
||||
|
||||
activate() {
|
||||
if (!document.body.classList.contains("custom-wizard")) {
|
||||
document.body.classList.add("custom-wizard");
|
||||
}
|
||||
},
|
||||
|
||||
deactivate() {
|
||||
if (document.body.classList.contains("custom-wizard")) {
|
||||
document.body.classList.remove("custom-wizard");
|
||||
}
|
||||
|
||||
document.body.style.background = "";
|
||||
},
|
||||
});
|
|
@ -1,13 +1,13 @@
|
|||
<div class="wizard-composer-hyperlink-contents">
|
||||
<h3>{{wizard-i18n "composer.link_dialog_title"}}</h3>
|
||||
<h3>{{i18n "composer.link_dialog_title"}}</h3>
|
||||
{{input
|
||||
class="composer-link-name"
|
||||
placeholder=(wizard-i18n "composer.link_optional_text")
|
||||
placeholder=(i18n "composer.link_optional_text")
|
||||
type="text"
|
||||
value=linkName}}
|
||||
{{input
|
||||
class="composer-link-url"
|
||||
placeholder=(wizard-i18n "composer.link_url_placeholder")
|
||||
placeholder=(i18n "composer.link_url_placeholder")
|
||||
type="text"
|
||||
value=linkUrl}}
|
||||
{{d-button
|
|
@ -1,5 +1,5 @@
|
|||
{{#unless timeFirst}}
|
||||
{{wizard-date-input
|
||||
{{custom-wizard-date-input
|
||||
date=date
|
||||
relativeDate=relativeDate
|
||||
onChange=(action "onChangeDate")
|
||||
|
@ -8,7 +8,7 @@
|
|||
{{/unless}}
|
||||
|
||||
{{#if showTime}}
|
||||
{{wizard-time-input
|
||||
{{custom-wizard-time-input
|
||||
date=date
|
||||
relativeDate=relativeDate
|
||||
onChange=(action "onChangeTime")
|
||||
|
@ -17,7 +17,7 @@
|
|||
{{/if}}
|
||||
|
||||
{{#if timeFirst}}
|
||||
{{wizard-date-input
|
||||
{{custom-wizard-date-input
|
||||
date=date
|
||||
relativeDate=relativeDate
|
||||
onChange=(action "onChangeDate")
|
|
@ -27,7 +27,7 @@
|
|||
<button class="wizard-btn {{b.className}}" {{action b.action b}} title={{b.title}} type="button">
|
||||
{{d-icon b.icon}}
|
||||
{{#if b.label}}
|
||||
<span class="d-button-label">{{wizard-i18n b.label}}</span>
|
||||
<span class="d-button-label">{{i18n b.label}}</span>
|
||||
{{/if}}
|
||||
</button>
|
||||
{{/if}}
|
|
@ -0,0 +1,8 @@
|
|||
{{custom-wizard-category-selector
|
||||
categories=categories
|
||||
whitelist=field.content
|
||||
onChange=(action (mut categories))
|
||||
tabindex=field.tabindex
|
||||
options=(hash
|
||||
maximum=field.limit
|
||||
)}}
|
|
@ -1,4 +1,4 @@
|
|||
{{wizard-composer-editor
|
||||
{{custom-wizard-composer-editor
|
||||
field=field
|
||||
composer=composer
|
||||
wizard=wizard
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
<div class="bottom-bar">
|
||||
<button class="wizard-btn toggle-preview" {{action "togglePreview"}} type="button">
|
||||
<span class="d-button-label">{{wizard-i18n togglePreviewLabel}}</span>
|
||||
<span class="d-button-label">{{i18n togglePreviewLabel}}</span>
|
||||
</button>
|
||||
|
||||
{{#if field.char_counter}}
|
|
@ -1,4 +1,4 @@
|
|||
{{wizard-date-time-input
|
||||
{{custom-wizard-date-time-input
|
||||
date=dateTime
|
||||
onChange=(action "onChange")
|
||||
tabindex=field.tabindex
|
|
@ -1,4 +1,4 @@
|
|||
{{wizard-date-input
|
||||
{{custom-wizard-date-input
|
||||
date=date
|
||||
onChange=(action "onChange")
|
||||
tabindex=field.tabindex
|
|
@ -1,5 +1,5 @@
|
|||
{{wizard-group-selector
|
||||
groups=wizard.groups
|
||||
{{custom-wizard-group-selector
|
||||
groups=site.groups
|
||||
field=field
|
||||
whitelist=field.content
|
||||
value=field.value
|
|
@ -1,7 +1,8 @@
|
|||
{{wizard-tag-chooser
|
||||
{{custom-wizard-tag-chooser
|
||||
tags=field.value
|
||||
maximum=field.limit
|
||||
tabindex=field.tabindex
|
||||
tagGroups=field.tag_groups
|
||||
everyTag=true
|
||||
}}
|
||||
options=(hash
|
||||
maximum=field.limit
|
||||
)}}
|
|
@ -1,4 +1,4 @@
|
|||
{{wizard-time-input
|
||||
{{custom-wizard-time-input
|
||||
date=time
|
||||
onChange=(action "onChange")
|
||||
tabindex=field.tabindex
|
|
@ -1,8 +1,8 @@
|
|||
<label class="wizard-btn wizard-btn-upload-file {{if uploading "disabled"}}" tabindex={{field.tabindex}}>
|
||||
{{#if uploading}}
|
||||
{{wizard-i18n "wizard.uploading"}}
|
||||
{{i18n "wizard.uploading"}}
|
||||
{{else}}
|
||||
{{wizard-i18n "wizard.upload"}}
|
||||
{{i18n "wizard.upload"}}
|
||||
{{d-icon "upload"}}
|
||||
{{/if}}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<div>{{text}}</div>
|
||||
<div class="no-access-gutter">
|
||||
<button class="wizard-btn primary return-to-site" {{action "skip"}} type="button">
|
||||
{{wizard-i18n "wizard.return_to_site" siteName=siteName}}
|
||||
{{i18n "wizard.return_to_site" siteName=siteName}}
|
||||
{{d-icon "sign-out-alt"}}
|
||||
</button>
|
||||
</div>
|
|
@ -1,11 +1,11 @@
|
|||
{{#if showTopics}}
|
||||
<ul>
|
||||
{{#each topics as |topic|}}
|
||||
<li>{{wizard-similar-topic topic=topic}}</li>
|
||||
<li>{{custom-wizard-similar-topic topic=topic}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{else}}
|
||||
<a role="button" class="show-topics" {{action "toggleShowTopics"}}>
|
||||
{{wizard-i18n "realtime_validations.similar_topics.show"}}
|
||||
{{i18n "realtime_validations.similar_topics.show"}}
|
||||
</a>
|
||||
{{/if}}
|
|
@ -13,11 +13,11 @@
|
|||
<div class="wizard-step-description">{{cookedDescription}}</div>
|
||||
{{/if}}
|
||||
|
||||
{{#wizard-step-form step=step}}
|
||||
{{#custom-wizard-step-form step=step}}
|
||||
{{#each step.fields as |field|}}
|
||||
{{wizard-field field=field step=step wizard=wizard}}
|
||||
{{custom-wizard-field field=field step=step wizard=wizard}}
|
||||
{{/each}}
|
||||
{{/wizard-step-form}}
|
||||
{{/custom-wizard-step-form}}
|
||||
</div>
|
||||
|
||||
<div class="wizard-step-footer">
|
||||
|
@ -26,7 +26,7 @@
|
|||
<div class="white"></div>
|
||||
<div class="black" style={{barStyle}}></div>
|
||||
<div class="screen"></div>
|
||||
<span>{{wizard-i18n "wizard.step" current=step.displayIndex total=wizard.totalSteps}}</span>
|
||||
<span>{{i18n "wizard.step" current=step.displayIndex total=wizard.totalSteps}}</span>
|
||||
</div>
|
||||
|
||||
<div class="wizard-buttons">
|
||||
|
@ -34,23 +34,23 @@
|
|||
{{loading-spinner size="small"}}
|
||||
{{else}}
|
||||
{{#if showQuitButton}}
|
||||
<a href {{action "quit"}} class="action-link quit" tabindex={{secondaryButtonIndex}}>{{wizard-i18n "wizard.quit"}}</a>
|
||||
<a href {{action "quit"}} class="action-link quit" tabindex={{secondaryButtonIndex}}>{{i18n "wizard.quit"}}</a>
|
||||
{{/if}}
|
||||
{{#if showBackButton}}
|
||||
<a href {{action "backStep"}} class="action-link back" tabindex={{secondaryButtonIndex}}>{{wizard-i18n "wizard.back"}}</a>
|
||||
<a href {{action "backStep"}} class="action-link back" tabindex={{secondaryButtonIndex}}>{{i18n "wizard.back"}}</a>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{#if showNextButton}}
|
||||
<button type="button" class="wizard-btn next primary" {{action "nextStep"}} disabled={{saving}} tabindex={{primaryButtonIndex}}>
|
||||
{{wizard-i18n "wizard.next"}}
|
||||
{{i18n "wizard.next"}}
|
||||
{{d-icon "chevron-right"}}
|
||||
</button>
|
||||
{{/if}}
|
||||
|
||||
{{#if showDoneButton}}
|
||||
<button type="button" class="wizard-btn done" {{action "done"}} disabled={{saving}} tabindex={{primaryButtonIndex}}>
|
||||
{{wizard-i18n "wizard.done"}}
|
||||
{{i18n "wizard.done_custom"}}
|
||||
</button>
|
||||
{{/if}}
|
||||
</div>
|
|
@ -1,13 +1,13 @@
|
|||
<label class={{currentStateClass}}>
|
||||
{{#if currentState}}
|
||||
{{#if insufficientCharactersCategories}}
|
||||
{{html-safe (wizard-i18n currentStateKey catLinks=catLinks)}}
|
||||
{{html-safe (i18n currentStateKey catLinks=catLinks)}}
|
||||
{{else}}
|
||||
{{wizard-i18n currentStateKey}}
|
||||
{{i18n currentStateKey}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</label>
|
||||
|
||||
{{#if showSimilarTopics}}
|
||||
{{wizard-similar-topics topics=similarTopics}}
|
||||
{{custom-wizard-similar-topics topics=similarTopics}}
|
||||
{{/if}}
|
5
assets/javascripts/discourse/templates/components/validator.hbs
Normale Datei
5
assets/javascripts/discourse/templates/components/validator.hbs
Normale Datei
|
@ -0,0 +1,5 @@
|
|||
{{#if isValid}}
|
||||
{{i18n validMessageKey}}
|
||||
{{else}}
|
||||
{{i18n invalidMessageKey}}
|
||||
{{/if}}
|
3
assets/javascripts/discourse/templates/custom-wizard-index.hbs
Normale Datei
3
assets/javascripts/discourse/templates/custom-wizard-index.hbs
Normale Datei
|
@ -0,0 +1,3 @@
|
|||
{{#if noAccess}}
|
||||
{{custom-wizard-no-access text=(i18n noAccessI18nKey) wizardId=wizardId reason=noAccessReason}}
|
||||
{{/if}}
|
|
@ -5,13 +5,14 @@
|
|||
</div>
|
||||
{{#if showReset}}
|
||||
<a role="button" class="reset-wizard" {{action "resetWizard"}}>
|
||||
{{wizard-i18n "wizard.reset"}}
|
||||
{{i18n "wizard.reset"}}
|
||||
</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if step.permitted}}
|
||||
{{wizard-step step=step
|
||||
{{custom-wizard-step
|
||||
step=step
|
||||
wizard=wizard
|
||||
goNext=(action "goNext")
|
||||
goBack=(action "goBack")
|
|
@ -1,5 +0,0 @@
|
|||
//= require legacy/set-prototype-polyfill
|
||||
//= require legacy/env
|
||||
//= require legacy/jquery
|
||||
//= require legacy/ember_include
|
||||
//= require legacy/discourse-loader
|
717
assets/javascripts/legacy/bootbox.js
gevendort
717
assets/javascripts/legacy/bootbox.js
gevendort
|
@ -1,717 +0,0 @@
|
|||
// discourse-skip-module
|
||||
|
||||
/**
|
||||
* bootbox.js v3.2.0
|
||||
*
|
||||
* http://bootboxjs.com/license.txt
|
||||
*/
|
||||
var bootbox =
|
||||
window.bootbox ||
|
||||
(function (document, $) {
|
||||
/*jshint scripturl:true sub:true */
|
||||
|
||||
var _locale = "en",
|
||||
_defaultLocale = "en",
|
||||
_animate = true,
|
||||
_backdrop = "static",
|
||||
_defaultHref = "javascript:;",
|
||||
_classes = "",
|
||||
_btnClasses = {},
|
||||
_icons = {},
|
||||
/* last var should always be the public object we'll return */
|
||||
that = {};
|
||||
|
||||
/**
|
||||
* public API
|
||||
*/
|
||||
that.setLocale = function (locale) {
|
||||
for (var i in _locales) {
|
||||
if (i == locale) {
|
||||
_locale = locale;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error("Invalid locale: " + locale);
|
||||
};
|
||||
|
||||
that.addLocale = function (locale, translations) {
|
||||
if (typeof _locales[locale] === "undefined") {
|
||||
_locales[locale] = {};
|
||||
}
|
||||
for (var str in translations) {
|
||||
_locales[locale][str] = translations[str];
|
||||
}
|
||||
};
|
||||
|
||||
that.setIcons = function (icons) {
|
||||
_icons = icons;
|
||||
if (typeof _icons !== "object" || _icons === null) {
|
||||
_icons = {};
|
||||
}
|
||||
};
|
||||
|
||||
that.setBtnClasses = function (btnClasses) {
|
||||
_btnClasses = btnClasses;
|
||||
if (typeof _btnClasses !== "object" || _btnClasses === null) {
|
||||
_btnClasses = {};
|
||||
}
|
||||
};
|
||||
|
||||
that.alert = function (/*str, label, cb*/) {
|
||||
var str = "",
|
||||
label = _translate("OK"),
|
||||
cb = null;
|
||||
|
||||
switch (arguments.length) {
|
||||
case 1:
|
||||
// no callback, default button label
|
||||
str = arguments[0];
|
||||
break;
|
||||
case 2:
|
||||
// callback *or* custom button label dependent on type
|
||||
str = arguments[0];
|
||||
if (typeof arguments[1] == "function") {
|
||||
cb = arguments[1];
|
||||
} else {
|
||||
label = arguments[1];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// callback and custom button label
|
||||
str = arguments[0];
|
||||
label = arguments[1];
|
||||
cb = arguments[2];
|
||||
break;
|
||||
default:
|
||||
throw new Error("Incorrect number of arguments: expected 1-3");
|
||||
}
|
||||
|
||||
return that.dialog(
|
||||
str,
|
||||
{
|
||||
// only button (ok)
|
||||
label: label,
|
||||
icon: _icons.OK,
|
||||
class: _btnClasses.OK,
|
||||
callback: cb,
|
||||
},
|
||||
{
|
||||
// ensure that the escape key works; either invoking the user's
|
||||
// callback or true to just close the dialog
|
||||
onEscape: cb || true,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
that.confirm = function (/*str, labelCancel, labelOk, cb*/) {
|
||||
var str = "",
|
||||
labelCancel = _translate("CANCEL"),
|
||||
labelOk = _translate("CONFIRM"),
|
||||
cb = null;
|
||||
|
||||
switch (arguments.length) {
|
||||
case 1:
|
||||
str = arguments[0];
|
||||
break;
|
||||
case 2:
|
||||
str = arguments[0];
|
||||
if (typeof arguments[1] == "function") {
|
||||
cb = arguments[1];
|
||||
} else {
|
||||
labelCancel = arguments[1];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
str = arguments[0];
|
||||
labelCancel = arguments[1];
|
||||
if (typeof arguments[2] == "function") {
|
||||
cb = arguments[2];
|
||||
} else {
|
||||
labelOk = arguments[2];
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
str = arguments[0];
|
||||
labelCancel = arguments[1];
|
||||
labelOk = arguments[2];
|
||||
cb = arguments[3];
|
||||
break;
|
||||
default:
|
||||
throw new Error("Incorrect number of arguments: expected 1-4");
|
||||
}
|
||||
|
||||
var cancelCallback = function () {
|
||||
if (typeof cb === "function") {
|
||||
return cb(false);
|
||||
}
|
||||
};
|
||||
|
||||
var confirmCallback = function () {
|
||||
if (typeof cb === "function") {
|
||||
return cb(true);
|
||||
}
|
||||
};
|
||||
|
||||
return that.dialog(
|
||||
str,
|
||||
[
|
||||
{
|
||||
// first button (cancel)
|
||||
label: labelCancel,
|
||||
icon: _icons.CANCEL,
|
||||
class: _btnClasses.CANCEL,
|
||||
callback: cancelCallback,
|
||||
},
|
||||
{
|
||||
// second button (confirm)
|
||||
label: labelOk,
|
||||
icon: _icons.CONFIRM,
|
||||
class: _btnClasses.CONFIRM,
|
||||
callback: confirmCallback,
|
||||
},
|
||||
],
|
||||
{
|
||||
// escape key bindings
|
||||
onEscape: cancelCallback,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
that.prompt = function (/*str, labelCancel, labelOk, cb, defaultVal*/) {
|
||||
var str = "",
|
||||
labelCancel = _translate("CANCEL"),
|
||||
labelOk = _translate("CONFIRM"),
|
||||
cb = null,
|
||||
defaultVal = "";
|
||||
|
||||
switch (arguments.length) {
|
||||
case 1:
|
||||
str = arguments[0];
|
||||
break;
|
||||
case 2:
|
||||
str = arguments[0];
|
||||
if (typeof arguments[1] == "function") {
|
||||
cb = arguments[1];
|
||||
} else {
|
||||
labelCancel = arguments[1];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
str = arguments[0];
|
||||
labelCancel = arguments[1];
|
||||
if (typeof arguments[2] == "function") {
|
||||
cb = arguments[2];
|
||||
} else {
|
||||
labelOk = arguments[2];
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
str = arguments[0];
|
||||
labelCancel = arguments[1];
|
||||
labelOk = arguments[2];
|
||||
cb = arguments[3];
|
||||
break;
|
||||
case 5:
|
||||
str = arguments[0];
|
||||
labelCancel = arguments[1];
|
||||
labelOk = arguments[2];
|
||||
cb = arguments[3];
|
||||
defaultVal = arguments[4];
|
||||
break;
|
||||
default:
|
||||
throw new Error("Incorrect number of arguments: expected 1-5");
|
||||
}
|
||||
|
||||
var header = str;
|
||||
|
||||
// let's keep a reference to the form object for later
|
||||
var form = $("<form></form>");
|
||||
form.append(
|
||||
"<input class='input-block-level' autocomplete=off type=text value='" +
|
||||
defaultVal +
|
||||
"' />"
|
||||
);
|
||||
|
||||
var cancelCallback = function () {
|
||||
if (typeof cb === "function") {
|
||||
// yep, native prompts dismiss with null, whereas native
|
||||
// confirms dismiss with false...
|
||||
return cb(null);
|
||||
}
|
||||
};
|
||||
|
||||
var confirmCallback = function () {
|
||||
if (typeof cb === "function") {
|
||||
return cb(form.find("input[type=text]").val());
|
||||
}
|
||||
};
|
||||
|
||||
var div = that.dialog(
|
||||
form,
|
||||
[
|
||||
{
|
||||
// first button (cancel)
|
||||
label: labelCancel,
|
||||
icon: _icons.CANCEL,
|
||||
class: _btnClasses.CANCEL,
|
||||
callback: cancelCallback,
|
||||
},
|
||||
{
|
||||
// second button (confirm)
|
||||
label: labelOk,
|
||||
icon: _icons.CONFIRM,
|
||||
class: _btnClasses.CONFIRM,
|
||||
callback: confirmCallback,
|
||||
},
|
||||
],
|
||||
{
|
||||
// prompts need a few extra options
|
||||
header: header,
|
||||
// explicitly tell dialog NOT to show the dialog...
|
||||
show: false,
|
||||
onEscape: cancelCallback,
|
||||
}
|
||||
);
|
||||
|
||||
// ... the reason the prompt needs to be hidden is because we need
|
||||
// to bind our own "shown" handler, after creating the modal but
|
||||
// before any show(n) events are triggered
|
||||
// @see https://github.com/makeusabrew/bootbox/issues/69
|
||||
|
||||
div.on("shown", function () {
|
||||
form.find("input[type=text]").focus();
|
||||
|
||||
// ensure that submitting the form (e.g. with the enter key)
|
||||
// replicates the behaviour of a normal prompt()
|
||||
form.on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
div.find(".btn-primary").click();
|
||||
});
|
||||
});
|
||||
|
||||
div.modal("show");
|
||||
|
||||
return div;
|
||||
};
|
||||
|
||||
that.dialog = function (str, handlers, options) {
|
||||
var buttons = "",
|
||||
callbacks = [];
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
// check for single object and convert to array if necessary
|
||||
if (typeof handlers === "undefined") {
|
||||
handlers = [];
|
||||
} else if (typeof handlers.length == "undefined") {
|
||||
handlers = [handlers];
|
||||
}
|
||||
|
||||
var i = handlers.length;
|
||||
while (i--) {
|
||||
var label = null,
|
||||
href = null,
|
||||
_class = "btn-default",
|
||||
icon = "",
|
||||
callback = null;
|
||||
|
||||
if (
|
||||
typeof handlers[i]["label"] == "undefined" &&
|
||||
typeof handlers[i]["class"] == "undefined" &&
|
||||
typeof handlers[i]["callback"] == "undefined"
|
||||
) {
|
||||
// if we've got nothing we expect, check for condensed format
|
||||
|
||||
var propCount = 0, // condensed will only match if this == 1
|
||||
property = null; // save the last property we found
|
||||
|
||||
// be nicer to count the properties without this, but don't think it's possible...
|
||||
for (var j in handlers[i]) {
|
||||
property = j;
|
||||
if (++propCount > 1) {
|
||||
// forget it, too many properties
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (propCount == 1 && typeof handlers[i][j] == "function") {
|
||||
// matches condensed format of label -> function
|
||||
handlers[i]["label"] = property;
|
||||
handlers[i]["callback"] = handlers[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof handlers[i]["callback"] == "function") {
|
||||
callback = handlers[i]["callback"];
|
||||
}
|
||||
|
||||
if (handlers[i]["class"]) {
|
||||
_class = handlers[i]["class"];
|
||||
} else if (i == handlers.length - 1 && handlers.length <= 2) {
|
||||
// always add a primary to the main option in a two-button dialog
|
||||
_class = "btn-primary";
|
||||
}
|
||||
|
||||
// See: https://github.com/makeusabrew/bootbox/pull/114
|
||||
// Upgrade to official bootbox release when it gets merged.
|
||||
if (handlers[i]["link"] !== true) {
|
||||
_class = "btn " + _class;
|
||||
}
|
||||
|
||||
if (handlers[i]["label"]) {
|
||||
label = handlers[i]["label"];
|
||||
} else {
|
||||
label = "Option " + (i + 1);
|
||||
}
|
||||
|
||||
if (handlers[i]["icon"]) {
|
||||
icon = handlers[i]["icon"];
|
||||
}
|
||||
|
||||
if (handlers[i]["href"]) {
|
||||
href = handlers[i]["href"];
|
||||
} else {
|
||||
href = _defaultHref;
|
||||
}
|
||||
|
||||
buttons =
|
||||
buttons +
|
||||
"<a data-handler='" +
|
||||
i +
|
||||
"' class='" +
|
||||
_class +
|
||||
"' href='" +
|
||||
href +
|
||||
"'>" +
|
||||
icon +
|
||||
"<span class='d-button-label'>" +
|
||||
label +
|
||||
"</span></a>";
|
||||
|
||||
callbacks[i] = callback;
|
||||
}
|
||||
|
||||
// @see https://github.com/makeusabrew/bootbox/issues/46#issuecomment-8235302
|
||||
// and https://github.com/twitter/bootstrap/issues/4474
|
||||
// for an explanation of the inline overflow: hidden
|
||||
// @see https://github.com/twitter/bootstrap/issues/4854
|
||||
// for an explanation of tabIndex=-1
|
||||
|
||||
var parts = [
|
||||
"<div class='bootbox modal' tabindex='-1' style='overflow:hidden;'>",
|
||||
];
|
||||
|
||||
if (options["header"]) {
|
||||
var closeButton = "";
|
||||
if (
|
||||
typeof options["headerCloseButton"] == "undefined" ||
|
||||
options["headerCloseButton"]
|
||||
) {
|
||||
closeButton =
|
||||
"<a href='" + _defaultHref + "' class='close'>×</a>";
|
||||
}
|
||||
|
||||
parts.push(
|
||||
"<div class='modal-header'>" +
|
||||
closeButton +
|
||||
"<h3>" +
|
||||
options["header"] +
|
||||
"</h3></div>"
|
||||
);
|
||||
}
|
||||
|
||||
// push an empty body into which we'll inject the proper content later
|
||||
parts.push("<div class='modal-body'></div>");
|
||||
|
||||
if (buttons) {
|
||||
parts.push("<div class='modal-footer'>" + buttons + "</div>");
|
||||
}
|
||||
|
||||
parts.push("</div>");
|
||||
|
||||
var div = $(parts.join("\n"));
|
||||
|
||||
// check whether we should fade in/out
|
||||
var shouldFade =
|
||||
typeof options.animate === "undefined" ? _animate : options.animate;
|
||||
|
||||
if (shouldFade) {
|
||||
div.addClass("fade");
|
||||
}
|
||||
|
||||
var optionalClasses =
|
||||
typeof options.classes === "undefined" ? _classes : options.classes;
|
||||
if (optionalClasses) {
|
||||
div.addClass(optionalClasses);
|
||||
}
|
||||
|
||||
// now we've built up the div properly we can inject the content whether it was a string or a jQuery object
|
||||
div.find(".modal-body").html(str);
|
||||
|
||||
function onCancel(source) {
|
||||
// for now source is unused, but it will be in future
|
||||
var hideModal = null;
|
||||
if (typeof options.onEscape === "function") {
|
||||
// @see https://github.com/makeusabrew/bootbox/issues/91
|
||||
hideModal = options.onEscape();
|
||||
}
|
||||
|
||||
if (hideModal !== false) {
|
||||
div.modal("hide");
|
||||
}
|
||||
}
|
||||
|
||||
// hook into the modal's keyup trigger to check for the escape key
|
||||
div.on("keyup.dismiss.modal", function (e) {
|
||||
// any truthy value passed to onEscape will dismiss the dialog
|
||||
// as long as the onEscape function (if defined) doesn't prevent it
|
||||
if (e.which === 27 && options.onEscape !== false) {
|
||||
onCancel("escape");
|
||||
}
|
||||
});
|
||||
|
||||
// handle close buttons too
|
||||
div.on("click", "a.close", function (e) {
|
||||
e.preventDefault();
|
||||
onCancel("close");
|
||||
});
|
||||
|
||||
// well, *if* we have a primary - give the first dom element focus
|
||||
div.on("shown.bs.modal", function () {
|
||||
div.find("a.btn-primary:first").focus();
|
||||
});
|
||||
|
||||
div.on("hidden.bs.modal", function () {
|
||||
div.remove();
|
||||
});
|
||||
|
||||
// wire up button handlers
|
||||
div.on("click", ".modal-footer a", function (e) {
|
||||
var self = this;
|
||||
Ember.run(function () {
|
||||
var handler = $(self).data("handler"),
|
||||
cb = callbacks[handler],
|
||||
hideModal = null;
|
||||
|
||||
// sort of @see https://github.com/makeusabrew/bootbox/pull/68 - heavily adapted
|
||||
// if we've got a custom href attribute, all bets are off
|
||||
if (
|
||||
typeof handler !== "undefined" &&
|
||||
typeof handlers[handler]["href"] !== "undefined"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if (typeof cb === "function") {
|
||||
hideModal = cb(e);
|
||||
}
|
||||
|
||||
// the only way hideModal *will* be false is if a callback exists and
|
||||
// returns it as a value. in those situations, don't hide the dialog
|
||||
// @see https://github.com/makeusabrew/bootbox/pull/25
|
||||
if (hideModal !== false) {
|
||||
div.modal("hide");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// stick the modal right at the bottom of the main body out of the way
|
||||
(that.$body || $("body")).append(div);
|
||||
|
||||
div.modal({
|
||||
// unless explicitly overridden take whatever our default backdrop value is
|
||||
backdrop:
|
||||
typeof options.backdrop === "undefined"
|
||||
? _backdrop
|
||||
: options.backdrop,
|
||||
// ignore bootstrap's keyboard options; we'll handle this ourselves (more fine-grained control)
|
||||
keyboard: false,
|
||||
// @ see https://github.com/makeusabrew/bootbox/issues/69
|
||||
// we *never* want the modal to be shown before we can bind stuff to it
|
||||
// this method can also take a 'show' option, but we'll only use that
|
||||
// later if we need to
|
||||
show: false,
|
||||
});
|
||||
|
||||
// @see https://github.com/makeusabrew/bootbox/issues/64
|
||||
// @see https://github.com/makeusabrew/bootbox/issues/60
|
||||
// ...caused by...
|
||||
// @see https://github.com/twitter/bootstrap/issues/4781
|
||||
div.on("show", function (e) {
|
||||
$(document).off("focusin.modal");
|
||||
});
|
||||
|
||||
if (typeof options.show === "undefined" || options.show === true) {
|
||||
div.modal("show");
|
||||
}
|
||||
|
||||
return div;
|
||||
};
|
||||
|
||||
/**
|
||||
* #modal is deprecated in v3; it can still be used but no guarantees are
|
||||
* made - have never been truly convinced of its merit but perhaps just
|
||||
* needs a tidyup and some TLC
|
||||
*/
|
||||
that.modal = function (/*str, label, options*/) {
|
||||
var str;
|
||||
var label;
|
||||
var options;
|
||||
|
||||
var defaultOptions = {
|
||||
onEscape: null,
|
||||
keyboard: true,
|
||||
backdrop: _backdrop,
|
||||
};
|
||||
|
||||
switch (arguments.length) {
|
||||
case 1:
|
||||
str = arguments[0];
|
||||
break;
|
||||
case 2:
|
||||
str = arguments[0];
|
||||
if (typeof arguments[1] == "object") {
|
||||
options = arguments[1];
|
||||
} else {
|
||||
label = arguments[1];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
str = arguments[0];
|
||||
label = arguments[1];
|
||||
options = arguments[2];
|
||||
break;
|
||||
default:
|
||||
throw new Error("Incorrect number of arguments: expected 1-3");
|
||||
}
|
||||
|
||||
defaultOptions["header"] = label;
|
||||
|
||||
if (typeof options == "object") {
|
||||
options = $.extend(defaultOptions, options);
|
||||
} else {
|
||||
options = defaultOptions;
|
||||
}
|
||||
|
||||
return that.dialog(str, [], options);
|
||||
};
|
||||
|
||||
that.hideAll = function () {
|
||||
$(".bootbox").modal("hide");
|
||||
};
|
||||
|
||||
that.animate = function (animate) {
|
||||
_animate = animate;
|
||||
};
|
||||
|
||||
that.backdrop = function (backdrop) {
|
||||
_backdrop = backdrop;
|
||||
};
|
||||
|
||||
that.classes = function (classes) {
|
||||
_classes = classes;
|
||||
};
|
||||
|
||||
/**
|
||||
* private API
|
||||
*/
|
||||
|
||||
/**
|
||||
* standard locales. Please add more according to ISO 639-1 standard. Multiple language variants are
|
||||
* unlikely to be required. If this gets too large it can be split out into separate JS files.
|
||||
*/
|
||||
var _locales = {
|
||||
br: {
|
||||
OK: "OK",
|
||||
CANCEL: "Cancelar",
|
||||
CONFIRM: "Sim",
|
||||
},
|
||||
da: {
|
||||
OK: "OK",
|
||||
CANCEL: "Annuller",
|
||||
CONFIRM: "Accepter",
|
||||
},
|
||||
de: {
|
||||
OK: "OK",
|
||||
CANCEL: "Abbrechen",
|
||||
CONFIRM: "Akzeptieren",
|
||||
},
|
||||
en: {
|
||||
OK: "OK",
|
||||
CANCEL: "Cancel",
|
||||
CONFIRM: "OK",
|
||||
},
|
||||
es: {
|
||||
OK: "OK",
|
||||
CANCEL: "Cancelar",
|
||||
CONFIRM: "Aceptar",
|
||||
},
|
||||
fr: {
|
||||
OK: "OK",
|
||||
CANCEL: "Annuler",
|
||||
CONFIRM: "D'accord",
|
||||
},
|
||||
it: {
|
||||
OK: "OK",
|
||||
CANCEL: "Annulla",
|
||||
CONFIRM: "Conferma",
|
||||
},
|
||||
nl: {
|
||||
OK: "OK",
|
||||
CANCEL: "Annuleren",
|
||||
CONFIRM: "Accepteren",
|
||||
},
|
||||
pl: {
|
||||
OK: "OK",
|
||||
CANCEL: "Anuluj",
|
||||
CONFIRM: "Potwierdź",
|
||||
},
|
||||
ru: {
|
||||
OK: "OK",
|
||||
CANCEL: "Отмена",
|
||||
CONFIRM: "Применить",
|
||||
},
|
||||
zh_CN: {
|
||||
OK: "OK",
|
||||
CANCEL: "取消",
|
||||
CONFIRM: "确认",
|
||||
},
|
||||
zh_TW: {
|
||||
OK: "OK",
|
||||
CANCEL: "取消",
|
||||
CONFIRM: "確認",
|
||||
},
|
||||
};
|
||||
|
||||
function _translate(str, locale) {
|
||||
// we assume if no target locale is probided then we should take it from current setting
|
||||
if (typeof locale === "undefined") {
|
||||
locale = _locale;
|
||||
}
|
||||
if (typeof _locales[locale][str] === "string") {
|
||||
return _locales[locale][str];
|
||||
}
|
||||
|
||||
// if we couldn't find a lookup then try and fallback to a default translation
|
||||
|
||||
if (locale != _defaultLocale) {
|
||||
return _translate(str, _defaultLocale);
|
||||
}
|
||||
|
||||
// if we can't do anything then bail out with whatever string was passed in - last resort
|
||||
return str;
|
||||
}
|
||||
|
||||
return that;
|
||||
})(document, window.jQuery);
|
||||
|
||||
// @see https://github.com/makeusabrew/bootbox/issues/71
|
||||
window.bootbox = bootbox;
|
||||
|
||||
define("bootbox", ["exports"], function (__exports__) {
|
||||
__exports__.default = window.bootbox;
|
||||
});
|
360
assets/javascripts/legacy/bootstrap-modal.js
gevendort
360
assets/javascripts/legacy/bootstrap-modal.js
gevendort
|
@ -1,360 +0,0 @@
|
|||
// discourse-skip-module
|
||||
|
||||
/* ========================================================================
|
||||
* Bootstrap: modal.js v3.4.1
|
||||
* https://getbootstrap.com/docs/3.4/javascript/#modals
|
||||
* ========================================================================
|
||||
* Copyright 2011-2019 Twitter, Inc.
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
+function ($) {
|
||||
'use strict';
|
||||
|
||||
// MODAL CLASS DEFINITION
|
||||
// ======================
|
||||
|
||||
var Modal = function (element, options) {
|
||||
this.options = options
|
||||
this.$body = $(document.body)
|
||||
this.$element = $(element)
|
||||
this.$dialog = this.$element.find('.modal-dialog')
|
||||
this.$backdrop = null
|
||||
this.isShown = null
|
||||
this.originalBodyPad = null
|
||||
this.scrollbarWidth = 0
|
||||
this.ignoreBackdropClick = false
|
||||
this.fixedContent = '.navbar-fixed-top, .navbar-fixed-bottom'
|
||||
|
||||
if (this.options.remote) {
|
||||
this.$element
|
||||
.find('.modal-content')
|
||||
.load(this.options.remote, $.proxy(function () {
|
||||
this.$element.trigger('loaded.bs.modal')
|
||||
}, this))
|
||||
}
|
||||
}
|
||||
|
||||
Modal.VERSION = '3.4.1'
|
||||
|
||||
Modal.TRANSITION_DURATION = 300
|
||||
Modal.BACKDROP_TRANSITION_DURATION = 150
|
||||
|
||||
Modal.DEFAULTS = {
|
||||
backdrop: true,
|
||||
keyboard: true,
|
||||
show: true
|
||||
}
|
||||
|
||||
Modal.prototype.toggle = function (_relatedTarget) {
|
||||
return this.isShown ? this.hide() : this.show(_relatedTarget)
|
||||
}
|
||||
|
||||
Modal.prototype.show = function (_relatedTarget) {
|
||||
var that = this
|
||||
var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget })
|
||||
|
||||
this.$element.trigger(e)
|
||||
|
||||
if (this.isShown || e.isDefaultPrevented()) return
|
||||
|
||||
this.isShown = true
|
||||
|
||||
this.checkScrollbar()
|
||||
this.setScrollbar()
|
||||
this.$body.addClass('modal-open')
|
||||
|
||||
this.escape()
|
||||
this.resize()
|
||||
|
||||
this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
|
||||
|
||||
this.$dialog.on('mousedown.dismiss.bs.modal', function () {
|
||||
that.$element.one('mouseup.dismiss.bs.modal', function (e) {
|
||||
if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true
|
||||
})
|
||||
})
|
||||
|
||||
this.backdrop(function () {
|
||||
var transition = $.support.transition && that.$element.hasClass('fade')
|
||||
|
||||
if (!that.$element.parent().length) {
|
||||
that.$element.appendTo(that.$body) // don't move modals dom position
|
||||
}
|
||||
|
||||
that.$element
|
||||
.show()
|
||||
.scrollTop(0)
|
||||
|
||||
that.adjustDialog()
|
||||
|
||||
if (transition) {
|
||||
that.$element[0].offsetWidth // force reflow
|
||||
}
|
||||
|
||||
that.$element.addClass('in')
|
||||
|
||||
that.enforceFocus()
|
||||
|
||||
var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
|
||||
|
||||
transition ?
|
||||
that.$dialog // wait for modal to slide in
|
||||
.one('bsTransitionEnd', function () {
|
||||
that.$element.trigger('focus').trigger(e)
|
||||
})
|
||||
.emulateTransitionEnd(Modal.TRANSITION_DURATION) :
|
||||
that.$element.trigger('focus').trigger(e)
|
||||
})
|
||||
}
|
||||
|
||||
Modal.prototype.hide = function (e) {
|
||||
if (e) e.preventDefault()
|
||||
|
||||
e = $.Event('hide.bs.modal')
|
||||
|
||||
this.$element.trigger(e)
|
||||
|
||||
if (!this.isShown || e.isDefaultPrevented()) return
|
||||
|
||||
this.isShown = false
|
||||
|
||||
this.escape()
|
||||
this.resize()
|
||||
|
||||
$(document).off('focusin.bs.modal')
|
||||
|
||||
this.$element
|
||||
.removeClass('in')
|
||||
.off('click.dismiss.bs.modal')
|
||||
.off('mouseup.dismiss.bs.modal')
|
||||
|
||||
this.$dialog.off('mousedown.dismiss.bs.modal')
|
||||
|
||||
$.support.transition && this.$element.hasClass('fade') ?
|
||||
this.$element
|
||||
.one('bsTransitionEnd', $.proxy(this.hideModal, this))
|
||||
.emulateTransitionEnd(Modal.TRANSITION_DURATION) :
|
||||
this.hideModal()
|
||||
}
|
||||
|
||||
Modal.prototype.enforceFocus = function () {
|
||||
$(document)
|
||||
.off('focusin.bs.modal') // guard against infinite focus loop
|
||||
.on('focusin.bs.modal', $.proxy(function (e) {
|
||||
if (document !== e.target &&
|
||||
this.$element[0] !== e.target &&
|
||||
!this.$element.has(e.target).length) {
|
||||
this.$element.trigger('focus')
|
||||
}
|
||||
}, this))
|
||||
}
|
||||
|
||||
Modal.prototype.escape = function () {
|
||||
if (this.isShown && this.options.keyboard) {
|
||||
this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) {
|
||||
e.which == 27 && this.hide()
|
||||
}, this))
|
||||
} else if (!this.isShown) {
|
||||
this.$element.off('keydown.dismiss.bs.modal')
|
||||
}
|
||||
}
|
||||
|
||||
Modal.prototype.resize = function () {
|
||||
if (this.isShown) {
|
||||
$(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this))
|
||||
} else {
|
||||
$(window).off('resize.bs.modal')
|
||||
}
|
||||
}
|
||||
|
||||
Modal.prototype.hideModal = function () {
|
||||
var that = this
|
||||
this.$element.hide()
|
||||
this.backdrop(function () {
|
||||
that.$body.removeClass('modal-open')
|
||||
that.resetAdjustments()
|
||||
that.resetScrollbar()
|
||||
that.$element.trigger('hidden.bs.modal')
|
||||
})
|
||||
}
|
||||
|
||||
Modal.prototype.removeBackdrop = function () {
|
||||
this.$backdrop && this.$backdrop.remove()
|
||||
this.$backdrop = null
|
||||
}
|
||||
|
||||
Modal.prototype.backdrop = function (callback) {
|
||||
var that = this
|
||||
var animate = this.$element.hasClass('fade') ? 'fade' : ''
|
||||
|
||||
if (this.isShown && this.options.backdrop) {
|
||||
var doAnimate = $.support.transition && animate
|
||||
|
||||
this.$backdrop = $(document.createElement('div'))
|
||||
.addClass('modal-backdrop ' + animate)
|
||||
.appendTo(this.$body)
|
||||
|
||||
this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
|
||||
if (this.ignoreBackdropClick) {
|
||||
this.ignoreBackdropClick = false
|
||||
return
|
||||
}
|
||||
if (e.target !== e.currentTarget) return
|
||||
this.options.backdrop == 'static'
|
||||
? this.$element[0].focus()
|
||||
: this.hide()
|
||||
}, this))
|
||||
|
||||
if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
|
||||
|
||||
this.$backdrop.addClass('in')
|
||||
|
||||
if (!callback) return
|
||||
|
||||
doAnimate ?
|
||||
this.$backdrop
|
||||
.one('bsTransitionEnd', callback)
|
||||
.emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
|
||||
callback()
|
||||
|
||||
} else if (!this.isShown && this.$backdrop) {
|
||||
this.$backdrop.removeClass('in')
|
||||
|
||||
var callbackRemove = function () {
|
||||
that.removeBackdrop()
|
||||
callback && callback()
|
||||
}
|
||||
$.support.transition && this.$element.hasClass('fade') ?
|
||||
this.$backdrop
|
||||
.one('bsTransitionEnd', callbackRemove)
|
||||
.emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
|
||||
callbackRemove()
|
||||
|
||||
} else if (callback) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
// these following methods are used to handle overflowing modals
|
||||
|
||||
Modal.prototype.handleUpdate = function () {
|
||||
this.adjustDialog()
|
||||
}
|
||||
|
||||
Modal.prototype.adjustDialog = function () {
|
||||
var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight
|
||||
|
||||
this.$element.css({
|
||||
paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '',
|
||||
paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
|
||||
})
|
||||
}
|
||||
|
||||
Modal.prototype.resetAdjustments = function () {
|
||||
this.$element.css({
|
||||
paddingLeft: '',
|
||||
paddingRight: ''
|
||||
})
|
||||
}
|
||||
|
||||
Modal.prototype.checkScrollbar = function () {
|
||||
var fullWindowWidth = window.innerWidth
|
||||
if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
|
||||
var documentElementRect = document.documentElement.getBoundingClientRect()
|
||||
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left)
|
||||
}
|
||||
this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth
|
||||
this.scrollbarWidth = this.measureScrollbar()
|
||||
}
|
||||
|
||||
Modal.prototype.setScrollbar = function () {
|
||||
var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
|
||||
this.originalBodyPad = document.body.style.paddingRight || ''
|
||||
var scrollbarWidth = this.scrollbarWidth
|
||||
if (this.bodyIsOverflowing) {
|
||||
this.$body.css('padding-right', bodyPad + scrollbarWidth)
|
||||
$(this.fixedContent).each(function (index, element) {
|
||||
var actualPadding = element.style.paddingRight
|
||||
var calculatedPadding = $(element).css('padding-right')
|
||||
$(element)
|
||||
.data('padding-right', actualPadding)
|
||||
.css('padding-right', parseFloat(calculatedPadding) + scrollbarWidth + 'px')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Modal.prototype.resetScrollbar = function () {
|
||||
this.$body.css('padding-right', this.originalBodyPad)
|
||||
$(this.fixedContent).each(function (index, element) {
|
||||
var padding = $(element).data('padding-right')
|
||||
$(element).removeData('padding-right')
|
||||
element.style.paddingRight = padding ? padding : ''
|
||||
})
|
||||
}
|
||||
|
||||
Modal.prototype.measureScrollbar = function () { // thx walsh
|
||||
var scrollDiv = document.createElement('div')
|
||||
scrollDiv.className = 'modal-scrollbar-measure'
|
||||
this.$body.append(scrollDiv)
|
||||
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
|
||||
this.$body[0].removeChild(scrollDiv)
|
||||
return scrollbarWidth
|
||||
}
|
||||
|
||||
|
||||
// MODAL PLUGIN DEFINITION
|
||||
// =======================
|
||||
|
||||
function Plugin(option, _relatedTarget) {
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
var data = $this.data('bs.modal')
|
||||
var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)
|
||||
|
||||
if (!data) $this.data('bs.modal', (data = new Modal(this, options)))
|
||||
if (typeof option == 'string') data[option](_relatedTarget)
|
||||
else if (options.show) data.show(_relatedTarget)
|
||||
})
|
||||
}
|
||||
|
||||
var old = $.fn.modal
|
||||
|
||||
$.fn.modal = Plugin
|
||||
$.fn.modal.Constructor = Modal
|
||||
|
||||
|
||||
// MODAL NO CONFLICT
|
||||
// =================
|
||||
|
||||
$.fn.modal.noConflict = function () {
|
||||
$.fn.modal = old
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
// MODAL DATA-API
|
||||
// ==============
|
||||
|
||||
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
|
||||
var $this = $(this)
|
||||
var href = $this.attr('href')
|
||||
var target = $this.attr('data-target') ||
|
||||
(href && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
|
||||
|
||||
var $target = $(document).find(target)
|
||||
var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
|
||||
|
||||
if ($this.is('a')) e.preventDefault()
|
||||
|
||||
$target.one('show.bs.modal', function (showEvent) {
|
||||
if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
|
||||
$target.one('hidden.bs.modal', function () {
|
||||
$this.is(':visible') && $this.trigger('focus')
|
||||
})
|
||||
})
|
||||
Plugin.call($target, option, this)
|
||||
})
|
||||
|
||||
}(jQuery);
|
|
@ -1,164 +0,0 @@
|
|||
// discourse-skip-module
|
||||
|
||||
// TODO: This code should be moved to lib, it was heavily modified by us over the years, and mostly written by us
|
||||
// except for the little snippet from StackOverflow
|
||||
//
|
||||
// http://stackoverflow.com/questions/263743/how-to-get-caret-position-in-textarea
|
||||
var clone = null;
|
||||
|
||||
$.fn.caret = function(elem) {
|
||||
var getCaret = function(el) {
|
||||
if (el.selectionStart) {
|
||||
return el.selectionStart;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
return getCaret(elem || this[0]);
|
||||
};
|
||||
|
||||
/**
|
||||
This is a jQuery plugin to retrieve the caret position in a textarea
|
||||
|
||||
@module $.fn.caretPosition
|
||||
**/
|
||||
$.fn.caretPosition = function(options) {
|
||||
var after,
|
||||
before,
|
||||
getStyles,
|
||||
guard,
|
||||
html,
|
||||
important,
|
||||
insertSpaceAfterBefore,
|
||||
letter,
|
||||
makeCursor,
|
||||
p,
|
||||
pPos,
|
||||
pos,
|
||||
span,
|
||||
styles,
|
||||
textarea,
|
||||
val;
|
||||
if (clone) {
|
||||
clone.remove();
|
||||
}
|
||||
span = $("#pos span");
|
||||
textarea = $(this);
|
||||
|
||||
getStyles = function(el) {
|
||||
if (el.currentStyle) {
|
||||
return el.currentStyle;
|
||||
} else {
|
||||
return document.defaultView.getComputedStyle(el, "");
|
||||
}
|
||||
};
|
||||
|
||||
important = function(prop) {
|
||||
return styles.getPropertyValue(prop);
|
||||
};
|
||||
|
||||
styles = getStyles(textarea[0]);
|
||||
clone = $("<div><p></p></div>").appendTo("body");
|
||||
p = clone.find("p");
|
||||
|
||||
var isRTL = $("html").hasClass("rtl");
|
||||
clone.css({
|
||||
border: "1px solid black",
|
||||
padding: important("padding"),
|
||||
resize: important("resize"),
|
||||
"max-height": textarea.height() + "px",
|
||||
"overflow-y": "auto",
|
||||
"word-wrap": "break-word",
|
||||
position: "absolute",
|
||||
left: isRTL ? "auto" : "-7000px",
|
||||
right: isRTL ? "-7000px" : "auto"
|
||||
});
|
||||
|
||||
p.css({
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
"word-wrap": "break-word",
|
||||
"letter-spacing": important("letter-spacing"),
|
||||
"font-family": important("font-family"),
|
||||
"font-size": important("font-size"),
|
||||
"line-height": important("line-height")
|
||||
});
|
||||
|
||||
clone.width(textarea.width());
|
||||
clone.height(textarea.height());
|
||||
|
||||
pos =
|
||||
options && (options.pos || options.pos === 0)
|
||||
? options.pos
|
||||
: $.caret(textarea[0]);
|
||||
|
||||
val = textarea.val().replace("\r", "");
|
||||
if (options && options.key) {
|
||||
val = val.substring(0, pos) + options.key + val.substring(pos);
|
||||
}
|
||||
before = pos - 1;
|
||||
after = pos;
|
||||
insertSpaceAfterBefore = false;
|
||||
|
||||
// if before and after are \n insert a space
|
||||
if (val[before] === "\n" && val[after] === "\n") {
|
||||
insertSpaceAfterBefore = true;
|
||||
}
|
||||
|
||||
guard = function(v) {
|
||||
var buf;
|
||||
buf = v.replace(/</g, "<");
|
||||
buf = buf.replace(/>/g, ">");
|
||||
buf = buf.replace(/[ ]/g, "​ ​");
|
||||
return buf.replace(/\n/g, "<br />");
|
||||
};
|
||||
|
||||
makeCursor = function(pos, klass, color) {
|
||||
var l;
|
||||
l = val.substring(pos, pos + 1);
|
||||
if (l === "\n") return "<br>";
|
||||
return (
|
||||
"<span class='" +
|
||||
klass +
|
||||
"' style='background-color:" +
|
||||
color +
|
||||
"; margin:0; padding: 0'>" +
|
||||
guard(l) +
|
||||
"</span>"
|
||||
);
|
||||
};
|
||||
|
||||
html = "";
|
||||
|
||||
if (before >= 0) {
|
||||
html +=
|
||||
guard(val.substring(0, pos - 1)) +
|
||||
makeCursor(before, "before", "#d0ffff");
|
||||
if (insertSpaceAfterBefore) {
|
||||
html += makeCursor(0, "post-before", "#d0ffff");
|
||||
}
|
||||
}
|
||||
|
||||
if (after >= 0) {
|
||||
html += makeCursor(after, "after", "#ffd0ff");
|
||||
if (after - 1 < val.length) {
|
||||
html += guard(val.substring(after + 1));
|
||||
}
|
||||
}
|
||||
|
||||
p.html(html);
|
||||
clone.scrollTop(textarea.scrollTop());
|
||||
letter = p.find("span:first");
|
||||
pos = letter.offset();
|
||||
if (letter.hasClass("before")) {
|
||||
pos.left = pos.left + letter.width();
|
||||
}
|
||||
|
||||
pPos = p.offset();
|
||||
var position = {
|
||||
left: pos.left - pPos.left,
|
||||
top: pos.top - pPos.top - clone.scrollTop()
|
||||
};
|
||||
|
||||
clone.remove();
|
||||
return position;
|
||||
};
|
|
@ -1,435 +0,0 @@
|
|||
// discourse-skip-module
|
||||
|
||||
var define, requirejs;
|
||||
|
||||
(function () {
|
||||
let JS_MODULES = {};
|
||||
let ALIASES = {
|
||||
"ember-addons/ember-computed-decorators":
|
||||
"discourse-common/utils/decorators",
|
||||
"discourse/lib/raw-templates": "discourse/plugins/discourse-custom-wizard/legacy/raw-templates",
|
||||
"discourse-common/lib/raw-templates": "discourse/plugins/discourse-custom-wizard/legacy/raw-templates",
|
||||
"preload-store": "discourse/lib/preload-store",
|
||||
"fixtures/user_fixtures": "discourse/tests/fixtures/user-fixtures",
|
||||
};
|
||||
let ALIAS_PREPEND = {
|
||||
fixtures: "discourse/tests/",
|
||||
helpers: "discourse/tests/",
|
||||
};
|
||||
|
||||
// In future versions of ember we don't need this
|
||||
if (typeof Ember !== "undefined") {
|
||||
JS_MODULES = {
|
||||
jquery: { default: $ },
|
||||
"@ember/array": {
|
||||
default: Ember.Array,
|
||||
A: Ember.A,
|
||||
isArray: Ember.isArray,
|
||||
},
|
||||
"@ember/array/proxy": {
|
||||
default: Ember.ArrayProxy,
|
||||
},
|
||||
"@ember/component": {
|
||||
default: Ember.Component,
|
||||
},
|
||||
"@ember/controller": {
|
||||
default: Ember.Controller,
|
||||
inject: Ember.inject.controller,
|
||||
},
|
||||
"@ember/debug": {
|
||||
assert: Ember.assert,
|
||||
runInDebug: Ember.runInDebug,
|
||||
warn: Ember.warn,
|
||||
},
|
||||
"@ember/object": {
|
||||
action: Ember._action,
|
||||
default: Ember.Object,
|
||||
get: Ember.get,
|
||||
getProperties: Ember.getProperties,
|
||||
set: Ember.set,
|
||||
setProperties: Ember.setProperties,
|
||||
computed: Ember.computed,
|
||||
defineProperty: Ember.defineProperty,
|
||||
observer: Ember.observer,
|
||||
},
|
||||
"@ember/object/computed": {
|
||||
alias: Ember.computed.alias,
|
||||
and: Ember.computed.and,
|
||||
bool: Ember.computed.bool,
|
||||
collect: Ember.computed.collect,
|
||||
deprecatingAlias: Ember.computed.deprecatingAlias,
|
||||
empty: Ember.computed.empty,
|
||||
equal: Ember.computed.equal,
|
||||
filter: Ember.computed.filter,
|
||||
filterBy: Ember.computed.filterBy,
|
||||
gt: Ember.computed.gt,
|
||||
gte: Ember.computed.gte,
|
||||
intersect: Ember.computed.intersect,
|
||||
lt: Ember.computed.lt,
|
||||
lte: Ember.computed.lte,
|
||||
map: Ember.computed.map,
|
||||
mapBy: Ember.computed.mapBy,
|
||||
match: Ember.computed.match,
|
||||
max: Ember.computed.max,
|
||||
min: Ember.computed.min,
|
||||
none: Ember.computed.none,
|
||||
not: Ember.computed.not,
|
||||
notEmpty: Ember.computed.notEmpty,
|
||||
oneWay: Ember.computed.oneWay,
|
||||
or: Ember.computed.or,
|
||||
readOnly: Ember.computed.readOnly,
|
||||
reads: Ember.computed.reads,
|
||||
setDiff: Ember.computed.setDiff,
|
||||
sort: Ember.computed.sort,
|
||||
sum: Ember.computed.sum,
|
||||
union: Ember.computed.union,
|
||||
uniq: Ember.computed.uniq,
|
||||
uniqBy: Ember.computed.uniqBy,
|
||||
},
|
||||
"@ember/object/mixin": { default: Ember.Mixin },
|
||||
"@ember/object/proxy": { default: Ember.ObjectProxy },
|
||||
"@ember/object/promise-proxy-mixin": { default: Ember.PromiseProxyMixin },
|
||||
"@ember/object/evented": {
|
||||
default: Ember.Evented,
|
||||
on: Ember.on,
|
||||
},
|
||||
"@ember/routing/route": { default: Ember.Route },
|
||||
"@ember/routing/router": { default: Ember.Router },
|
||||
"@ember/runloop": {
|
||||
bind: Ember.run.bind,
|
||||
cancel: Ember.run.cancel,
|
||||
debounce: Ember.testing ? Ember.run : Ember.run.debounce,
|
||||
later: Ember.run.later,
|
||||
next: Ember.run.next,
|
||||
once: Ember.run.once,
|
||||
run: Ember.run,
|
||||
schedule: Ember.run.schedule,
|
||||
scheduleOnce: Ember.run.scheduleOnce,
|
||||
throttle: Ember.run.throttle,
|
||||
},
|
||||
"@ember/service": {
|
||||
default: Ember.Service,
|
||||
inject: Ember.inject.service,
|
||||
},
|
||||
"@ember/utils": {
|
||||
isBlank: Ember.isBlank,
|
||||
isEmpty: Ember.isEmpty,
|
||||
isNone: Ember.isNone,
|
||||
isPresent: Ember.isPresent,
|
||||
},
|
||||
rsvp: {
|
||||
asap: Ember.RSVP.asap,
|
||||
all: Ember.RSVP.all,
|
||||
allSettled: Ember.RSVP.allSettled,
|
||||
race: Ember.RSVP.race,
|
||||
hash: Ember.RSVP.hash,
|
||||
hashSettled: Ember.RSVP.hashSettled,
|
||||
rethrow: Ember.RSVP.rethrow,
|
||||
defer: Ember.RSVP.defer,
|
||||
denodeify: Ember.RSVP.denodeify,
|
||||
resolve: Ember.RSVP.resolve,
|
||||
reject: Ember.RSVP.reject,
|
||||
map: Ember.RSVP.map,
|
||||
filter: Ember.RSVP.filter,
|
||||
default: Ember.RSVP,
|
||||
Promise: Ember.RSVP.Promise,
|
||||
EventTarget: Ember.RSVP.EventTarget,
|
||||
},
|
||||
"@ember/string": {
|
||||
w: Ember.String.w,
|
||||
dasherize: Ember.String.dasherize,
|
||||
decamelize: Ember.String.decamelize,
|
||||
camelize: Ember.String.camelize,
|
||||
classify: Ember.String.classify,
|
||||
underscore: Ember.String.underscore,
|
||||
capitalize: Ember.String.capitalize,
|
||||
},
|
||||
"@ember/template": {
|
||||
htmlSafe: Ember.String.htmlSafe,
|
||||
},
|
||||
"@ember/application": {
|
||||
default: Ember.Application,
|
||||
setOwner: Ember.setOwner,
|
||||
getOwner: Ember.getOwner,
|
||||
},
|
||||
"@ember/component/helper": {
|
||||
default: Ember.Helper,
|
||||
},
|
||||
"@ember/component/text-field": {
|
||||
default: Ember.TextField,
|
||||
},
|
||||
"@ember/component/text-area": {
|
||||
default: Ember.TextArea,
|
||||
},
|
||||
"@ember/error": {
|
||||
default: Ember.error,
|
||||
},
|
||||
"@ember/object/internals": {
|
||||
guidFor: Ember.guidFor,
|
||||
},
|
||||
"@ember/test": {
|
||||
registerWaiter: Ember.Test && Ember.Test.registerWaiter,
|
||||
unregisterWaiter: Ember.Test && Ember.Test.unregisterWaiter,
|
||||
},
|
||||
I18n: {
|
||||
// eslint-disable-next-line
|
||||
default: I18n,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let _isArray;
|
||||
if (!Array.isArray) {
|
||||
_isArray = function (x) {
|
||||
return Object.prototype.toString.call(x) === "[object Array]";
|
||||
};
|
||||
} else {
|
||||
_isArray = Array.isArray;
|
||||
}
|
||||
|
||||
let registry = {};
|
||||
let seen = {};
|
||||
let FAILED = false;
|
||||
|
||||
let uuid = 0;
|
||||
|
||||
function tryFinally(tryable, finalizer) {
|
||||
try {
|
||||
return tryable();
|
||||
} finally {
|
||||
finalizer();
|
||||
}
|
||||
}
|
||||
|
||||
function unsupportedModule(length) {
|
||||
throw new Error(
|
||||
"an unsupported module was defined, expected `define(name, deps, module)` instead got: `" +
|
||||
length +
|
||||
"` arguments to define`"
|
||||
);
|
||||
}
|
||||
|
||||
function deprecatedModule(depricated, useInstead) {
|
||||
let warning = "[DEPRECATION] `" + depricated + "` is deprecated.";
|
||||
if (useInstead) {
|
||||
warning += " Please use `" + useInstead + "` instead.";
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(warning);
|
||||
}
|
||||
|
||||
let defaultDeps = ["require", "exports", "module"];
|
||||
|
||||
function Module(name, deps, callback, exports) {
|
||||
this.id = uuid++;
|
||||
this.name = name;
|
||||
this.deps = !deps.length && callback.length ? defaultDeps : deps;
|
||||
this.exports = exports || {};
|
||||
this.callback = callback;
|
||||
this.state = undefined;
|
||||
this._require = undefined;
|
||||
}
|
||||
|
||||
Module.prototype.makeRequire = function () {
|
||||
let name = transformForAliases(this.name);
|
||||
|
||||
return (
|
||||
this._require ||
|
||||
(this._require = function (dep) {
|
||||
return requirejs(resolve(dep, name));
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
define = function (name, deps, callback) {
|
||||
if (arguments.length < 2) {
|
||||
unsupportedModule(arguments.length);
|
||||
}
|
||||
|
||||
if (!_isArray(deps)) {
|
||||
callback = deps;
|
||||
deps = [];
|
||||
}
|
||||
|
||||
registry[name] = new Module(name, deps, callback);
|
||||
};
|
||||
|
||||
// we don't support all of AMD
|
||||
// define.amd = {};
|
||||
// we will support petals...
|
||||
define.petal = {};
|
||||
|
||||
function Alias(path) {
|
||||
this.name = path;
|
||||
}
|
||||
|
||||
define.alias = function (path) {
|
||||
return new Alias(path);
|
||||
};
|
||||
|
||||
function reify(mod, name, rseen) {
|
||||
let deps = mod.deps;
|
||||
let length = deps.length;
|
||||
let reified = new Array(length);
|
||||
let dep;
|
||||
// TODO: new Module
|
||||
// TODO: seen refactor
|
||||
let module = {};
|
||||
|
||||
for (let i = 0, l = length; i < l; i++) {
|
||||
dep = deps[i];
|
||||
if (dep === "exports") {
|
||||
module.exports = reified[i] = rseen;
|
||||
} else if (dep === "require") {
|
||||
reified[i] = mod.makeRequire();
|
||||
} else if (dep === "module") {
|
||||
mod.exports = rseen;
|
||||
module = reified[i] = mod;
|
||||
} else {
|
||||
reified[i] = requireFrom(resolve(dep, name), name);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
deps: reified,
|
||||
module,
|
||||
};
|
||||
}
|
||||
|
||||
function requireFrom(name, origin) {
|
||||
name = transformForAliases(name);
|
||||
|
||||
if (name === "discourse") {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
"discourse has been moved to `discourse/app` - please update your code"
|
||||
);
|
||||
name = "discourse/app";
|
||||
}
|
||||
|
||||
if (name === "discourse/models/input-validation") {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
"input-validation has been removed and should be replaced with `@ember/object`"
|
||||
);
|
||||
name = "@ember/object";
|
||||
}
|
||||
|
||||
let mod = JS_MODULES[name] || registry[name];
|
||||
if (!mod) {
|
||||
throw new Error(
|
||||
"Could not find module `" + name + "` imported from `" + origin + "`"
|
||||
);
|
||||
}
|
||||
return requirejs(name);
|
||||
}
|
||||
|
||||
function missingModule(name) {
|
||||
throw new Error("Could not find module " + name);
|
||||
}
|
||||
|
||||
function transformForAliases(name) {
|
||||
let alias = ALIASES[name];
|
||||
if (!alias) {
|
||||
let segment = name.split("/")[0];
|
||||
let prepend = ALIAS_PREPEND[segment];
|
||||
if (!prepend) {
|
||||
return name;
|
||||
}
|
||||
alias = prepend + name;
|
||||
}
|
||||
deprecatedModule(name, alias);
|
||||
return alias;
|
||||
}
|
||||
|
||||
requirejs = require = function (name) {
|
||||
name = transformForAliases(name);
|
||||
if (JS_MODULES[name]) {
|
||||
return JS_MODULES[name];
|
||||
}
|
||||
|
||||
let mod = registry[name];
|
||||
|
||||
if (mod && mod.callback instanceof Alias) {
|
||||
mod = registry[mod.callback.name];
|
||||
}
|
||||
|
||||
if (!mod) {
|
||||
missingModule(name);
|
||||
}
|
||||
|
||||
if (mod.state !== FAILED && seen.hasOwnProperty(name)) {
|
||||
return seen[name];
|
||||
}
|
||||
|
||||
let reified;
|
||||
let module;
|
||||
let loaded = false;
|
||||
|
||||
seen[name] = {}; // placeholder for run-time cycles
|
||||
|
||||
tryFinally(
|
||||
function () {
|
||||
reified = reify(mod, name, seen[name]);
|
||||
module = mod.callback.apply(this, reified.deps);
|
||||
loaded = true;
|
||||
},
|
||||
function () {
|
||||
if (!loaded) {
|
||||
mod.state = FAILED;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let obj;
|
||||
if (module === undefined && reified.module.exports) {
|
||||
obj = reified.module.exports;
|
||||
} else {
|
||||
obj = seen[name] = module;
|
||||
}
|
||||
|
||||
if (
|
||||
obj !== null &&
|
||||
(typeof obj === "object" || typeof obj === "function") &&
|
||||
obj["default"] === undefined
|
||||
) {
|
||||
obj["default"] = obj;
|
||||
}
|
||||
|
||||
return (seen[name] = obj);
|
||||
};
|
||||
window.requireModule = requirejs;
|
||||
|
||||
function resolve(child, name) {
|
||||
if (child.charAt(0) !== ".") {
|
||||
return child;
|
||||
}
|
||||
|
||||
let parts = child.split("/");
|
||||
let nameParts = name.split("/");
|
||||
let parentBase = nameParts.slice(0, -1);
|
||||
|
||||
for (let i = 0, l = parts.length; i < l; i++) {
|
||||
let part = parts[i];
|
||||
|
||||
if (part === "..") {
|
||||
if (parentBase.length === 0) {
|
||||
throw new Error("Cannot access parent module of root");
|
||||
}
|
||||
parentBase.pop();
|
||||
} else if (part === ".") {
|
||||
continue;
|
||||
} else {
|
||||
parentBase.push(part);
|
||||
}
|
||||
}
|
||||
|
||||
return parentBase.join("/");
|
||||
}
|
||||
|
||||
requirejs.entries = requirejs._eak_seen = registry;
|
||||
requirejs.clear = function () {
|
||||
requirejs.entries = requirejs._eak_seen = registry = {};
|
||||
seen = {};
|
||||
};
|
||||
})();
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
Laden …
In neuem Issue referenzieren