Clean codes

This commit is contained in:
cuigh 2018-04-24 15:43:59 +08:00
parent a3857ac7da
commit 54b07dcd12
5 changed files with 0 additions and 135 deletions

View File

@ -1,70 +0,0 @@
///<reference path="../../core/core.ts" />
namespace Swirl.Stack.Archive {
import Validator = Swirl.Core.Validator;
import AjaxResult = Swirl.Core.AjaxResult;
import Notification = Swirl.Core.Notification;
import ValidationRule = Swirl.Core.ValidationRule;
class ContentRequiredRule implements ValidationRule {
validate($form: JQuery, $input: JQuery, arg?: string): {ok: boolean, error?: string} {
let el = <HTMLInputElement>$input[0];
if ($("#type-" + arg).prop("checked")) {
console.log(el.value);
return {ok: el.checkValidity ? el.checkValidity() : true, error: el.validationMessage};
}
return {ok: true}
}
}
export class EditPage {
private editor: any;
constructor() {
Validator.register("content", new ContentRequiredRule(), "");
this.editor = CodeMirror.fromTextArea($("#txt-content")[0], {lineNumbers: true});
$("#file-content").change(e => {
let file = <HTMLInputElement>e.target;
if (file.files.length > 0) {
$('#filename').text(file.files[0].name);
}
});
$("#type-input,#type-upload").click(e => {
let type = $(e.target).val();
$("#div-input").toggle(type == "input");
$("#div-upload").toggle(type == "upload");
});
$("#btn-submit").click(this.submit.bind(this))
}
private submit(e: JQueryEventObject) {
this.editor.save();
let results = Validator.bind("#div-form").validate();
if (results.length > 0) {
return;
}
let data = new FormData();
data.append('name', $("#name").val());
if ($("#type-input").prop("checked")) {
data.append('content', $('#txt-content').val());
} else {
let file = <HTMLInputElement>$('#file-content')[0];
data.append('content', file.files[0]);
}
let url = $(e.target).data("url") || "";
$ajax.post(url, data).encoder("none").trigger(e.target).json((r: AjaxResult) => {
if (r.success) {
location.href = "/stack/archive/"
} else {
Notification.show("danger", `FAILED: ${r.message}`);
}
})
}
}
}
declare var CodeMirror: any;

View File

@ -1,37 +0,0 @@
///<reference path="../../core/core.ts" />
namespace Swirl.Stack.Archive {
import Modal = Swirl.Core.Modal;
import AjaxResult = Swirl.Core.AjaxResult;
import Dispatcher = Swirl.Core.Dispatcher;
export class ListPage {
constructor() {
let dispatcher = Dispatcher.bind("#table-items");
dispatcher.on("deploy-archive", this.deployArchive.bind(this));
dispatcher.on("delete-archive", this.deleteArchive.bind(this));
}
private deployArchive(e: JQueryEventObject) {
let $tr = $(e.target).closest("tr");
let id = $tr.data("id");
let name = $tr.find("td:first").text().trim();
Modal.confirm(`Are you sure to deploy archive: <strong>${name}</strong>?`, "Deploy archive", (dlg, e) => {
$ajax.post("deploy", {id: id}).trigger(e.target).encoder("form").json<AjaxResult>(r => {
dlg.close();
})
});
}
private deleteArchive(e: JQueryEventObject) {
let $tr = $(e.target).closest("tr");
let id = $tr.data("id");
let name = $tr.find("td:first").text().trim();
Modal.confirm(`Are you sure to remove archive: <strong>${name}</strong>?`, "Delete archive", (dlg, e) => {
$ajax.post("delete", {id: id}).trigger(e.target).encoder("form").json<AjaxResult>(r => {
$tr.remove();
dlg.close();
})
});
}
}
}

View File

@ -1,24 +0,0 @@
///<reference path="../../core/core.ts" />
namespace Swirl.Stack.Task {
import Modal = Swirl.Core.Modal;
import AjaxResult = Swirl.Core.AjaxResult;
import Dispatcher = Swirl.Core.Dispatcher;
export class ListPage {
constructor() {
let dispatcher = Dispatcher.bind("#table-items");
dispatcher.on("delete-stack", this.deleteStack.bind(this));
}
private deleteStack(e: JQueryEventObject) {
let $tr = $(e.target).closest("tr");
let name = $tr.find("td:first").text().trim();
Modal.confirm(`Are you sure to remove stack: <strong>${name}</strong>?`, "Delete stack", (dlg, e) => {
$ajax.post("delete", {name: name}).trigger(e.target).encoder("form").json<AjaxResult>(r => {
$tr.remove();
dlg.close();
})
});
}
}
}

View File

@ -74,8 +74,6 @@ menu.network: Networks
menu.service: Services
menu.service.template: Templates
menu.stack: Stacks
menu.stack.task: Tasks
menu.stack.archive: Archives
menu.task: Tasks
menu.secret: Secrets
menu.config: Configs

View File

@ -74,8 +74,6 @@ menu.network: 网络
menu.service: 服务
menu.service.template: 模板
menu.stack: 编排
menu.stack.task: 任务
menu.stack.archive: 档案
menu.task: 任务
menu.secret: 私密配置
menu.config: 常规配置