FIX: validates import theme form (#6513)

This commit is contained in:
Joffrey JAFFEUX 2018-10-23 03:09:06 +02:00 committed by Sam
parent b74dd7d379
commit 7d2e582b28
2 changed files with 18 additions and 5 deletions

View File

@ -1,7 +1,10 @@
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import { observes } from "ember-addons/ember-computed-decorators"; import {
default as computed,
observes
} from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
local: Ember.computed.equal("selection", "local"), local: Ember.computed.equal("selection", "local"),
@ -11,8 +14,14 @@ export default Ember.Controller.extend(ModalFunctionality, {
loading: false, loading: false,
keyGenUrl: "/admin/themes/generate_key_pair", keyGenUrl: "/admin/themes/generate_key_pair",
importUrl: "/admin/themes/import", importUrl: "/admin/themes/import",
checkPrivate: Ember.computed.match("uploadUrl", /^git/), checkPrivate: Ember.computed.match("uploadUrl", /^git/),
localFile: null,
uploadUrl: null,
@computed("loading", "remote", "uploadUrl", "local", "localFile")
importDisabled(isLoading, isRemote, uploadUrl, isLocal, localFile) {
return isLoading || (isRemote && !uploadUrl) || (isLocal && !localFile);
},
@observes("privateChecked") @observes("privateChecked")
privateWasChecked() { privateWasChecked() {
@ -32,6 +41,10 @@ export default Ember.Controller.extend(ModalFunctionality, {
}, },
actions: { actions: {
uploadLocaleFile() {
this.set("localFile", $("#file-input")[0].files[0]);
},
importTheme() { importTheme() {
let options = { let options = {
type: "POST" type: "POST"
@ -41,7 +54,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
options.processData = false; options.processData = false;
options.contentType = false; options.contentType = false;
options.data = new FormData(); options.data = new FormData();
options.data.append("theme", $("#file-input")[0].files[0]); options.data.append("theme", this.get("localFile"));
} else { } else {
options.data = { options.data = {
remote: this.get("uploadUrl"), remote: this.get("uploadUrl"),

View File

@ -4,7 +4,7 @@
<label class="radio" for="local">{{i18n 'upload_selector.from_my_computer'}}</label> <label class="radio" for="local">{{i18n 'upload_selector.from_my_computer'}}</label>
{{#if local}} {{#if local}}
<div class="inputs"> <div class="inputs">
<input type="file" id="file-input" accept='.dcstyle.json,application/json'><br> <input onchange={{action "uploadLocaleFile"}} type="file" id="file-input" accept='.dcstyle.json,application/json'><br>
<span class="description">{{i18n 'admin.customize.theme.import_file_tip'}}</span> <span class="description">{{i18n 'admin.customize.theme.import_file_tip'}}</span>
</div> </div>
{{/if}} {{/if}}
@ -44,6 +44,6 @@
{{/d-modal-body}} {{/d-modal-body}}
<div class="modal-footer"> <div class="modal-footer">
{{d-button action="importTheme" disabled=loading class='btn btn-primary' icon='upload' label='admin.customize.import'}} {{d-button action="importTheme" disabled=importDisabled class='btn btn-primary' icon='upload' label='admin.customize.import'}}
{{d-modal-cancel close=(action "closeModal")}} {{d-modal-cancel close=(action "closeModal")}}
</div> </div>