1
0
Fork 0

Merge pull request #198 from paviliondev/move_custom_wizard_into_main_app

Move custom wizard into main app
Dieser Commit ist enthalten in:
Angus McLeod 2022-07-28 21:02:23 +01:00 committet von GitHub
Commit 72a1f9f2c2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
212 geänderte Dateien mit 2597 neuen und 33745 gelöschten Zeilen

Datei anzeigen

@ -3,51 +3,52 @@ name: Linting
on: on:
push: push:
branches: branches:
- master
- main - main
- stable - stable
pull_request: 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: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Set up Node.js - name: Set up Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v3
with: with:
node-version: 14 node-version: 16
cache: yarn
- name: Yarn install
run: yarn install
- name: Set up ruby - name: Set up ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
ruby-version: 2.7 ruby-version: 2.7
bundler-cache: true
- 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
- name: ESLint - 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 - name: Prettier
if: ${{ always() }}
shell: bash
run: | run: |
yarn prettier -v yarn prettier -v
if [ -d "assets" ]; then \ 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/javascripts/{discourse,wizard}/**/*.{scss,js,es6}" ; \ 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 fi
- name: Ember template lint
run: yarn ember-template-lint assets/javascripts
- name: Rubocop - name: Rubocop
if: ${{ always() }}
run: bundle exec rubocop . run: bundle exec rubocop .

Datei anzeigen

@ -36,9 +36,9 @@ jobs:
uses: actions/github-script@v5 uses: actions/github-script@v5
with: with:
script: | script: |
const semver = require('semver'); const semver = require('semver');
const { head_version, base_version } = process.env; const { head_version, base_version } = process.env;
if (semver.lte(head_version, base_version)) { if (semver.lte(head_version, base_version)) {
core.setFailed("Head version is equal to or lower than base version."); core.setFailed("Head version is equal to or lower than base version.");
} }

Datei anzeigen

@ -3,24 +3,25 @@ name: Plugin Tests
on: on:
push: push:
branches: branches:
- stable
- master
- main - main
- stable
pull_request: 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: jobs:
build: build:
name: ${{ matrix.build_type }} name: ${{ matrix.build_type }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 60 container: discourse/discourse_test:slim${{ startsWith(matrix.build_type, 'frontend') && '-browsers' || '' }}
timeout-minutes: 30
env: env:
DISCOURSE_HOSTNAME: www.example.com DISCOURSE_HOSTNAME: www.example.com
RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072 RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072
RAILS_ENV: test RAILS_ENV: test
PGHOST: localhost
PGUSER: discourse PGUSER: discourse
PGPASSWORD: discourse PGPASSWORD: discourse
@ -29,44 +30,17 @@ jobs:
matrix: matrix:
build_type: ["backend", "frontend"] 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: 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 - uses: actions/checkout@v3
with: with:
repository: discourse/discourse repository: discourse/discourse
ref: ${{ steps.discourse_branch.outputs.value }}
fetch-depth: 1 fetch-depth: 1
- name: Install plugin - name: Install plugin
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
path: plugins/${{ github.event.repository.name }} path: plugins/${{ github.event.repository.name }}
ref: "${{ github.head_ref }}"
fetch-depth: 1 fetch-depth: 1
- name: Setup Git - name: Setup Git
@ -74,61 +48,89 @@ jobs:
git config --global user.email "ci@ci.invalid" git config --global user.email "ci@ci.invalid"
git config --global user.name "Discourse CI" git config --global user.name "Discourse CI"
- name: Setup packages - name: Start redis
run: | run: |
sudo apt-get update redis-server /etc/redis/redis.conf &
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
- name: Update imagemagick - name: Start Postgres
if: matrix.build_type == 'backend'
run: | run: |
wget https://raw.githubusercontent.com/discourse/discourse_docker/master/image/base/install-imagemagick chown -R postgres /var/run/postgresql
chmod +x install-imagemagick sudo -E -u postgres script/start_test_db.rb
sudo ./install-imagemagick sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';"
- name: Setup redis - name: Bundler cache
uses: shogo82148/actions-setup-redis@v1 uses: actions/cache@v3
with: with:
redis-version: ${{ matrix.redis }} path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
- name: Setup ruby - name: Setup gems
uses: ruby/setup-ruby@v1 run: |
with: gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' Gemfile.lock)
ruby-version: ${{ matrix.ruby }} bundle config --local path vendor/bundle
bundler-cache: true bundle config --local deployment true
bundle config --local without development
bundle install --jobs 4
bundle clean
- name: Lint English locale - name: Lint English locale
if: matrix.build_type == 'backend' 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 - name: Get yarn cache directory
id: yarn-cache-dir id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn cache dir)" run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Yarn cache - name: Yarn cache
uses: actions/cache@v2 uses: actions/cache@v3
id: yarn-cache id: yarn-cache
with: with:
path: ${{ steps.yarn-cache-dir.outputs.dir }} 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: | restore-keys: |
${{ runner.os }}-${{ matrix.os }}-yarn- ${{ runner.os }}-yarn-
- name: Yarn install - 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: | run: |
bin/rake db:create bin/rake db:create
bin/rake db:migrate 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' if: matrix.build_type == 'backend'
run: | run: bin/rake plugin:spec[${{ github.event.repository.name }}]
if [ -e plugins/${{ steps.repo-name.outputs.value }}/.simplecov ]
then - name: Plugin QUnit
cp plugins/${{ steps.repo-name.outputs.value }}/.simplecov .simplecov if: matrix.build_type == 'frontend'
export COVERAGE=1 run: QUNIT_EMBER_CLI=1 bundle exec rake plugin:qunit['${{ github.event.repository.name }}','1200000']
fi timeout-minutes: 10
bin/rake plugin:spec[${{ steps.repo-name.outputs.value }}]

Datei anzeigen

@ -1,40 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
class CustomWizard::WizardController < ::ActionController::Base class CustomWizard::WizardController < ::ApplicationController
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
before_action :ensure_plugin_enabled before_action :ensure_plugin_enabled
before_action :ensure_logged_in, only: [:skip] before_action :ensure_logged_in, only: [:skip]
around_action :with_resolved_locale
helper_method :wizard_page_title def show
helper_method :wizard_theme_id if wizard.present?
helper_method :wizard_theme_lookup render json: CustomWizard::WizardSerializer.new(wizard, scope: guardian, root: false).as_json, status: 200
helper_method :wizard_theme_translations_lookup else
render json: { error: I18n.t('wizard.none') }
def set_wizard_layout
action_name === 'qunit' ? 'qunit' : 'wizard'
end
def index
respond_to do |format|
format.json do
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
end end
@ -58,26 +31,8 @@ class CustomWizard::WizardController < ::ActionController::Base
render json: result render json: result
end 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 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 def wizard
@wizard ||= begin @wizard ||= begin
builder = CustomWizard::Builder.new(params[:wizard_id].underscore, current_user) builder = CustomWizard::Builder.new(params[:wizard_id].underscore, current_user)
@ -88,41 +43,6 @@ class CustomWizard::WizardController < ::ActionController::Base
end end
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 private
def ensure_plugin_enabled def ensure_plugin_enabled

Datei anzeigen

@ -9,13 +9,10 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
:completed, :completed,
:required, :required,
:permitted, :permitted,
:uncategorized_category_id,
:categories,
:resume_on_revisit :resume_on_revisit
has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects
has_one :user, serializer: ::BasicUserSerializer, embed: :objects has_one :user, serializer: ::BasicUserSerializer, embed: :objects
has_many :groups, serializer: ::BasicGroupSerializer, embed: :objects
def completed def completed
object.completed? object.completed?
@ -46,24 +43,4 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
def include_steps? def include_steps?
!include_completed? !include_completed?
end 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 end

Datei anzeigen

@ -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>

Datei anzeigen

@ -3,8 +3,8 @@ import {
observes, observes,
} from "discourse-common/utils/decorators"; } from "discourse-common/utils/decorators";
import { renderAvatar } from "discourse/helpers/user-avatar"; import { renderAvatar } from "discourse/helpers/user-avatar";
import userSearch from "../lib/user-search"; import userSearch from "discourse/lib/user-search";
import WizardI18n from "../lib/wizard-i18n"; import I18n from "I18n";
import Handlebars from "handlebars"; import Handlebars from "handlebars";
import { isEmpty } from "@ember/utils"; import { isEmpty } from "@ember/utils";
import TextField from "@ember/component/text-field"; import TextField from "@ember/component/text-field";
@ -41,7 +41,7 @@ export default TextField.extend({
@computed("placeholderKey") @computed("placeholderKey")
placeholder(placeholderKey) { placeholder(placeholderKey) {
return placeholderKey ? WizardI18n(placeholderKey) : ""; return placeholderKey ? I18n.t(placeholderKey) : "";
}, },
@observes("usernames") @observes("usernames")

Datei anzeigen

@ -3,17 +3,16 @@ import {
default as discourseComputed, default as discourseComputed,
on, on,
} from "discourse-common/utils/decorators"; } 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 { scheduleOnce } from "@ember/runloop";
import { caretPosition, inCodeBlock } from "discourse/lib/utilities"; import { caretPosition, inCodeBlock } from "discourse/lib/utilities";
import highlightSyntax from "discourse/lib/highlight-syntax"; import highlightSyntax from "discourse/lib/highlight-syntax";
import { alias } from "@ember/object/computed"; import { alias } from "@ember/object/computed";
import Site from "../models/site"; import Site from "discourse/models/site";
import { uploadIcon } from "discourse/lib/uploads"; import { uploadIcon } from "discourse/lib/uploads";
import { dasherize } from "@ember/string"; import { dasherize } from "@ember/string";
export default ComposerEditor.extend({ export default ComposerEditor.extend({
layoutName: "wizard/templates/components/wizard-composer-editor",
classNameBindings: ["fieldClass"], classNameBindings: ["fieldClass"],
allowUpload: true, allowUpload: true,
showLink: false, showLink: false,
@ -35,7 +34,7 @@ export default ComposerEditor.extend({
if (this.siteSettings.enable_mentions) { if (this.siteSettings.enable_mentions) {
$input.autocomplete({ $input.autocomplete({
template: findRawTemplate("user-selector-autocomplete"), template: findRawTemplate("user-selector-autocomplete"),
dataSource: (term) => this.userSearchTerm.call(this, term), dataSource: (term) => this._userSearchTerm.call(this, term),
key: "@", key: "@",
transformComplete: (v) => v.username || v.name, transformComplete: (v) => v.username || v.name,
afterComplete: (value) => { afterComplete: (value) => {

Datei anzeigen

@ -2,7 +2,6 @@ import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
classNames: ["wizard-composer-hyperlink"], classNames: ["wizard-composer-hyperlink"],
layoutName: "wizard/templates/components/wizard-composer-hyperlink",
actions: { actions: {
addLink() { addLink() {

Datei anzeigen

@ -3,7 +3,6 @@ import discourseComputed from "discourse-common/utils/decorators";
export default DateInput.extend({ export default DateInput.extend({
useNativePicker: false, useNativePicker: false,
layoutName: "wizard/templates/components/wizard-date-input",
@discourseComputed() @discourseComputed()
placeholder() { placeholder() {

Datei anzeigen

@ -2,8 +2,6 @@ import DateTimeInput from "discourse/components/date-time-input";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default DateTimeInput.extend({ export default DateTimeInput.extend({
layoutName: "wizard/templates/components/wizard-date-time-input",
@discourseComputed("timeFirst", "tabindex") @discourseComputed("timeFirst", "tabindex")
timeTabindex(timeFirst, tabindex) { timeTabindex(timeFirst, tabindex) {
return timeFirst ? tabindex : tabindex + 1; return timeFirst ? tabindex : tabindex + 1;

Datei anzeigen

@ -3,8 +3,6 @@ import Category from "discourse/models/category";
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-category",
didInsertElement() { didInsertElement() {
const property = this.field.property || "id"; const property = this.field.property || "id";
const value = this.field.value; const value = this.field.value;

Datei anzeigen

@ -0,0 +1,3 @@
import Component from "@ember/component";
export default Component.extend({});

Datei anzeigen

@ -7,8 +7,6 @@ import { ajax } from "discourse/lib/ajax";
import { on } from "discourse-common/utils/decorators"; import { on } from "discourse-common/utils/decorators";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-composer-preview",
@on("init") @on("init")
updatePreview() { updatePreview() {
if (this.isDestroyed) { if (this.isDestroyed) {

Datei anzeigen

@ -6,8 +6,6 @@ import EmberObject from "@ember/object";
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-composer",
showPreview: false, showPreview: false,
classNameBindings: [ classNameBindings: [
":wizard-field-composer", ":wizard-field-composer",

Datei anzeigen

@ -2,8 +2,6 @@ import Component from "@ember/component";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-date-time",
@observes("dateTime") @observes("dateTime")
setValue() { setValue() {
this.set("field.value", this.dateTime.format(this.field.format)); this.set("field.value", this.dateTime.format(this.field.format));

Datei anzeigen

@ -2,8 +2,6 @@ import Component from "@ember/component";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-date",
@observes("date") @observes("date")
setValue() { setValue() {
this.set("field.value", this.date.format(this.field.format)); this.set("field.value", this.date.format(this.field.format));

Datei anzeigen

@ -1,8 +1,6 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-dropdown",
keyPress(e) { keyPress(e) {
e.stopPropagation(); e.stopPropagation();
}, },

Datei anzeigen

@ -0,0 +1,3 @@
import Component from "@ember/component";
export default Component.extend({});

Datei anzeigen

@ -0,0 +1,3 @@
import Component from "@ember/component";
export default Component.extend({});

Datei anzeigen

@ -0,0 +1,3 @@
import Component from "@ember/component";
export default Component.extend({});

Datei anzeigen

@ -1,8 +1,6 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-text",
keyPress(e) { keyPress(e) {
e.stopPropagation(); e.stopPropagation();
}, },

Datei anzeigen

@ -1,8 +1,6 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-textarea",
keyPress(e) { keyPress(e) {
e.stopPropagation(); e.stopPropagation();
}, },

Datei anzeigen

@ -2,8 +2,6 @@ import Component from "@ember/component";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field-time",
@observes("time") @observes("time")
setValue() { setValue() {
this.set("field.value", this.time.format(this.field.format)); this.set("field.value", this.time.format(this.field.format));

Datei anzeigen

@ -3,7 +3,6 @@ import Component from "@ember/component";
import { computed } from "@ember/object"; import { computed } from "@ember/object";
export default Component.extend(UppyUploadMixin, { export default Component.extend(UppyUploadMixin, {
layoutName: "wizard/templates/components/wizard-field-upload",
classNames: ["wizard-field-upload"], classNames: ["wizard-field-upload"],
classNameBindings: ["isImage"], classNameBindings: ["isImage"],
uploading: false, uploading: false,

Datei anzeigen

@ -0,0 +1,3 @@
import Component from "@ember/component";
export default Component.extend({});

Datei anzeigen

@ -0,0 +1,3 @@
import Component from "@ember/component";
export default Component.extend({});

Datei anzeigen

@ -1,10 +1,9 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { dasherize } from "@ember/string"; import { dasherize } from "@ember/string";
import discourseComputed from "discourse-common/utils/decorators"; 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({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-field",
classNameBindings: [ classNameBindings: [
":wizard-field", ":wizard-field",
"typeClasses", "typeClasses",
@ -12,6 +11,14 @@ export default Component.extend({
"field.id", "field.id",
], ],
didReceiveAttrs() {
this._super(...arguments);
cookAsync(this.field.translatedDescription).then((cookedDescription) => {
this.set("cookedDescription", cookedDescription);
});
},
@discourseComputed("field.type", "field.id") @discourseComputed("field.type", "field.id")
typeClasses: (type, id) => typeClasses: (type, id) =>
`${dasherize(type)}-field ${dasherize(type)}-${dasherize(id)}`, `${dasherize(type)}-field ${dasherize(type)}-${dasherize(id)}`,
@ -24,12 +31,7 @@ export default Component.extend({
if (["text_only"].includes(type)) { if (["text_only"].includes(type)) {
return false; return false;
} }
return dasherize(type === "component" ? id : `wizard-field-${type}`); return dasherize(type === "component" ? id : `custom-wizard-field-${type}`);
},
@discourseComputed("field.translatedDescription")
cookedDescription(description) {
return cook(description);
}, },
@discourseComputed("field.type") @discourseComputed("field.type")

Datei anzeigen

@ -3,7 +3,6 @@ import { computed } from "@ember/object";
import { makeArray } from "discourse-common/lib/helpers"; import { makeArray } from "discourse-common/lib/helpers";
export default ComboBox.extend({ export default ComboBox.extend({
layoutName: "wizard/templates/components/wizard-group-selector",
content: computed("groups.[]", "field.content.[]", function () { content: computed("groups.[]", "field.content.[]", function () {
const whitelist = makeArray(this.field.content); const whitelist = makeArray(this.field.content);
return this.groups return this.groups

Datei anzeigen

@ -1,11 +1,10 @@
import CustomWizard from "../models/wizard"; import CustomWizard from "../models/custom-wizard";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component"; import Component from "@ember/component";
import { dasherize } from "@ember/string"; import { dasherize } from "@ember/string";
export default Component.extend({ export default Component.extend({
classNameBindings: [":wizard-no-access", "reasonClass"], classNameBindings: [":wizard-no-access", "reasonClass"],
layoutName: "wizard/templates/components/wizard-no-access",
@discourseComputed("reason") @discourseComputed("reason")
reasonClass(reason) { reasonClass(reason) {

Datei anzeigen

@ -4,7 +4,6 @@ import { observes } from "discourse-common/utils/decorators";
export default Component.extend({ export default Component.extend({
classNames: ["wizard-similar-topics"], classNames: ["wizard-similar-topics"],
layoutName: "wizard/templates/components/wizard-similar-topics",
showTopics: true, showTopics: true,
didInsertElement() { didInsertElement() {

Datei anzeigen

@ -4,15 +4,15 @@ import I18n from "I18n";
import getUrl from "discourse-common/lib/get-url"; import getUrl from "discourse-common/lib/get-url";
import { htmlSafe } from "@ember/template"; import { htmlSafe } from "@ember/template";
import { schedule } from "@ember/runloop"; import { schedule } from "@ember/runloop";
import { cook } from "discourse/plugins/discourse-custom-wizard/wizard/lib/text-lite"; import { cookAsync } from "discourse/lib/text";
import { updateCachedWizard } from "discourse/plugins/discourse-custom-wizard/wizard/models/wizard"; import CustomWizard, {
updateCachedWizard,
} from "discourse/plugins/discourse-custom-wizard/discourse/models/custom-wizard";
import { alias, not } from "@ember/object/computed"; import { alias, not } from "@ember/object/computed";
import CustomWizard from "../models/wizard";
const alreadyWarned = {}; const alreadyWarned = {};
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/wizard-step",
classNameBindings: [":wizard-step", "step.id"], classNameBindings: [":wizard-step", "step.id"],
saving: null, saving: null,
@ -21,6 +21,17 @@ export default Component.extend({
this.set("stylingDropdown", {}); 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() { didInsertElement() {
this._super(...arguments); this._super(...arguments);
this.autoFocus(); this.autoFocus();
@ -32,16 +43,6 @@ export default Component.extend({
showNextButton: not("step.final"), showNextButton: not("step.final"),
showDoneButton: alias("step.final"), showDoneButton: alias("step.final"),
@discourseComputed("step.translatedTitle")
cookedTitle(title) {
return cook(title);
},
@discourseComputed("step.translatedDescription")
cookedDescription(description) {
return cook(description);
},
@discourseComputed( @discourseComputed(
"step.index", "step.index",
"step.displayIndex", "step.displayIndex",

Datei anzeigen

@ -1,6 +1,6 @@
import computed from "discourse-common/utils/decorators"; import computed from "discourse-common/utils/decorators";
import { isLTR, isRTL, siteDir } from "discourse/lib/text-direction"; 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"; import TextField from "@ember/component/text-field";
export default TextField.extend({ export default TextField.extend({
@ -39,6 +39,6 @@ export default TextField.extend({
@computed("placeholderKey") @computed("placeholderKey")
placeholder(placeholderKey) { placeholder(placeholderKey) {
return placeholderKey ? WizardI18n(placeholderKey) : ""; return placeholderKey ? I18n.t(placeholderKey) : "";
}, },
}); });

Datei anzeigen

@ -0,0 +1,3 @@
import TimeInput from "discourse/components/time-input";
export default TimeInput.extend({});

Datei anzeigen

@ -1,8 +1,6 @@
import Component from "@ember/component"; import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
layoutName: "wizard/templates/components/field-validators",
actions: { actions: {
perform() { perform() {
this.appEvents.trigger("custom-wizard:validate"); this.appEvents.trigger("custom-wizard:validate");

Datei anzeigen

@ -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 { deepMerge } from "discourse-common/lib/object";
import discourseComputed, { observes } from "discourse-common/utils/decorators"; import discourseComputed, { observes } from "discourse-common/utils/decorators";
import { cancel, later } from "@ember/runloop"; import { cancel, later } from "@ember/runloop";
@ -10,7 +10,6 @@ import { dasherize } from "@ember/string";
export default WizardFieldValidator.extend({ export default WizardFieldValidator.extend({
classNames: ["similar-topics-validator"], classNames: ["similar-topics-validator"],
layoutName: "wizard/templates/components/similar-topics-validator",
similarTopics: null, similarTopics: null,
hasInput: notEmpty("field.value"), hasInput: notEmpty("field.value"),
hasSimilarTopics: notEmpty("similarTopics"), hasSimilarTopics: notEmpty("similarTopics"),

Datei anzeigen

@ -1,12 +1,10 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { equal } from "@ember/object/computed"; import { equal } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax"; import { ajax, getToken } from "discourse/lib/ajax";
import { getToken } from "../lib/ajax";
export default Component.extend({ export default Component.extend({
classNames: ["validator"], classNames: ["validator"],
classNameBindings: ["isValid", "isInvalid"], classNameBindings: ["isValid", "isInvalid"],
layoutName: "wizard/templates/components/validator",
validMessageKey: null, validMessageKey: null,
invalidMessageKey: null, invalidMessageKey: null,
isValid: null, isValid: null,

Datei anzeigen

@ -1,9 +1,9 @@
import CustomWizard from "../../models/custom-wizard"; import CustomWizardAdmin from "../../models/custom-wizard-admin";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
export default { export default {
setupComponent(attrs, component) { setupComponent(attrs, component) {
CustomWizard.all() CustomWizardAdmin.all()
.then((result) => { .then((result) => {
component.set("wizardList", result); component.set("wizardList", result);
}) })

Datei anzeigen

@ -149,7 +149,6 @@ export default Controller.extend({
const api = this.get("api"); const api = this.get("api");
const name = api.name; const name = api.name;
const authType = api.authType; const authType = api.authType;
let refreshList = false; // eslint-disable-line
let error; let error;
if (!name || !authType) { if (!name || !authType) {
@ -164,11 +163,6 @@ export default Controller.extend({
data["title"] = api.title; data["title"] = api.title;
} }
const originalTitle = this.get("api.originalTitle");
if (api.get("isNew") || (originalTitle && api.title !== originalTitle)) {
refreshList = true;
}
if (api.get("isNew")) { if (api.get("isNew")) {
data["new"] = true; data["new"] = true;
} }

Datei anzeigen

@ -15,12 +15,12 @@ export default Controller.extend({
const wizardId = this.get("wizard.id"); const wizardId = this.get("wizard.id");
window.location.href = getUrl(`/w/${wizardId}/steps/${nextStepId}`); window.location.href = getUrl(`/w/${wizardId}/steps/${nextStepId}`);
} else { } else {
this.transitionToRoute("step", nextStepId); this.transitionToRoute("customWizardStep", nextStepId);
} }
}, },
goBack() { goBack() {
this.transitionToRoute("step", this.get("step.previous")); this.transitionToRoute("customWizardStep", this.get("step.previous"));
}, },
showMessage(message) { showMessage(message) {

Datei anzeigen

@ -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,
});
}
);
}

Datei anzeigen

@ -1,6 +0,0 @@
import { registerUnbound } from "discourse-common/lib/helpers";
import { dasherize } from "@ember/string";
registerUnbound("dasherize", function (string) {
return dasherize(string);
});

Datei anzeigen

@ -38,6 +38,7 @@ export default {
}); });
api.modifyClass("component:uppy-image-uploader", { api.modifyClass("component:uppy-image-uploader", {
pluginId: "custom-wizard",
// Needed to ensure appEvents get registered when navigating between steps // Needed to ensure appEvents get registered when navigating between steps
@observes("id") @observes("id")
initOnStepChange() { initOnStepChange() {

Datei anzeigen

@ -5,7 +5,7 @@ export default {
after: "message-bus", after: "message-bus",
initialize: function (container) { initialize: function (container) {
const messageBus = container.lookup("message-bus:main"); const messageBus = container.lookup("service:message-bus");
const siteSettings = container.lookup("site-settings:main"); const siteSettings = container.lookup("site-settings:main");
if (!siteSettings.custom_wizard_enabled || !messageBus) { if (!siteSettings.custom_wizard_enabled || !messageBus) {

Datei anzeigen

@ -1,5 +1,6 @@
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import wizardSchema from "./wizard-schema"; import wizardSchema from "./wizard-schema";
import I18n from "I18n";
function selectKitContent(content) { function selectKitContent(content) {
return content.map((i) => ({ id: i, name: i })); 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 = [ const userProperties = [
"name", "name",
"username", "username",
@ -121,4 +126,5 @@ export {
notificationLevels, notificationLevels,
wizardFieldList, wizardFieldList,
sentenceCase, sentenceCase,
translationOrText,
}; };

Datei anzeigen

@ -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;

Datei anzeigen

@ -1,7 +1,7 @@
import EmberObject from "@ember/object"; 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 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 = [ const StandardFieldValidation = [
"text", "text",
@ -34,17 +34,17 @@ export default EmberObject.extend(ValidState, {
@discourseComputed("i18nKey", "label") @discourseComputed("i18nKey", "label")
translatedLabel(i18nKey, label) { translatedLabel(i18nKey, label) {
return translatedText(`${i18nKey}.label`, label); return translationOrText(`${i18nKey}.label`, label);
}, },
@discourseComputed("i18nKey", "placeholder") @discourseComputed("i18nKey", "placeholder")
translatedPlaceholder(i18nKey, placeholder) { translatedPlaceholder(i18nKey, placeholder) {
return translatedText(`${i18nKey}.placeholder`, placeholder); return translationOrText(`${i18nKey}.placeholder`, placeholder);
}, },
@discourseComputed("i18nKey", "description") @discourseComputed("i18nKey", "description")
translatedDescription(i18nKey, description) { translatedDescription(i18nKey, description) {
return translatedText(`${i18nKey}.description`, description); return translationOrText(`${i18nKey}.description`, description);
}, },
check() { check() {

Datei anzeigen

@ -1,9 +1,9 @@
import EmberObject from "@ember/object"; 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 { ajax } from "../lib/ajax"; import { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse-common/utils/decorators"; 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 { later } from "@ember/runloop";
import { translationOrText } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard";
export default EmberObject.extend(ValidState, { export default EmberObject.extend(ValidState, {
id: null, id: null,
@ -15,12 +15,12 @@ export default EmberObject.extend(ValidState, {
@discourseComputed("i18nKey", "title") @discourseComputed("i18nKey", "title")
translatedTitle(i18nKey, title) { translatedTitle(i18nKey, title) {
return translatedText(`${i18nKey}.title`, title); return translationOrText(`${i18nKey}.title`, title);
}, },
@discourseComputed("i18nKey", "description") @discourseComputed("i18nKey", "description")
translatedDescription(i18nKey, description) { translatedDescription(i18nKey, description) {
return translatedText(`${i18nKey}.description`, description); return translationOrText(`${i18nKey}.description`, description);
}, },
@discourseComputed("index") @discourseComputed("index")

Datei anzeigen

@ -1,227 +1,127 @@
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import { buildProperties, mapped, present } from "../lib/wizard-json"; import { ajax } from "discourse/lib/ajax";
import { listProperties, snakeCase } from "../lib/wizard";
import wizardSchema from "../lib/wizard-schema";
import { Promise } from "rsvp";
import { popupAjaxError } from "discourse/lib/ajax-error"; 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({ const CustomWizard = EmberObject.extend({
save(opts) { @discourseComputed("steps.length")
return new Promise((resolve, reject) => { totalSteps: (length) => length,
let wizard = this.buildJson(this, "wizard");
if (wizard.error) { skip() {
reject(wizard); if (this.required && !this.completed && this.permitted) {
} return;
}
let data = { CustomWizard.skip(this.id);
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 = {}) { restart() {
let objectType = object.type || null; CustomWizard.restart(this.id);
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);
}, },
}); });
CustomWizard.reopenClass({ CustomWizard.reopenClass({
all() { skip(wizardId) {
return ajax("/admin/wizards/wizard", { ajax({ url: `/w/${wizardId}/skip`, type: "PUT" })
type: "GET",
})
.then((result) => { .then((result) => {
return result.wizard_list; CustomWizard.finished(result);
}) })
.catch(popupAjaxError); .catch(popupAjaxError);
}, },
submissions(wizardId) { restart(wizardId) {
return ajax(`/admin/wizards/submissions/${wizardId}`, { ajax({ url: `/w/${wizardId}/skip`, type: "PUT" })
type: "GET", .then(() => {
}).catch(popupAjaxError); window.location.href = `/w/${wizardId}`;
})
.catch(popupAjaxError);
}, },
create(wizardJson = {}) { finished(result) {
const wizard = this._super.apply(this); let url = "/";
wizard.setProperties(buildProperties(wizardJson)); if (result.redirect_on_complete) {
return wizard; 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; export default CustomWizard;

Datei anzeigen

@ -1,9 +1,9 @@
import CustomWizard from "../models/custom-wizard"; import CustomWizardAdmin from "../models/custom-wizard-admin";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
model() { model() {
return CustomWizard.all(); return CustomWizardAdmin.all();
}, },
setupController(controller, model) { setupController(controller, model) {

Datei anzeigen

@ -1,11 +1,11 @@
import CustomWizard from "../models/custom-wizard"; import CustomWizardAdmin from "../models/custom-wizard-admin";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
const excludedMetaFields = ["route_to", "redirect_on_complete", "redirect_to"]; const excludedMetaFields = ["route_to", "redirect_on_complete", "redirect_to"];
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
model(params) { model(params) {
return CustomWizard.submissions(params.wizardId); return CustomWizardAdmin.submissions(params.wizardId);
}, },
setupController(controller, model) { setupController(controller, model) {

Datei anzeigen

@ -1,4 +1,4 @@
import CustomWizard from "../models/custom-wizard"; import CustomWizardAdmin from "../models/custom-wizard-admin";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n"; import I18n from "I18n";
@ -20,7 +20,9 @@ export default DiscourseRoute.extend({
setupController(controller, model) { setupController(controller, model) {
const parentModel = this.modelFor("adminWizardsWizard"); 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) => { const fieldTypes = Object.keys(parentModel.field_types).map((type) => {
return { return {
id: type, id: type,

Datei anzeigen

@ -1,4 +1,4 @@
import { getCachedWizard } from "../models/wizard"; import { getCachedWizard } from "../models/custom-wizard";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default Route.extend({
@ -11,7 +11,7 @@ export default Route.extend({
!wizard.completed && !wizard.completed &&
wizard.start wizard.start
) { ) {
this.replaceWith("step", wizard.start); this.replaceWith("customWizardStep", wizard.start);
} }
}, },
@ -19,10 +19,6 @@ export default Route.extend({
return getCachedWizard(); return getCachedWizard();
}, },
renderTemplate() {
this.render("wizard/templates/wizard-index");
},
setupController(controller, model) { setupController(controller, model) {
if (model && model.id) { if (model && model.id) {
const completed = model.get("completed"); const completed = model.get("completed");

Datei anzeigen

@ -1,5 +1,5 @@
import WizardI18n from "../lib/wizard-i18n"; import I18n from "I18n";
import { getCachedWizard } from "../models/wizard"; import { getCachedWizard } from "../models/custom-wizard";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default Route.extend({
@ -25,10 +25,6 @@ export default Route.extend({
return model.set("wizardId", this.wizard.id); return model.set("wizardId", this.wizard.id);
}, },
renderTemplate() {
this.render("wizard/templates/step");
},
setupController(controller, model) { setupController(controller, model) {
let props = { let props = {
step: model, step: model,
@ -38,8 +34,7 @@ export default Route.extend({
if (!model.permitted) { if (!model.permitted) {
props["stepMessage"] = { props["stepMessage"] = {
state: "not-permitted", state: "not-permitted",
text: text: model.permitted_message || I18n.t("wizard.step_not_permitted"),
model.permitted_message || WizardI18n("wizard.step_not_permitted"),
}; };
if (model.index > 0) { if (model.index > 0) {
props["showReset"] = true; props["showReset"] = true;

Datei anzeigen

@ -1,10 +1,13 @@
import { findCustomWizard, updateCachedWizard } from "../models/wizard"; import { findCustomWizard, updateCachedWizard } from "../models/custom-wizard";
import WizardI18n from "../lib/wizard-i18n"; import I18n from "I18n";
import Route from "@ember/routing/route"; import DiscourseRoute from "discourse/routes/discourse";
import { scheduleOnce } from "@ember/runloop";
import { getOwner } from "discourse-common/lib/get-owner"; 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) { beforeModel(transition) {
if (transition.intent.queryParams) { if (transition.intent.queryParams) {
this.set("queryParams", transition.intent.queryParams); this.set("queryParams", transition.intent.queryParams);
@ -16,7 +19,7 @@ export default Route.extend({
}, },
showDialog(wizardModel) { 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( date: moment(wizardModel.submission_last_updated_at).format(
"MMMM Do YYYY" "MMMM Do YYYY"
), ),
@ -24,14 +27,14 @@ export default Route.extend({
const buttons = [ const buttons = [
{ {
label: WizardI18n("wizard.incomplete_submission.restart"), label: I18n.t("wizard.incomplete_submission.restart"),
class: "btn btn-default", class: "btn btn-default",
callback: () => { callback: () => {
wizardModel.restart(); wizardModel.restart();
}, },
}, },
{ {
label: WizardI18n("wizard.incomplete_submission.resume"), label: I18n.t("wizard.incomplete_submission.resume"),
class: "btn btn-primary", class: "btn btn-primary",
}, },
]; ];
@ -47,25 +50,12 @@ export default Route.extend({
updateCachedWizard(model); updateCachedWizard(model);
}, },
renderTemplate() {
this.render("wizard/templates/wizard");
},
setupController(controller, model) { 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({ controller.setProperties({
customWizard: true, customWizard: true,
logoUrl: this.siteSettings.logo_small, logoUrl: this.siteSettings.logo_small,
reset: null, reset: null,
model,
}); });
const stepModel = this.modelFor("step"); const stepModel = this.modelFor("step");
@ -76,5 +66,24 @@ export default Route.extend({
) { ) {
this.showDialog(model); 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 = "";
}, },
}); });

Datei anzeigen

@ -1,13 +1,13 @@
<div class="wizard-composer-hyperlink-contents"> <div class="wizard-composer-hyperlink-contents">
<h3>{{wizard-i18n "composer.link_dialog_title"}}</h3> <h3>{{i18n "composer.link_dialog_title"}}</h3>
{{input {{input
class="composer-link-name" class="composer-link-name"
placeholder=(wizard-i18n "composer.link_optional_text") placeholder=(i18n "composer.link_optional_text")
type="text" type="text"
value=linkName}} value=linkName}}
{{input {{input
class="composer-link-url" class="composer-link-url"
placeholder=(wizard-i18n "composer.link_url_placeholder") placeholder=(i18n "composer.link_url_placeholder")
type="text" type="text"
value=linkUrl}} value=linkUrl}}
{{d-button {{d-button

Datei anzeigen

@ -1,5 +1,5 @@
{{#unless timeFirst}} {{#unless timeFirst}}
{{wizard-date-input {{custom-wizard-date-input
date=date date=date
relativeDate=relativeDate relativeDate=relativeDate
onChange=(action "onChangeDate") onChange=(action "onChangeDate")
@ -8,7 +8,7 @@
{{/unless}} {{/unless}}
{{#if showTime}} {{#if showTime}}
{{wizard-time-input {{custom-wizard-time-input
date=date date=date
relativeDate=relativeDate relativeDate=relativeDate
onChange=(action "onChangeTime") onChange=(action "onChangeTime")
@ -17,7 +17,7 @@
{{/if}} {{/if}}
{{#if timeFirst}} {{#if timeFirst}}
{{wizard-date-input {{custom-wizard-date-input
date=date date=date
relativeDate=relativeDate relativeDate=relativeDate
onChange=(action "onChangeDate") onChange=(action "onChangeDate")

Datei anzeigen

@ -27,7 +27,7 @@
<button class="wizard-btn {{b.className}}" {{action b.action b}} title={{b.title}} type="button"> <button class="wizard-btn {{b.className}}" {{action b.action b}} title={{b.title}} type="button">
{{d-icon b.icon}} {{d-icon b.icon}}
{{#if b.label}} {{#if b.label}}
<span class="d-button-label">{{wizard-i18n b.label}}</span> <span class="d-button-label">{{i18n b.label}}</span>
{{/if}} {{/if}}
</button> </button>
{{/if}} {{/if}}

Datei anzeigen

@ -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
)}}

Datei anzeigen

@ -1,4 +1,4 @@
{{wizard-composer-editor {{custom-wizard-composer-editor
field=field field=field
composer=composer composer=composer
wizard=wizard wizard=wizard
@ -10,7 +10,7 @@
<div class="bottom-bar"> <div class="bottom-bar">
<button class="wizard-btn toggle-preview" {{action "togglePreview"}} type="button"> <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> </button>
{{#if field.char_counter}} {{#if field.char_counter}}

Datei anzeigen

@ -1,4 +1,4 @@
{{wizard-date-time-input {{custom-wizard-date-time-input
date=dateTime date=dateTime
onChange=(action "onChange") onChange=(action "onChange")
tabindex=field.tabindex tabindex=field.tabindex

Datei anzeigen

@ -1,4 +1,4 @@
{{wizard-date-input {{custom-wizard-date-input
date=date date=date
onChange=(action "onChange") onChange=(action "onChange")
tabindex=field.tabindex tabindex=field.tabindex

Datei anzeigen

@ -1,5 +1,5 @@
{{wizard-group-selector {{custom-wizard-group-selector
groups=wizard.groups groups=site.groups
field=field field=field
whitelist=field.content whitelist=field.content
value=field.value value=field.value

Datei anzeigen

@ -1,7 +1,8 @@
{{wizard-tag-chooser {{custom-wizard-tag-chooser
tags=field.value tags=field.value
maximum=field.limit
tabindex=field.tabindex tabindex=field.tabindex
tagGroups=field.tag_groups tagGroups=field.tag_groups
everyTag=true everyTag=true
}} options=(hash
maximum=field.limit
)}}

Datei anzeigen

@ -1,4 +1,4 @@
{{wizard-time-input {{custom-wizard-time-input
date=time date=time
onChange=(action "onChange") onChange=(action "onChange")
tabindex=field.tabindex tabindex=field.tabindex

Datei anzeigen

@ -1,8 +1,8 @@
<label class="wizard-btn wizard-btn-upload-file {{if uploading "disabled"}}" tabindex={{field.tabindex}}> <label class="wizard-btn wizard-btn-upload-file {{if uploading "disabled"}}" tabindex={{field.tabindex}}>
{{#if uploading}} {{#if uploading}}
{{wizard-i18n "wizard.uploading"}} {{i18n "wizard.uploading"}}
{{else}} {{else}}
{{wizard-i18n "wizard.upload"}} {{i18n "wizard.upload"}}
{{d-icon "upload"}} {{d-icon "upload"}}
{{/if}} {{/if}}

Datei anzeigen

@ -1,7 +1,7 @@
<div>{{text}}</div> <div>{{text}}</div>
<div class="no-access-gutter"> <div class="no-access-gutter">
<button class="wizard-btn primary return-to-site" {{action "skip"}} type="button"> <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"}} {{d-icon "sign-out-alt"}}
</button> </button>
</div> </div>

Datei anzeigen

@ -1,11 +1,11 @@
{{#if showTopics}} {{#if showTopics}}
<ul> <ul>
{{#each topics as |topic|}} {{#each topics as |topic|}}
<li>{{wizard-similar-topic topic=topic}}</li> <li>{{custom-wizard-similar-topic topic=topic}}</li>
{{/each}} {{/each}}
</ul> </ul>
{{else}} {{else}}
<a role="button" class="show-topics" {{action "toggleShowTopics"}}> <a role="button" class="show-topics" {{action "toggleShowTopics"}}>
{{wizard-i18n "realtime_validations.similar_topics.show"}} {{i18n "realtime_validations.similar_topics.show"}}
</a> </a>
{{/if}} {{/if}}

Datei anzeigen

@ -13,11 +13,11 @@
<div class="wizard-step-description">{{cookedDescription}}</div> <div class="wizard-step-description">{{cookedDescription}}</div>
{{/if}} {{/if}}
{{#wizard-step-form step=step}} {{#custom-wizard-step-form step=step}}
{{#each step.fields as |field|}} {{#each step.fields as |field|}}
{{wizard-field field=field step=step wizard=wizard}} {{custom-wizard-field field=field step=step wizard=wizard}}
{{/each}} {{/each}}
{{/wizard-step-form}} {{/custom-wizard-step-form}}
</div> </div>
<div class="wizard-step-footer"> <div class="wizard-step-footer">
@ -26,7 +26,7 @@
<div class="white"></div> <div class="white"></div>
<div class="black" style={{barStyle}}></div> <div class="black" style={{barStyle}}></div>
<div class="screen"></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>
<div class="wizard-buttons"> <div class="wizard-buttons">
@ -34,23 +34,23 @@
{{loading-spinner size="small"}} {{loading-spinner size="small"}}
{{else}} {{else}}
{{#if showQuitButton}} {{#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}}
{{#if showBackButton}} {{#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}} {{/if}}
{{#if showNextButton}} {{#if showNextButton}}
<button type="button" class="wizard-btn next primary" {{action "nextStep"}} disabled={{saving}} tabindex={{primaryButtonIndex}}> <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"}} {{d-icon "chevron-right"}}
</button> </button>
{{/if}} {{/if}}
{{#if showDoneButton}} {{#if showDoneButton}}
<button type="button" class="wizard-btn done" {{action "done"}} disabled={{saving}} tabindex={{primaryButtonIndex}}> <button type="button" class="wizard-btn done" {{action "done"}} disabled={{saving}} tabindex={{primaryButtonIndex}}>
{{wizard-i18n "wizard.done"}} {{i18n "wizard.done_custom"}}
</button> </button>
{{/if}} {{/if}}
</div> </div>

Datei anzeigen

@ -1,13 +1,13 @@
<label class={{currentStateClass}}> <label class={{currentStateClass}}>
{{#if currentState}} {{#if currentState}}
{{#if insufficientCharactersCategories}} {{#if insufficientCharactersCategories}}
{{html-safe (wizard-i18n currentStateKey catLinks=catLinks)}} {{html-safe (i18n currentStateKey catLinks=catLinks)}}
{{else}} {{else}}
{{wizard-i18n currentStateKey}} {{i18n currentStateKey}}
{{/if}} {{/if}}
{{/if}} {{/if}}
</label> </label>
{{#if showSimilarTopics}} {{#if showSimilarTopics}}
{{wizard-similar-topics topics=similarTopics}} {{custom-wizard-similar-topics topics=similarTopics}}
{{/if}} {{/if}}

Datei anzeigen

@ -0,0 +1,5 @@
{{#if isValid}}
{{i18n validMessageKey}}
{{else}}
{{i18n invalidMessageKey}}
{{/if}}

Datei anzeigen

@ -0,0 +1,3 @@
{{#if noAccess}}
{{custom-wizard-no-access text=(i18n noAccessI18nKey) wizardId=wizardId reason=noAccessReason}}
{{/if}}

Datei anzeigen

@ -5,15 +5,16 @@
</div> </div>
{{#if showReset}} {{#if showReset}}
<a role="button" class="reset-wizard" {{action "resetWizard"}}> <a role="button" class="reset-wizard" {{action "resetWizard"}}>
{{wizard-i18n "wizard.reset"}} {{i18n "wizard.reset"}}
</a> </a>
{{/if}} {{/if}}
</div> </div>
{{/if}} {{/if}}
{{#if step.permitted}} {{#if step.permitted}}
{{wizard-step step=step {{custom-wizard-step
wizard=wizard step=step
goNext=(action "goNext") wizard=wizard
goBack=(action "goBack") goNext=(action "goNext")
showMessage=(action "showMessage")}} goBack=(action "goBack")
showMessage=(action "showMessage")}}
{{/if}} {{/if}}

Datei anzeigen

@ -1,5 +0,0 @@
//= require legacy/set-prototype-polyfill
//= require legacy/env
//= require legacy/jquery
//= require legacy/ember_include
//= require legacy/discourse-loader

Datei anzeigen

@ -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'>&times;</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;
});

Datei anzeigen

@ -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);

Datei anzeigen

@ -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, "&lt;");
buf = buf.replace(/>/g, "&gt;");
buf = buf.replace(/[ ]/g, "&#x200b;&nbsp;&#x200b;");
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;
};

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen