| 12 | * 管理当前活跃和非活跃的表单 |
| 13 | * */ |
| 14 | export class InputHandler implements CommandHandler { |
| 15 | accept_command: string[] = ['input', 'input_group', 'update_input', 'destroy_form']; |
| 16 | |
| 17 | session: Session; |
| 18 | private form_ctrls: LRUMap; // task_id -> stack of FormGroupController |
| 19 | private readonly container_elem: JQuery; |
| 20 | |
| 21 | constructor(session: Session, container_elem: JQuery) { |
| 22 | this.session = session; |
| 23 | this.container_elem = container_elem; |
| 24 | this.form_ctrls = new LRUMap(); // task_id -> stack of FormGroupController |
| 25 | } |
| 26 | |
| 27 | private _after_show_form() { |
| 28 | // 解决表单显示后动态添加内容,表单宽高不变的问题 |
| 29 | setTimeout(() => { |
| 30 | let curr_card = $('#input-cards > .card')[0]; |
| 31 | curr_card.style.height = "unset"; |
| 32 | curr_card.style.width = "unset"; |
| 33 | }, 50); |
| 34 | |
| 35 | show_input(); |
| 36 | |
| 37 | let old_ctrls = this.form_ctrls.get_top(); |
| 38 | if (old_ctrls) |
| 39 | old_ctrls[old_ctrls.length - 1].after_show(); |
| 40 | |
| 41 | if (state.AutoFocusOnInput) |
| 42 | $('[auto_focus="true"]').focus(); |
| 43 | }; |
| 44 | |
| 45 | // hide old_ctrls显示的表单,激活 task_id 对应的表单 |
| 46 | // 需要保证 task_id 对应有表单 |
| 47 | private _activate_form(task_id: string, old_ctrl: InputItem) { |
| 48 | let ctrls = this.form_ctrls.get_value(task_id); |
| 49 | let ctrl = ctrls[ctrls.length - 1]; |
| 50 | if (ctrl === old_ctrl || old_ctrl === undefined) { |
| 51 | return ctrl.element.show(state.ShowDuration, () => { |
| 52 | this._after_show_form() |
| 53 | }); |
| 54 | } |
| 55 | this.form_ctrls.move_to_top(task_id); |
| 56 | old_ctrl.element.hide(100, () => { |
| 57 | // ctrl.element.show(100); |
| 58 | // 需要在回调中重新获取当前前置表单元素,因为100ms内可能有变化 |
| 59 | let t = this.form_ctrls.get_top(); |
| 60 | if (t) t[t.length - 1].element.show(state.ShowDuration, () => { |
| 61 | this._after_show_form() |
| 62 | }); |
| 63 | }); |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | /* |
| 68 | * 每次函数调用返回后,this.form_ctrls.get_top()的栈顶对应的表单为当前活跃表单 |
| 69 | * */ |
| 70 | handle_message(msg: Command) { |
| 71 | let old_ctrls = this.form_ctrls.get_top(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…