Created
March 29, 2016 20:41
-
-
Save fpaint/8fa65902703246605bfd2a1d3395c1c9 to your computer and use it in GitHub Desktop.
Модуль для форм
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| App.editor = (-> | |
| self = | |
| # ------------------ Форма ------------------ | |
| form: (container)-> | |
| el = $(container) | |
| # примитивы | |
| init_controls = -> | |
| button = $('<button type=button>').addClass('submit_button').html('Сохранить') | |
| el.append App.template.div 'form_controls', button | |
| button_state = App.ajax.button button, on_submit | |
| submit_proc = (url, data = {}, on_success = null, on_error = null)-> | |
| $.ajax | |
| method: 'post', | |
| url: url, | |
| data: data, | |
| success: on_success, | |
| error: on_error | |
| get_form_data = (data = {})-> | |
| $.extend data, $('form', el).serializeObject() | |
| # поведение | |
| on_submit = -> {} | |
| on_success = -> {} | |
| # внешний интерфейс | |
| form_instance = | |
| simple: (name, url)-> | |
| on_submit = -> | |
| data = get_form_data({name: name}) | |
| submit_proc(url, data, on_success) | |
| init_controls() | |
| @ | |
| form_instance | |
| self | |
| )() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment