diff --git a/static/js/modal.js b/static/js/modal.js new file mode 100644 index 0000000..0e94cfc --- /dev/null +++ b/static/js/modal.js @@ -0,0 +1,40 @@ +function Modal(modalTitle, fields, onSubmit) { + this.modalTitle = modalTitle + this.fields = fields + this.onSubmit = onSubmit +} + +Modal.prototype.GenericModalForm = function () { + let self = this + // 设置表单标题 + $('#genericFormModalLabel').text(self.modalTitle) + // 生成表单内容 + let $form = $('#genericForm') + $form.empty() + self.fields.forEach(function(field) { + let $formGroup = $('
') + $formGroup.append('') + + let $input + if (field.type === 'textarea') { + $input = $('') + } else { + $input = $('') + } + + $formGroup.append($input) + $form.append($formGroup) + }) + // 显示模态框 + $('#genericFormModal').modal('show'); + + // 处理表单提交 + $('#genericFormSubmit').off('click').on('click', function() { + let formData = {} + $form.serializeArray().forEach(function(item) { + formData[item.name] = item.value + }) + self.onSubmit(formData) + $('#genericFormModal').modal('hide') + }) +} \ No newline at end of file diff --git a/view/layout.html b/view/layout.html index 929f2db..0dfa2df 100644 --- a/view/layout.html +++ b/view/layout.html @@ -49,15 +49,28 @@ {{ .csrfField }} {{template "content" .}} - + + {{template "script" .}} diff --git a/view/picture.html b/view/picture.html index 65916ad..8b89223 100644 --- a/view/picture.html +++ b/view/picture.html @@ -2,9 +2,31 @@ {{end}} {{define "content"}} -

Picture

-

Picture page content goes here.

+

通用弹出表单示例

+ + {{end}} {{define "script"}} + + {{end}}