From fd9dc5d54578cb7fde371f81ecb914d1cab7fbec Mon Sep 17 00:00:00 2001 From: decoder Date: Wed, 6 Mar 2024 23:11:10 +0500 Subject: [PATCH] added translate for form name --- app/Http/Controllers/FormController.php | 4 +- app/Http/Controllers/LocaleController.php | 9 + .../Controllers/ManageSettingsController.php | 9 + ...2941_add_translate_name_to_forms_table.php | 33 + lang/en/messages.php | 2 + resources/js/components/CreateForm.vue | 1380 +++++++------ resources/js/components/FormTab.vue | 1751 +++++++++-------- resources/views/home.blade.php | 19 +- 8 files changed, 1809 insertions(+), 1398 deletions(-) create mode 100644 database/migrations/2024_03_06_172941_add_translate_name_to_forms_table.php diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index 3d3658d..19bbb73 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -191,7 +191,7 @@ class FormController extends Controller public function update($id) { try { - $input = request()->only('name', 'description', 'slug'); + $input = request()->only('name', 'name_ru', 'name_est', 'description', 'slug'); $form_data = [ 'form' => request()->input('form'), 'emailConfig' => request()->input('email_config'), @@ -210,6 +210,8 @@ class FormController extends Controller $form = Form::find($id); $form->name = $input['name']; + $form->name_ru = $input['name_ru']; + $form->name_est = $input['name_est']; $form->slug = $input['slug']; $form->description = $input['description']; $form->schema = $input['schema']; diff --git a/app/Http/Controllers/LocaleController.php b/app/Http/Controllers/LocaleController.php index 0a052ab..dbda5a8 100644 --- a/app/Http/Controllers/LocaleController.php +++ b/app/Http/Controllers/LocaleController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\UserSetting; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Session; @@ -17,6 +18,14 @@ class LocaleController extends Controller app()->setLocale($locale); + $userSetting = UserSetting::where('user_id', auth()->user()->id)->first(); + + if (!empty($userSetting)) { + $userSetting->update([ + 'language' => $locale + ]); + } + return redirect()->back(); } } diff --git a/app/Http/Controllers/ManageSettingsController.php b/app/Http/Controllers/ManageSettingsController.php index 4d43f1e..dca31a1 100644 --- a/app/Http/Controllers/ManageSettingsController.php +++ b/app/Http/Controllers/ManageSettingsController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\UserSetting; use DateTimeZone; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Session; class ManageSettingsController extends Controller { @@ -57,6 +58,14 @@ class ManageSettingsController extends Controller $setting = UserSetting::where('user_id', $input['user_id'])->first(); + if (! in_array($request->language, ['en', 'ru', 'est'])) { + abort(400); + } + + Session::put('locale', $request->language); + + app()->setLocale($request->language); + if (empty($setting)) { UserSetting::create($input); } else { diff --git a/database/migrations/2024_03_06_172941_add_translate_name_to_forms_table.php b/database/migrations/2024_03_06_172941_add_translate_name_to_forms_table.php new file mode 100644 index 0000000..3c28ad6 --- /dev/null +++ b/database/migrations/2024_03_06_172941_add_translate_name_to_forms_table.php @@ -0,0 +1,33 @@ +string('name_ru')->after('name')->nullable(); + $table->string('name_est')->after('name_ru')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('forms', function (Blueprint $table) { + // + }); + } +}; diff --git a/lang/en/messages.php b/lang/en/messages.php index 83dcaa4..331a8b6 100644 --- a/lang/en/messages.php +++ b/lang/en/messages.php @@ -685,4 +685,6 @@ return [ 'placeholder_ru' => 'Placeholder in Ru', 'options_est' => 'Options in est', 'options_ru' => 'Options in Ru', + 'form_name_est' => 'Form Name est', + 'form_name_ru' => 'Form Name ru', ]; diff --git a/resources/js/components/CreateForm.vue b/resources/js/components/CreateForm.vue index 98adbfd..603569a 100644 --- a/resources/js/components/CreateForm.vue +++ b/resources/js/components/CreateForm.vue @@ -1,617 +1,787 @@ \ No newline at end of file + + this.webhook_info = + this.form_parsed?.webhook_info || this.getData("webhook_info"); + + this.getNewlyAddedPropertyForExistingForm(); + this.$eventBus.$on("callRedirectUser", (data) => { + $("#userChoiceModal").modal("hide"); + setTimeout(() => { + this.redirectUsersAccordingToResponse(data); + }, 1000); + }); + }, + beforeDestroy() { + this.$eventBus.$off("callRedirectUser"); + }, + mounted() { + const self = this; + + $("form#create_form").validate({ + ignore: ".note-editor *", + submitHandler: function (form, e) { + var field_names = []; + if (self.selected_elements.length > 0) { + for (let index = 0; index < self.selected_elements.length; index++) { + self.selected_elements[index].extras.showConfigurator = false; + if (_.isEmpty(self.selected_elements[index].name)) { + toastr.error( + self.trans("messages.field_dont_have_name_property", { + input: self.selected_elements[index].label, + }) + ); + return false; + } else if (/\s/.test(self.selected_elements[index].name)) { + toastr.error( + self.trans("messages.field_contain_space", { + input: self.selected_elements[index].label, + }) + ); + return false; + } else if ( + _.includes(field_names, self.selected_elements[index].name) + ) { + toastr.error( + self.trans("messages.field_contain_duplicate_field_name", { + input: self.selected_elements[index].label, + }) + ); + field_names = []; + return false; + } else if ( + !_.includes(field_names, self.selected_elements[index].name) + ) { + field_names.push(self.selected_elements[index].name); + } + } + } + + let data = _.pick(self.form, [ + "name", + "name_ru", + "name_est", + "description", + "slug", + ]); + console.log(data); + data.form = self.selected_elements; + data.email_config = self.emailConfig; + data.settings = self.settings; + data.js_css = self.additionalData; + data.mailchimp_details = self.mailchimp_details; + data.acelle_mail_info = self.acelle_mail_info; + data.conditional_fields = self.conditional_fields; + data.is_template = $("input[name='submit_type']").val(); + data.form_attributes = self.form_custom_attributes; + data.contains_page_break = _.some(self.selected_elements, { + type: "page_break", + }); + data.webhook_info = self.webhook_info; + //get ladda btn based on submit type + if (data.is_template === "1") { + var ladda = Ladda.create( + document.querySelector(".ladda-template-save-btn") + ); + } else { + var ladda = Ladda.create( + document.querySelector(".ladda-form-save-btn") + ); + } + + if ($("form#create_form").valid()) { + //disable both btn and start ladda + $("button.ladda-form-save-btn, button.ladda-template-save-btn").attr( + "disabled", + "disabled" + ); + ladda.start(); + + axios + .put("/forms/" + self.form_parsed.id, data) + .then(function (response) { + //remove disable from both btn and stop ladda + $( + "button.ladda-form-save-btn, button.ladda-template-save-btn" + ).removeAttr("disabled"); + ladda.stop(); + + if (response.data.success == true) { + self.responseData = response.data; + $("#userChoiceModal").modal("show"); + } else { + toastr.error(response.data.msg); + } + }) + .catch(function (error) { + console.log(error); + }); + } + }, + }); + + //if mpfg_tour not finished call getAppTour + if (_.isNull(localStorage.getItem("mpfg_tour"))) { + localStorage.setItem("mpfg_tour", "finished"); + this.getAppTour(); + } + }, + methods: { + getData(type) { + if (type == "email_config") { + var email = { + email: { + enable: "", + from: "", + to: "", + reply_to_email: "", + cc: "", + bcc: "", + subject: "", + body: "", + attach_pdf: false, + }, + auto_response: { + from: "", + to: "", + subject: "", + body: "", + is_enable: false, + attach_pdf: false, + }, + smtp: { + host: "", + port: "", + from_address: "", + from_name: "", + encryption: "", + username: "", + password: "", + use_system_smtp: 1, + }, + }; + + return email; + } else if (type == "settings") { + var setting = { + recaptcha: { + is_enable: 0, + site_key: "", + secret_key: "", + }, + color: { + label: "#000000", + error_msg: "#a94442", + required_asterisk_color: "#a94442", + background: "#ffffff", + image_path: "", + page_color: "#f4f6f9", + }, + notification: { + post_submit_action: "same_page", + failed_msg: "Something went wrong, please try again.", + success_msg: "Your submission has been received.", + redirect_url: "", + position: "toast-top-right", + }, + submit: { + text: "Submit", + loading_text: "Submitting...", + btn_alignment: "float-right", + btn_size: "", + btn_color: "btn-primary", + btn_style: "default", + btn_icon: "none", + icon_position: "left", + }, + form_data: { + col_visible: [], + btn_enabled: ["view", "delete"], + }, + background: { + bg_type: "bg_color", + }, + form_scheduling: this.form_scheduling, + form_submision_ref: this.form_submision_ref, + theme: this.form_theme, + is_enabled_draft_submit: this.is_enabled_draft_submit, + layout: "classic", + password_protection: this.password_protection, + pdf_design: this.pdf_design, + is_qr_code_enabled: false, + qr_code_data_format: "string", + is_ref_num_bar_code_enabled: false, + is_ref_num_qr_code_enabled: false, + }; + + return setting; + } else if (type == "mailchimp") { + return { + is_enable: false, + api_key: "", + list_id: "", + email_field: "", + name_field: "", + }; + } else if (type == "acelle_mail") { + return { + is_enable: false, + api_token: "", + list_id: "", + campaign_fields: [], + }; + } else if (type == "conditional_fields") { + var conditional_fields = [ + { + action: "", + element: "", + conditions: [ + { + condition: "", + value: "", + element_type: "text", + element_index: "", + operator: "==", + logical_operator: "AND", + }, + ], + }, + ]; + + return conditional_fields; + } else if (type == "webhook_info") { + return { + is_enable: false, + url: "", + secret_key: "", + }; + } + }, + getNewlyAddedPropertyForExistingForm() { + const self = this; + _.forEach(self.selected_elements, function (element) { + if (_.isUndefined(element.conditional_class)) { + element.conditional_class = ""; + } + + if (_.isUndefined(element.col)) { + element.col = "col-md-12"; + } + + if (_.isUndefined(element.popover_help_text)) { + element["popover_help_text"] = _.clone(self.popover_help_text); + } + //if spread to col option is undefined for element set to default + if ( + _.includes(["radio", "checkbox"], element.type) && + _.isUndefined(element.spread_to_col) + ) { + element.spread_to_col = self.spread_to_col; + } + + if ( + _.includes(["text"], element.type) && + _.includes(["text", "email", "number"], element.subtype) && + _.isUndefined(element.allowed_input) + ) { + element.allowed_input = { + values: "", + error_msg: "This value is not allowed.", + }; + } + }); + + if (_.isUndefined(self.settings.form_scheduling)) { + self.settings.form_scheduling = self.form_scheduling; + } + + if (_.isUndefined(self.settings.form_submision_ref)) { + self.settings.form_submision_ref = self.form_submision_ref; + } + + if (_.isUndefined(self.settings.theme)) { + self.settings.theme = self.form_theme; + } + + if (_.isUndefined(self.settings.is_qr_code_enabled)) { + Vue.set(self.settings, "is_qr_code_enabled", false); + } + + if ( + _.isUndefined(self.settings.is_ref_num_bar_code_enabled) || + _.isUndefined(self.settings.is_ref_num_qr_code_enabled) + ) { + Vue.set(self.settings, "is_ref_num_bar_code_enabled", false); + Vue.set(self.settings, "is_ref_num_qr_code_enabled", false); + } + + if (_.isUndefined(self.settings.qr_code_data_format)) { + Vue.set(self.settings, "qr_code_data_format", "string"); + } + + if (_.isUndefined(self.settings.is_enabled_draft_submit)) { + self.settings.is_enabled_draft_submit = self.is_enabled_draft_submit; + } + + if (_.isUndefined(self.settings.notification.position)) { + self.settings.notification.position = "toast-top-right"; + } + + if (_.isUndefined(self.settings.submit.btn_style)) { + Vue.set(self.settings.submit, "btn_style", "default"); + } + + if (_.isUndefined(self.settings.submit.btn_icon)) { + Vue.set(self.settings.submit, "btn_icon", "none"); + } + + if (_.isUndefined(self.settings.submit.icon_position)) { + Vue.set(self.settings.submit, "icon_position", "left"); + } + + if (_.isUndefined(self.settings.color.page_color)) { + Vue.set(self.settings.color, "page_color", "#f4f6f9"); + } + + if (_.isUndefined(self.settings.password_protection)) { + self.settings.password_protection = self.password_protection; + } + + if (_.isUndefined(self.settings.pdf_design)) { + self.settings.pdf_design = self.pdf_design; + } + }, + redirectUsersAccordingToResponse(choice) { + if (choice == "home") { + window.location = this.responseData.redirect; + } else if (choice == "preview") { + window.open(this.responseData.preview, this.responseData.form_name); + } + }, + getAppTour() { + if (!$('#appTab a[href="#form-generator"]').hasClass("active")) { + $('#appTab a[href="#form-generator"]').tab("show"); + } + + const self = this; + var intro = introJs(); + intro.setOptions({ + steps: [ + { + intro: self.trans("messages.welcome_tour_msg"), + }, + { + element: document.querySelectorAll("#tour_step_1")[0], + intro: self.trans("messages.tour_step_1_intro"), + position: "right", + scrollTo: "tooltip", + }, + { + element: "#tour_step_2", + intro: self.trans("messages.tour_step_2_intro"), + position: "right", + scrollTo: "tooltip", + }, + { + element: "#tour_step_3", + intro: self.trans("messages.tour_step_3_intro"), + position: "bottom", + scrollTo: "tooltip", + }, + { + element: "#tour_step_4", + intro: self.trans("messages.tour_step_4_intro"), + scrollTo: "tooltip", + }, + { + element: "#tour_step_5", + intro: self.trans("messages.tour_step_5_intro"), + scrollTo: "tooltip", + }, + { + element: "#tour_step_6", + intro: self.trans("messages.tour_step_6_intro"), + scrollTo: "tooltip", + }, + { + element: "#tour_step_7", + intro: self.trans("messages.tour_step_7_intro"), + scrollTo: "tooltip", + }, + { + element: "#tour_step_8", + intro: self.trans("messages.tour_step_8_intro"), + scrollTo: "tooltip", + }, + { + element: "#tour_step_9", + intro: self.trans("messages.tour_step_9_intro"), + scrollTo: "tooltip", + }, + ], + }); + + intro.start(); + }, + }, +}; + diff --git a/resources/js/components/FormTab.vue b/resources/js/components/FormTab.vue index f010dfb..fdf19b7 100644 --- a/resources/js/components/FormTab.vue +++ b/resources/js/components/FormTab.vue @@ -1,822 +1,991 @@ diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 578f5bc..2f98656 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -178,6 +178,15 @@ @section('footer')