-
Notifications
You must be signed in to change notification settings - Fork 32
/
customFormFieldEdit.js
154 lines (132 loc) · 4.15 KB
/
customFormFieldEdit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import $ from 'jquery'
import {
TweenLite,
Expo
} from 'gsap'
/**
* CUSTOM FORM FIELD EDIT
*/
export default function CustomFormFieldEdit () {
var _this = this
// Selectors
_this.$btn = $('.custom-form-field-edit-button')
if (_this.$btn.length) {
_this.$formFieldRow = $('.custom-form-field-row')
_this.$formFieldCol = $('.custom-form-field-col')
_this.indexOpen = null
_this.openFormDelay = 0
_this.$formCont = null
_this.$form = null
_this.$formIcon = null
_this.$formContHeight = null
// Methods
_this.init()
}
};
/**
* Init
* @return {[type]} [description]
*/
CustomFormFieldEdit.prototype.init = function () {
var _this = this
// Events
var proxy = $.proxy(_this.btnClick, _this)
_this.$btn.off('click', proxy)
_this.$btn.on('click', proxy)
}
/**
* Btn click
* @return {[type]} [description]
*/
CustomFormFieldEdit.prototype.btnClick = function (e) {
var _this = this
e.preventDefault()
if (_this.indexOpen !== null) {
_this.closeForm()
_this.openFormDelay = 500
} else _this.openFormDelay = 0
if (_this.indexOpen !== parseInt(e.currentTarget.getAttribute('data-index'))) {
if (_this.openTimeout) {
clearTimeout(_this.openTimeout)
}
_this.openTimeout = setTimeout(function () {
_this.indexOpen = parseInt(e.currentTarget.getAttribute('data-index'))
$.ajax({
url: e.currentTarget.href,
type: 'get',
cache: false,
dataType: 'html'
})
.done(function (data) {
_this.applyContent(e.currentTarget, data, e.currentTarget.href)
})
.fail(function () {
// console.log("error");
window.UIkit.notify({
message: window.Rozier.messages.forbiddenPage,
status: 'danger',
timeout: 3000,
pos: 'top-center'
})
})
}, _this.openFormDelay)
}
return false
}
/**
* Apply content
* @return {[type]} [description]
*/
CustomFormFieldEdit.prototype.applyContent = function (target, data, url) {
var _this = this
var dataWrapped = [
'<tr class="custom-form-field-edit-form-row">',
'<td colspan="4">',
'<div class="custom-form-field-edit-form-cont">',
data,
'</div>',
'</td>',
'</tr>'
].join('')
$(target).parent().parent().after(dataWrapped)
// Remove class to pause sortable actions
_this.$formFieldCol.removeClass('custom-form-field-col')
// Switch checkboxes
$('.rz-boolean-checkbox').bootstrapSwitch({
size: 'small'
})
window.Rozier.lazyload.initMarkdownEditors()
setTimeout(function () {
_this.$formCont = $('.custom-form-field-edit-form-cont')
_this.formContHeight = _this.$formCont.actual('height')
_this.$formRow = $('.custom-form-field-edit-form-row')
_this.$form = $('#edit-custom-form-field-form')
_this.$formIcon = $(_this.$formFieldRow[_this.indexOpen]).find('.custom-form-field-col-1 i')
_this.$form.attr('action', url)
_this.$formIcon[0].className = 'uk-icon-chevron-down'
_this.$formCont[0].style.height = '0px'
_this.$formCont[0].style.display = 'block'
TweenLite.to(_this.$form, 0.6, {height: _this.formContHeight, ease: Expo.easeOut})
TweenLite.to(_this.$formCont, 0.6, {height: _this.formContHeight, ease: Expo.easeOut})
}, 200)
}
/**
* Close form
* @return {[type]} [description]
*/
CustomFormFieldEdit.prototype.closeForm = function () {
var _this = this
_this.$formIcon[0].className = 'uk-icon-chevron-right'
TweenLite.to(_this.$formCont, 0.4, {height: 0,
ease: Expo.easeOut,
onComplete: function () {
_this.$formRow.remove()
_this.indexOpen = null
_this.$formFieldCol.addClass('custom-form-field-col')
}})
}
/**
* Window resize callback
* @return {[type]} [description]
*/
CustomFormFieldEdit.prototype.resize = function () {}