| 1 |
import './helpers'; |
| 2 |
import Vue from 'vue'; |
| 3 |
import Vddl from 'vddl'; |
| 4 |
|
| 5 |
import store from './store'; |
| 6 |
import jQueryActions from './jquery-actions'; |
| 7 |
import ajaxCaller from './ajaxCaller'; |
| 8 |
import './css/element-variables.scss'; |
| 9 |
import { |
| 10 |
Button, |
| 11 |
Checkbox, |
| 12 |
CheckboxGroup, |
| 13 |
Col, |
| 14 |
ColorPicker, |
| 15 |
Dialog, |
| 16 |
Dropdown, |
| 17 |
DropdownItem, |
| 18 |
DropdownMenu, |
| 19 |
Form, |
| 20 |
FormItem, |
| 21 |
Input, |
| 22 |
Slider, |
| 23 |
Loading, |
| 24 |
Message, |
| 25 |
Notification, |
| 26 |
Option, |
| 27 |
Popover, |
| 28 |
Radio, |
| 29 |
RadioButton, |
| 30 |
RadioGroup, |
| 31 |
Rate, |
| 32 |
Row, |
| 33 |
Select, |
| 34 |
TabPane, |
| 35 |
Tabs, |
| 36 |
Tooltip, |
| 37 |
Upload |
| 38 |
} from 'element-ui'; |
| 39 |
|
| 40 |
import lang from 'element-ui/lib/locale/lang/en'; |
| 41 |
import locale from 'element-ui/lib/locale'; |
| 42 |
import mixins from './editor_mixins'; |
| 43 |
// Global error handling... |
| 44 |
import Errors from '../common/Errors'; |
| 45 |
import FormEditor from './views/FormEditor.vue'; |
| 46 |
import {mapActions} from 'vuex'; |
| 47 |
|
| 48 |
Vue.use(Vddl); |
| 49 |
Vue.use(jQueryActions); |
| 50 |
Vue.use(ajaxCaller); |
| 51 |
|
| 52 |
Vue.use(Rate); |
| 53 |
Vue.use(Tabs); |
| 54 |
Vue.use(TabPane); |
| 55 |
Vue.use(ColorPicker); |
| 56 |
Vue.use(Dropdown); |
| 57 |
Vue.use(DropdownMenu); |
| 58 |
Vue.use(DropdownItem); |
| 59 |
Vue.use(Select); |
| 60 |
Vue.use(Slider); |
| 61 |
Vue.use(Option); |
| 62 |
Vue.use(Popover); |
| 63 |
Vue.use(Checkbox); |
| 64 |
Vue.use(CheckboxGroup); |
| 65 |
Vue.use(Row); |
| 66 |
Vue.use(Col); |
| 67 |
Vue.use(RadioButton); |
| 68 |
Vue.use(RadioGroup); |
| 69 |
Vue.use(Radio); |
| 70 |
Vue.use(Input); |
| 71 |
Vue.use(Dialog); |
| 72 |
Vue.use(Button); |
| 73 |
Vue.use(Form); |
| 74 |
Vue.use(FormItem); |
| 75 |
Vue.use(Tooltip); |
| 76 |
Vue.use(Upload); |
| 77 |
|
| 78 |
Vue.use(Loading.directive); |
| 79 |
Vue.prototype.$loading = Loading.service; |
| 80 |
Vue.prototype.$notify = Notification; |
| 81 |
Vue.prototype.$message = Message; |
| 82 |
|
| 83 |
// configure language |
| 84 |
locale.use(lang); |
| 85 |
|
| 86 |
window.FluentFormEditorEvents = new Vue(); |
| 87 |
|
| 88 |
Vue.mixin(mixins); |
| 89 |
|
| 90 |
global.Errors = Errors; |
| 91 |
|
| 92 |
new Vue({ |
| 93 |
el: "#ff_form_editor_app", |
| 94 |
store, |
| 95 |
components: { |
| 96 |
ff_form_editor: FormEditor |
| 97 |
}, |
| 98 |
data: { |
| 99 |
form_id: window.FluentFormApp.form_id, |
| 100 |
form: { |
| 101 |
title: "", |
| 102 |
dropzone: [], |
| 103 |
submitButton: {}, |
| 104 |
stepsWrapper: {}, |
| 105 |
stepStart: { |
| 106 |
element: "step_start", |
| 107 |
attributes: { |
| 108 |
id: "", |
| 109 |
class: "" |
| 110 |
}, |
| 111 |
settings: { |
| 112 |
progress_indicator: "progress-bar", |
| 113 |
step_titles: [], |
| 114 |
disable_auto_focus: 'no', |
| 115 |
enable_auto_slider: 'no', |
| 116 |
enable_step_data_persistency: 'no', |
| 117 |
enable_step_page_resume: 'no' |
| 118 |
}, |
| 119 |
editor_options: { |
| 120 |
title: "Start Paging" |
| 121 |
} |
| 122 |
}, |
| 123 |
stepEnd: { |
| 124 |
element: "step_end", |
| 125 |
attributes: { |
| 126 |
id: "", |
| 127 |
class: "" |
| 128 |
}, |
| 129 |
settings: { |
| 130 |
prev_btn: { |
| 131 |
type: "default", |
| 132 |
text: "Previous", |
| 133 |
img_url: "" |
| 134 |
} |
| 135 |
}, |
| 136 |
editor_options: { |
| 137 |
title: "End Paging" |
| 138 |
} |
| 139 |
} |
| 140 |
}, |
| 141 |
submitButtonMock: { |
| 142 |
uniqElKey: "el_" + Date.now(), |
| 143 |
element: "button", |
| 144 |
attributes: { |
| 145 |
type: "submit", |
| 146 |
class: "" |
| 147 |
}, |
| 148 |
settings: { |
| 149 |
align: "left", |
| 150 |
button_style: "default", |
| 151 |
container_class: "", |
| 152 |
help_message: "", |
| 153 |
button_size: "md", |
| 154 |
button_ui: { |
| 155 |
type: "default", |
| 156 |
text: "Submit Form", |
| 157 |
img_url: "" |
| 158 |
}, |
| 159 |
conditional_logics: [], |
| 160 |
normal_styles: { |
| 161 |
'backgroundColor' : '#409EFF', |
| 162 |
'borderColor' : '#409EFF', |
| 163 |
'color' : '#ffffff', |
| 164 |
'borderRadius' : '', |
| 165 |
'minWidth' : '' |
| 166 |
}, |
| 167 |
hover_styles: { |
| 168 |
'backgroundColor' : '#ffffff', |
| 169 |
'borderColor' : '#409EFF', |
| 170 |
'color' : '#409EFF', |
| 171 |
'borderRadius' : '', |
| 172 |
'minWidth' : '' |
| 173 |
} |
| 174 |
}, |
| 175 |
editor_options: { |
| 176 |
title: "Submit Button" |
| 177 |
} |
| 178 |
}, |
| 179 |
loading: false, |
| 180 |
form_saving: false |
| 181 |
}, |
| 182 |
methods: { |
| 183 |
...mapActions(["loadEditorShortcodes"]), |
| 184 |
|
| 185 |
/** |
| 186 |
* Prepare the form for the dropzone |
| 187 |
* after fetching from the server |
| 188 |
*/ |
| 189 |
prepareForm() { |
| 190 |
var form = window.FluentFormApp.form; |
| 191 |
let formData = form.form_fields ? JSON.parse(form.form_fields) : {}; |
| 192 |
|
| 193 |
this.form.id = form.id; |
| 194 |
this.form.title = form.title; |
| 195 |
this.form.dropzone = formData.fields || []; |
| 196 |
let button = formData.submitButton || JSON.parse(JSON.stringify(this.submitButtonMock)); |
| 197 |
|
| 198 |
if (!button.settings.conditional_logics) { |
| 199 |
// we will implement later |
| 200 |
// button.settings.conditional_logics = []; |
| 201 |
} |
| 202 |
|
| 203 |
this.form.submitButton = button; |
| 204 |
|
| 205 |
this.form.stepsWrapper = formData.stepsWrapper || this.form.stepsWrapper; |
| 206 |
|
| 207 |
if (formData.stepsWrapper && formData.stepsWrapper.stepStart) { |
| 208 |
if(!formData.stepsWrapper.stepStart.settings.disable_auto_focus) { |
| 209 |
formData.stepsWrapper.stepStart.settings.disable_auto_focus = 'no'; |
| 210 |
} |
| 211 |
|
| 212 |
if(!formData.stepsWrapper.stepStart.settings.enable_auto_slider) { |
| 213 |
formData.stepsWrapper.stepStart.settings.enable_auto_slider = 'no'; |
| 214 |
} |
| 215 |
|
| 216 |
if(!formData.stepsWrapper.stepStart.settings.enable_step_data_persistency) { |
| 217 |
formData.stepsWrapper.stepStart.settings.enable_step_data_persistency = 'no'; |
| 218 |
} |
| 219 |
|
| 220 |
if(!formData.stepsWrapper.stepStart.settings.enable_step_page_resume) { |
| 221 |
formData.stepsWrapper.stepStart.settings.enable_step_page_resume = 'no'; |
| 222 |
} |
| 223 |
|
| 224 |
this.form.stepStart = formData.stepsWrapper.stepStart; |
| 225 |
} |
| 226 |
|
| 227 |
if (formData.stepsWrapper && formData.stepsWrapper.stepEnd) { |
| 228 |
this.form.stepEnd = formData.stepsWrapper.stepEnd; |
| 229 |
} |
| 230 |
|
| 231 |
this.initNotifyUnsaved(); |
| 232 |
}, |
| 233 |
|
| 234 |
/** |
| 235 |
* The the form data into the server |
| 236 |
*/ |
| 237 |
saveForm() { |
| 238 |
this.form_saving = true; |
| 239 |
let formFields = { |
| 240 |
fields: this.form.dropzone, |
| 241 |
submitButton: this.form.submitButton |
| 242 |
}; |
| 243 |
|
| 244 |
if (!_ff.isEmpty(this.form.stepsWrapper)) { |
| 245 |
formFields.stepsWrapper = this.form.stepsWrapper; |
| 246 |
} |
| 247 |
|
| 248 |
let data = { |
| 249 |
action: this.$action.updateForm, |
| 250 |
formId: this.form_id, |
| 251 |
title: this.form.title, |
| 252 |
formFields: JSON.stringify(formFields) |
| 253 |
}; |
| 254 |
|
| 255 |
jQuery |
| 256 |
.post(ajaxurl, data) |
| 257 |
.done(response => { |
| 258 |
this.$notify({ |
| 259 |
title: "Success", |
| 260 |
message: response.message, |
| 261 |
type: "success", |
| 262 |
position: "bottom-right" |
| 263 |
}); |
| 264 |
this.form_saving = false; |
| 265 |
FluentFormApp.isDirty = false; |
| 266 |
|
| 267 |
const saveFormBtn = jQuery("#saveFormData"); |
| 268 |
saveFormBtn.text(saveFormBtn.data("text")); |
| 269 |
|
| 270 |
// Update the hash now. |
| 271 |
this.saveHash(); |
| 272 |
}) |
| 273 |
.error(error => { |
| 274 |
this.$notify.error({ |
| 275 |
title: "Oops", |
| 276 |
message: error.responseJSON.title, |
| 277 |
offset: 30 |
| 278 |
}); |
| 279 |
}); |
| 280 |
}, |
| 281 |
|
| 282 |
initNotifyUnsaved() { |
| 283 |
// Save the initial save. |
| 284 |
this.saveHash(); |
| 285 |
|
| 286 |
jQuery(window).on('beforeunload', () => { |
| 287 |
if (this.dropzoneHash !== JSON.stringify(this.form.dropzone)) return true; |
| 288 |
}); |
| 289 |
}, |
| 290 |
|
| 291 |
saveHash() { |
| 292 |
this.dropzoneHash = JSON.stringify(this.form.dropzone); |
| 293 |
} |
| 294 |
}, |
| 295 |
mounted() { |
| 296 |
this.prepareForm(); |
| 297 |
this.loadEditorShortcodes(this.form_id); |
| 298 |
}, |
| 299 |
beforeCreate() { |
| 300 |
// Event listener for page title updater |
| 301 |
this.$on("change-title", module => { |
| 302 |
jQuery("title").text(`${module} - Fluentform`); |
| 303 |
}); |
| 304 |
this.$emit("change-title", "Editor"); |
| 305 |
} |
| 306 |
}); |
| 307 |
|