diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54985c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +#configuration +.env + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +debug +.vscode +.vs/ +.DS_Store diff --git a/app/views/qor/action.tmpl b/app/views/qor/action.tmpl new file mode 100644 index 0000000..2733153 --- /dev/null +++ b/app/views/qor/action.tmpl @@ -0,0 +1,21 @@ +{{$action := .Result}} + +
+ {{render "shared/flashes"}} + {{render "shared/errors"}} + +
+
+ + + {{if $action.Resource}} + {{render_form $action.Resource.NewStruct (edit_sections $action.Resource)}} + {{end}} + +
+ + {{t "qor_admin.form.cancel" "Cancel"}} +
+
+
+
diff --git a/app/views/qor/actions/9.action.tmpl b/app/views/qor/actions/9.action.tmpl new file mode 100644 index 0000000..37e2206 --- /dev/null +++ b/app/views/qor/actions/9.action.tmpl @@ -0,0 +1,12 @@ +{{$context := .}} +{{$result := .Result}} +{{$allowed_actions := (allowed_actions $context.Resource.GetActions $context.Action $result)}} +{{$resource := .Resource}} + +{{if gt (len $allowed_actions) 0 }} +
+ {{range $action := $allowed_actions}} + {{render_with "shared/action_item" (to_map "Action" $action "Result" $result "Context" $context "Resource" $resource)}} + {{end}} +
+{{end}} diff --git a/app/views/qor/actions/header/1.page_title.tmpl b/app/views/qor/actions/header/1.page_title.tmpl new file mode 100644 index 0000000..5b25b9c --- /dev/null +++ b/app/views/qor/actions/header/1.page_title.tmpl @@ -0,0 +1,3 @@ +{{page_title}} + + diff --git a/app/views/qor/actions/header/5.userinfo.tmpl b/app/views/qor/actions/header/5.userinfo.tmpl new file mode 100644 index 0000000..fe1914a --- /dev/null +++ b/app/views/qor/actions/header/5.userinfo.tmpl @@ -0,0 +1,4 @@ +{{if .CurrentUser}} +
+ +{{end}} diff --git a/app/views/qor/actions/header/6.searchbar.tmpl b/app/views/qor/actions/header/6.searchbar.tmpl new file mode 100644 index 0000000..3c5176f --- /dev/null +++ b/app/views/qor/actions/header/6.searchbar.tmpl @@ -0,0 +1,27 @@ +{{if .Resource}} + {{if .Resource.SearchHandler}} + {{ $keyword := .Context.Request.URL.Query.Get "keyword" }} +
+ {{range $key, $values := .Context.Request.URL.Query}} + {{if (and (ne $key "keyword") (ne $key "page"))}} + {{range $value := $values}} + + {{end}} + {{end}} + {{end}} + + +
+ {{end}} +{{end}} diff --git a/app/views/qor/actions/index/5.scope.tmpl b/app/views/qor/actions/index/5.scope.tmpl new file mode 100644 index 0000000..e3a6b04 --- /dev/null +++ b/app/views/qor/actions/index/5.scope.tmpl @@ -0,0 +1,19 @@ +{{$scopes := get_scopes}} +{{$resource := .Resource}} +{{if $scopes}} +
+ {{range $scope := $scopes}} + {{if $scope.Group}} + + {{else}} + {{range $s := $scope.Scopes}} + {{t (printf "%v.scopes.%v" $resource.ToParam $s.Label) $s.Label}} {{if $s.Active}}clear{{end}} + {{end}} + {{end}} + {{end}} +
+{{end}} diff --git a/app/views/qor/actions/index/9.action.tmpl b/app/views/qor/actions/index/9.action.tmpl new file mode 100644 index 0000000..1ce2896 --- /dev/null +++ b/app/views/qor/actions/index/9.action.tmpl @@ -0,0 +1,28 @@ +{{$context := .}} +{{$result := .Result}} +{{$allowed_actions := (allowed_actions $context.Resource.GetActions "batch")}} +{{$resource := .Resource}} + +{{if gt (len $allowed_actions) 0 }} +
+ + +
+ + +
+
+{{end}} + +{{$collection_actions := (allowed_actions $context.Resource.GetActions "collection")}} +{{if gt (len $collection_actions) 0 }} +
+ {{range $action := $collection_actions}} + {{render_with "shared/action_item" (to_map "Action" $action "Result" $result "Context" $context "Resource" $resource "Multiple" true)}} + {{end}} +
+{{end}} diff --git a/app/views/qor/actions/index/9.advanced_filter.tmpl b/app/views/qor/actions/index/9.advanced_filter.tmpl new file mode 100644 index 0000000..f8611c3 --- /dev/null +++ b/app/views/qor/actions/index/9.advanced_filter.tmpl @@ -0,0 +1,41 @@ +{{$filters := get_filters}} +{{if $filters}} +
+ + + +
+{{end}} diff --git a/app/views/qor/assets/fonts/MaterialIcons.woff b/app/views/qor/assets/fonts/MaterialIcons.woff new file mode 100644 index 0000000..76cd97c Binary files /dev/null and b/app/views/qor/assets/fonts/MaterialIcons.woff differ diff --git a/app/views/qor/assets/fonts/Roboto-Black.ttf b/app/views/qor/assets/fonts/Roboto-Black.ttf new file mode 100644 index 0000000..cb905bc Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-Black.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-BlackItalic.ttf b/app/views/qor/assets/fonts/Roboto-BlackItalic.ttf new file mode 100644 index 0000000..3ebdc7d Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-BlackItalic.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-Bold.ttf b/app/views/qor/assets/fonts/Roboto-Bold.ttf new file mode 100644 index 0000000..68822ca Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-Bold.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-BoldItalic.ttf b/app/views/qor/assets/fonts/Roboto-BoldItalic.ttf new file mode 100644 index 0000000..aebf8eb Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-BoldItalic.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-Italic.ttf b/app/views/qor/assets/fonts/Roboto-Italic.ttf new file mode 100644 index 0000000..2041cbc Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-Italic.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-Light.ttf b/app/views/qor/assets/fonts/Roboto-Light.ttf new file mode 100644 index 0000000..aa45340 Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-Light.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-LightItalic.ttf b/app/views/qor/assets/fonts/Roboto-LightItalic.ttf new file mode 100644 index 0000000..a85444f Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-LightItalic.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-Medium.ttf b/app/views/qor/assets/fonts/Roboto-Medium.ttf new file mode 100644 index 0000000..a3c1a1f Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-Medium.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-MediumItalic.ttf b/app/views/qor/assets/fonts/Roboto-MediumItalic.ttf new file mode 100644 index 0000000..b828205 Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-MediumItalic.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-Regular.ttf b/app/views/qor/assets/fonts/Roboto-Regular.ttf new file mode 100644 index 0000000..0e58508 Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-Regular.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-Thin.ttf b/app/views/qor/assets/fonts/Roboto-Thin.ttf new file mode 100644 index 0000000..8779333 Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-Thin.ttf differ diff --git a/app/views/qor/assets/fonts/Roboto-ThinItalic.ttf b/app/views/qor/assets/fonts/Roboto-ThinItalic.ttf new file mode 100644 index 0000000..b79cb26 Binary files /dev/null and b/app/views/qor/assets/fonts/Roboto-ThinItalic.ttf differ diff --git a/app/views/qor/assets/fonts/RobotoCondensed-Bold.ttf b/app/views/qor/assets/fonts/RobotoCondensed-Bold.ttf new file mode 100644 index 0000000..3e06c7c Binary files /dev/null and b/app/views/qor/assets/fonts/RobotoCondensed-Bold.ttf differ diff --git a/app/views/qor/assets/fonts/RobotoCondensed-BoldItalic.ttf b/app/views/qor/assets/fonts/RobotoCondensed-BoldItalic.ttf new file mode 100644 index 0000000..aaf9fe0 Binary files /dev/null and b/app/views/qor/assets/fonts/RobotoCondensed-BoldItalic.ttf differ diff --git a/app/views/qor/assets/fonts/RobotoCondensed-Italic.ttf b/app/views/qor/assets/fonts/RobotoCondensed-Italic.ttf new file mode 100644 index 0000000..d2b611f Binary files /dev/null and b/app/views/qor/assets/fonts/RobotoCondensed-Italic.ttf differ diff --git a/app/views/qor/assets/fonts/RobotoCondensed-Light.ttf b/app/views/qor/assets/fonts/RobotoCondensed-Light.ttf new file mode 100644 index 0000000..d4eb198 Binary files /dev/null and b/app/views/qor/assets/fonts/RobotoCondensed-Light.ttf differ diff --git a/app/views/qor/assets/fonts/RobotoCondensed-LightItalic.ttf b/app/views/qor/assets/fonts/RobotoCondensed-LightItalic.ttf new file mode 100644 index 0000000..a08f3f4 Binary files /dev/null and b/app/views/qor/assets/fonts/RobotoCondensed-LightItalic.ttf differ diff --git a/app/views/qor/assets/fonts/RobotoCondensed-Regular.ttf b/app/views/qor/assets/fonts/RobotoCondensed-Regular.ttf new file mode 100644 index 0000000..b9fc49c Binary files /dev/null and b/app/views/qor/assets/fonts/RobotoCondensed-Regular.ttf differ diff --git a/app/views/qor/assets/fonts/codepoints b/app/views/qor/assets/fonts/codepoints new file mode 100644 index 0000000..3c8b075 --- /dev/null +++ b/app/views/qor/assets/fonts/codepoints @@ -0,0 +1,932 @@ +3d_rotation e84d +ac_unit eb3b +access_alarm e190 +access_alarms e191 +access_time e192 +accessibility e84e +accessible e914 +account_balance e84f +account_balance_wallet e850 +account_box e851 +account_circle e853 +adb e60e +add e145 +add_a_photo e439 +add_alarm e193 +add_alert e003 +add_box e146 +add_circle e147 +add_circle_outline e148 +add_location e567 +add_shopping_cart e854 +add_to_photos e39d +add_to_queue e05c +adjust e39e +airline_seat_flat e630 +airline_seat_flat_angled e631 +airline_seat_individual_suite e632 +airline_seat_legroom_extra e633 +airline_seat_legroom_normal e634 +airline_seat_legroom_reduced e635 +airline_seat_recline_extra e636 +airline_seat_recline_normal e637 +airplanemode_active e195 +airplanemode_inactive e194 +airplay e055 +airport_shuttle eb3c +alarm e855 +alarm_add e856 +alarm_off e857 +alarm_on e858 +album e019 +all_inclusive eb3d +all_out e90b +android e859 +announcement e85a +apps e5c3 +archive e149 +arrow_back e5c4 +arrow_downward e5db +arrow_drop_down e5c5 +arrow_drop_down_circle e5c6 +arrow_drop_up e5c7 +arrow_forward e5c8 +arrow_upward e5d8 +art_track e060 +aspect_ratio e85b +assessment e85c +assignment e85d +assignment_ind e85e +assignment_late e85f +assignment_return e860 +assignment_returned e861 +assignment_turned_in e862 +assistant e39f +assistant_photo e3a0 +attach_file e226 +attach_money e227 +attachment e2bc +audiotrack e3a1 +autorenew e863 +av_timer e01b +backspace e14a +backup e864 +battery_alert e19c +battery_charging_full e1a3 +battery_full e1a4 +battery_std e1a5 +battery_unknown e1a6 +beach_access eb3e +beenhere e52d +block e14b +bluetooth e1a7 +bluetooth_audio e60f +bluetooth_connected e1a8 +bluetooth_disabled e1a9 +bluetooth_searching e1aa +blur_circular e3a2 +blur_linear e3a3 +blur_off e3a4 +blur_on e3a5 +book e865 +bookmark e866 +bookmark_border e867 +border_all e228 +border_bottom e229 +border_clear e22a +border_color e22b +border_horizontal e22c +border_inner e22d +border_left e22e +border_outer e22f +border_right e230 +border_style e231 +border_top e232 +border_vertical e233 +branding_watermark e06b +brightness_1 e3a6 +brightness_2 e3a7 +brightness_3 e3a8 +brightness_4 e3a9 +brightness_5 e3aa +brightness_6 e3ab +brightness_7 e3ac +brightness_auto e1ab +brightness_high e1ac +brightness_low e1ad +brightness_medium e1ae +broken_image e3ad +brush e3ae +bubble_chart e6dd +bug_report e868 +build e869 +burst_mode e43c +business e0af +business_center eb3f +cached e86a +cake e7e9 +call e0b0 +call_end e0b1 +call_made e0b2 +call_merge e0b3 +call_missed e0b4 +call_missed_outgoing e0e4 +call_received e0b5 +call_split e0b6 +call_to_action e06c +camera e3af +camera_alt e3b0 +camera_enhance e8fc +camera_front e3b1 +camera_rear e3b2 +camera_roll e3b3 +cancel e5c9 +card_giftcard e8f6 +card_membership e8f7 +card_travel e8f8 +casino eb40 +cast e307 +cast_connected e308 +center_focus_strong e3b4 +center_focus_weak e3b5 +change_history e86b +chat e0b7 +chat_bubble e0ca +chat_bubble_outline e0cb +check e5ca +check_box e834 +check_box_outline_blank e835 +check_circle e86c +chevron_left e5cb +chevron_right e5cc +child_care eb41 +child_friendly eb42 +chrome_reader_mode e86d +class e86e +clear e14c +clear_all e0b8 +close e5cd +closed_caption e01c +cloud e2bd +cloud_circle e2be +cloud_done e2bf +cloud_download e2c0 +cloud_off e2c1 +cloud_queue e2c2 +cloud_upload e2c3 +code e86f +collections e3b6 +collections_bookmark e431 +color_lens e3b7 +colorize e3b8 +comment e0b9 +compare e3b9 +compare_arrows e915 +computer e30a +confirmation_number e638 +contact_mail e0d0 +contact_phone e0cf +contacts e0ba +content_copy e14d +content_cut e14e +content_paste e14f +control_point e3ba +control_point_duplicate e3bb +copyright e90c +create e150 +create_new_folder e2cc +credit_card e870 +crop e3be +crop_16_9 e3bc +crop_3_2 e3bd +crop_5_4 e3bf +crop_7_5 e3c0 +crop_din e3c1 +crop_free e3c2 +crop_landscape e3c3 +crop_original e3c4 +crop_portrait e3c5 +crop_rotate e437 +crop_square e3c6 +dashboard e871 +data_usage e1af +date_range e916 +dehaze e3c7 +delete e872 +delete_forever e92b +delete_sweep e16c +description e873 +desktop_mac e30b +desktop_windows e30c +details e3c8 +developer_board e30d +developer_mode e1b0 +device_hub e335 +devices e1b1 +devices_other e337 +dialer_sip e0bb +dialpad e0bc +directions e52e +directions_bike e52f +directions_boat e532 +directions_bus e530 +directions_car e531 +directions_railway e534 +directions_run e566 +directions_subway e533 +directions_transit e535 +directions_walk e536 +disc_full e610 +dns e875 +do_not_disturb e612 +do_not_disturb_alt e611 +do_not_disturb_off e643 +do_not_disturb_on e644 +dock e30e +domain e7ee +done e876 +done_all e877 +donut_large e917 +donut_small e918 +drafts e151 +drag_handle e25d +drive_eta e613 +dvr e1b2 +edit e3c9 +edit_location e568 +eject e8fb +email e0be +enhanced_encryption e63f +equalizer e01d +error e000 +error_outline e001 +euro_symbol e926 +ev_station e56d +event e878 +event_available e614 +event_busy e615 +event_note e616 +event_seat e903 +exit_to_app e879 +expand_less e5ce +expand_more e5cf +explicit e01e +explore e87a +exposure e3ca +exposure_neg_1 e3cb +exposure_neg_2 e3cc +exposure_plus_1 e3cd +exposure_plus_2 e3ce +exposure_zero e3cf +extension e87b +face e87c +fast_forward e01f +fast_rewind e020 +favorite e87d +favorite_border e87e +featured_play_list e06d +featured_video e06e +feedback e87f +fiber_dvr e05d +fiber_manual_record e061 +fiber_new e05e +fiber_pin e06a +fiber_smart_record e062 +file_download e2c4 +file_upload e2c6 +filter e3d3 +filter_1 e3d0 +filter_2 e3d1 +filter_3 e3d2 +filter_4 e3d4 +filter_5 e3d5 +filter_6 e3d6 +filter_7 e3d7 +filter_8 e3d8 +filter_9 e3d9 +filter_9_plus e3da +filter_b_and_w e3db +filter_center_focus e3dc +filter_drama e3dd +filter_frames e3de +filter_hdr e3df +filter_list e152 +filter_none e3e0 +filter_tilt_shift e3e2 +filter_vintage e3e3 +find_in_page e880 +find_replace e881 +fingerprint e90d +first_page e5dc +fitness_center eb43 +flag e153 +flare e3e4 +flash_auto e3e5 +flash_off e3e6 +flash_on e3e7 +flight e539 +flight_land e904 +flight_takeoff e905 +flip e3e8 +flip_to_back e882 +flip_to_front e883 +folder e2c7 +folder_open e2c8 +folder_shared e2c9 +folder_special e617 +font_download e167 +format_align_center e234 +format_align_justify e235 +format_align_left e236 +format_align_right e237 +format_bold e238 +format_clear e239 +format_color_fill e23a +format_color_reset e23b +format_color_text e23c +format_indent_decrease e23d +format_indent_increase e23e +format_italic e23f +format_line_spacing e240 +format_list_bulleted e241 +format_list_numbered e242 +format_paint e243 +format_quote e244 +format_shapes e25e +format_size e245 +format_strikethrough e246 +format_textdirection_l_to_r e247 +format_textdirection_r_to_l e248 +format_underlined e249 +forum e0bf +forward e154 +forward_10 e056 +forward_30 e057 +forward_5 e058 +free_breakfast eb44 +fullscreen e5d0 +fullscreen_exit e5d1 +functions e24a +g_translate e927 +gamepad e30f +games e021 +gavel e90e +gesture e155 +get_app e884 +gif e908 +golf_course eb45 +gps_fixed e1b3 +gps_not_fixed e1b4 +gps_off e1b5 +grade e885 +gradient e3e9 +grain e3ea +graphic_eq e1b8 +grid_off e3eb +grid_on e3ec +group e7ef +group_add e7f0 +group_work e886 +hd e052 +hdr_off e3ed +hdr_on e3ee +hdr_strong e3f1 +hdr_weak e3f2 +headset e310 +headset_mic e311 +healing e3f3 +hearing e023 +help e887 +help_outline e8fd +high_quality e024 +highlight e25f +highlight_off e888 +history e889 +home e88a +hot_tub eb46 +hotel e53a +hourglass_empty e88b +hourglass_full e88c +http e902 +https e88d +image e3f4 +image_aspect_ratio e3f5 +import_contacts e0e0 +import_export e0c3 +important_devices e912 +inbox e156 +indeterminate_check_box e909 +info e88e +info_outline e88f +input e890 +insert_chart e24b +insert_comment e24c +insert_drive_file e24d +insert_emoticon e24e +insert_invitation e24f +insert_link e250 +insert_photo e251 +invert_colors e891 +invert_colors_off e0c4 +iso e3f6 +keyboard e312 +keyboard_arrow_down e313 +keyboard_arrow_left e314 +keyboard_arrow_right e315 +keyboard_arrow_up e316 +keyboard_backspace e317 +keyboard_capslock e318 +keyboard_hide e31a +keyboard_return e31b +keyboard_tab e31c +keyboard_voice e31d +kitchen eb47 +label e892 +label_outline e893 +landscape e3f7 +language e894 +laptop e31e +laptop_chromebook e31f +laptop_mac e320 +laptop_windows e321 +last_page e5dd +launch e895 +layers e53b +layers_clear e53c +leak_add e3f8 +leak_remove e3f9 +lens e3fa +library_add e02e +library_books e02f +library_music e030 +lightbulb_outline e90f +line_style e919 +line_weight e91a +linear_scale e260 +link e157 +linked_camera e438 +list e896 +live_help e0c6 +live_tv e639 +local_activity e53f +local_airport e53d +local_atm e53e +local_bar e540 +local_cafe e541 +local_car_wash e542 +local_convenience_store e543 +local_dining e556 +local_drink e544 +local_florist e545 +local_gas_station e546 +local_grocery_store e547 +local_hospital e548 +local_hotel e549 +local_laundry_service e54a +local_library e54b +local_mall e54c +local_movies e54d +local_offer e54e +local_parking e54f +local_pharmacy e550 +local_phone e551 +local_pizza e552 +local_play e553 +local_post_office e554 +local_printshop e555 +local_see e557 +local_shipping e558 +local_taxi e559 +location_city e7f1 +location_disabled e1b6 +location_off e0c7 +location_on e0c8 +location_searching e1b7 +lock e897 +lock_open e898 +lock_outline e899 +looks e3fc +looks_3 e3fb +looks_4 e3fd +looks_5 e3fe +looks_6 e3ff +looks_one e400 +looks_two e401 +loop e028 +loupe e402 +low_priority e16d +loyalty e89a +mail e158 +mail_outline e0e1 +map e55b +markunread e159 +markunread_mailbox e89b +memory e322 +menu e5d2 +merge_type e252 +message e0c9 +mic e029 +mic_none e02a +mic_off e02b +mms e618 +mode_comment e253 +mode_edit e254 +monetization_on e263 +money_off e25c +monochrome_photos e403 +mood e7f2 +mood_bad e7f3 +more e619 +more_horiz e5d3 +more_vert e5d4 +motorcycle e91b +mouse e323 +move_to_inbox e168 +movie e02c +movie_creation e404 +movie_filter e43a +multiline_chart e6df +music_note e405 +music_video e063 +my_location e55c +nature e406 +nature_people e407 +navigate_before e408 +navigate_next e409 +navigation e55d +near_me e569 +network_cell e1b9 +network_check e640 +network_locked e61a +network_wifi e1ba +new_releases e031 +next_week e16a +nfc e1bb +no_encryption e641 +no_sim e0cc +not_interested e033 +note e06f +note_add e89c +notifications e7f4 +notifications_active e7f7 +notifications_none e7f5 +notifications_off e7f6 +notifications_paused e7f8 +offline_pin e90a +ondemand_video e63a +opacity e91c +open_in_browser e89d +open_in_new e89e +open_with e89f +pages e7f9 +pageview e8a0 +palette e40a +pan_tool e925 +panorama e40b +panorama_fish_eye e40c +panorama_horizontal e40d +panorama_vertical e40e +panorama_wide_angle e40f +party_mode e7fa +pause e034 +pause_circle_filled e035 +pause_circle_outline e036 +payment e8a1 +people e7fb +people_outline e7fc +perm_camera_mic e8a2 +perm_contact_calendar e8a3 +perm_data_setting e8a4 +perm_device_information e8a5 +perm_identity e8a6 +perm_media e8a7 +perm_phone_msg e8a8 +perm_scan_wifi e8a9 +person e7fd +person_add e7fe +person_outline e7ff +person_pin e55a +person_pin_circle e56a +personal_video e63b +pets e91d +phone e0cd +phone_android e324 +phone_bluetooth_speaker e61b +phone_forwarded e61c +phone_in_talk e61d +phone_iphone e325 +phone_locked e61e +phone_missed e61f +phone_paused e620 +phonelink e326 +phonelink_erase e0db +phonelink_lock e0dc +phonelink_off e327 +phonelink_ring e0dd +phonelink_setup e0de +photo e410 +photo_album e411 +photo_camera e412 +photo_filter e43b +photo_library e413 +photo_size_select_actual e432 +photo_size_select_large e433 +photo_size_select_small e434 +picture_as_pdf e415 +picture_in_picture e8aa +picture_in_picture_alt e911 +pie_chart e6c4 +pie_chart_outlined e6c5 +pin_drop e55e +place e55f +play_arrow e037 +play_circle_filled e038 +play_circle_outline e039 +play_for_work e906 +playlist_add e03b +playlist_add_check e065 +playlist_play e05f +plus_one e800 +poll e801 +polymer e8ab +pool eb48 +portable_wifi_off e0ce +portrait e416 +power e63c +power_input e336 +power_settings_new e8ac +pregnant_woman e91e +present_to_all e0df +print e8ad +priority_high e645 +public e80b +publish e255 +query_builder e8ae +question_answer e8af +queue e03c +queue_music e03d +queue_play_next e066 +radio e03e +radio_button_checked e837 +radio_button_unchecked e836 +rate_review e560 +receipt e8b0 +recent_actors e03f +record_voice_over e91f +redeem e8b1 +redo e15a +refresh e5d5 +remove e15b +remove_circle e15c +remove_circle_outline e15d +remove_from_queue e067 +remove_red_eye e417 +remove_shopping_cart e928 +reorder e8fe +repeat e040 +repeat_one e041 +replay e042 +replay_10 e059 +replay_30 e05a +replay_5 e05b +reply e15e +reply_all e15f +report e160 +report_problem e8b2 +restaurant e56c +restaurant_menu e561 +restore e8b3 +restore_page e929 +ring_volume e0d1 +room e8b4 +room_service eb49 +rotate_90_degrees_ccw e418 +rotate_left e419 +rotate_right e41a +rounded_corner e920 +router e328 +rowing e921 +rss_feed e0e5 +rv_hookup e642 +satellite e562 +save e161 +scanner e329 +schedule e8b5 +school e80c +screen_lock_landscape e1be +screen_lock_portrait e1bf +screen_lock_rotation e1c0 +screen_rotation e1c1 +screen_share e0e2 +sd_card e623 +sd_storage e1c2 +search e8b6 +security e32a +select_all e162 +send e163 +sentiment_dissatisfied e811 +sentiment_neutral e812 +sentiment_satisfied e813 +sentiment_very_dissatisfied e814 +sentiment_very_satisfied e815 +settings e8b8 +settings_applications e8b9 +settings_backup_restore e8ba +settings_bluetooth e8bb +settings_brightness e8bd +settings_cell e8bc +settings_ethernet e8be +settings_input_antenna e8bf +settings_input_component e8c0 +settings_input_composite e8c1 +settings_input_hdmi e8c2 +settings_input_svideo e8c3 +settings_overscan e8c4 +settings_phone e8c5 +settings_power e8c6 +settings_remote e8c7 +settings_system_daydream e1c3 +settings_voice e8c8 +share e80d +shop e8c9 +shop_two e8ca +shopping_basket e8cb +shopping_cart e8cc +short_text e261 +show_chart e6e1 +shuffle e043 +signal_cellular_4_bar e1c8 +signal_cellular_connected_no_internet_4_bar e1cd +signal_cellular_no_sim e1ce +signal_cellular_null e1cf +signal_cellular_off e1d0 +signal_wifi_4_bar e1d8 +signal_wifi_4_bar_lock e1d9 +signal_wifi_off e1da +sim_card e32b +sim_card_alert e624 +skip_next e044 +skip_previous e045 +slideshow e41b +slow_motion_video e068 +smartphone e32c +smoke_free eb4a +smoking_rooms eb4b +sms e625 +sms_failed e626 +snooze e046 +sort e164 +sort_by_alpha e053 +spa eb4c +space_bar e256 +speaker e32d +speaker_group e32e +speaker_notes e8cd +speaker_notes_off e92a +speaker_phone e0d2 +spellcheck e8ce +star e838 +star_border e83a +star_half e839 +stars e8d0 +stay_current_landscape e0d3 +stay_current_portrait e0d4 +stay_primary_landscape e0d5 +stay_primary_portrait e0d6 +stop e047 +stop_screen_share e0e3 +storage e1db +store e8d1 +store_mall_directory e563 +straighten e41c +streetview e56e +strikethrough_s e257 +style e41d +subdirectory_arrow_left e5d9 +subdirectory_arrow_right e5da +subject e8d2 +subscriptions e064 +subtitles e048 +subway e56f +supervisor_account e8d3 +surround_sound e049 +swap_calls e0d7 +swap_horiz e8d4 +swap_vert e8d5 +swap_vertical_circle e8d6 +switch_camera e41e +switch_video e41f +sync e627 +sync_disabled e628 +sync_problem e629 +system_update e62a +system_update_alt e8d7 +tab e8d8 +tab_unselected e8d9 +tablet e32f +tablet_android e330 +tablet_mac e331 +tag_faces e420 +tap_and_play e62b +terrain e564 +text_fields e262 +text_format e165 +textsms e0d8 +texture e421 +theaters e8da +thumb_down e8db +thumb_up e8dc +thumbs_up_down e8dd +time_to_leave e62c +timelapse e422 +timeline e922 +timer e425 +timer_10 e423 +timer_3 e424 +timer_off e426 +title e264 +toc e8de +today e8df +toll e8e0 +tonality e427 +touch_app e913 +toys e332 +track_changes e8e1 +traffic e565 +train e570 +tram e571 +transfer_within_a_station e572 +transform e428 +translate e8e2 +trending_down e8e3 +trending_flat e8e4 +trending_up e8e5 +tune e429 +turned_in e8e6 +turned_in_not e8e7 +tv e333 +unarchive e169 +undo e166 +unfold_less e5d6 +unfold_more e5d7 +update e923 +usb e1e0 +verified_user e8e8 +vertical_align_bottom e258 +vertical_align_center e259 +vertical_align_top e25a +vibration e62d +video_call e070 +video_label e071 +video_library e04a +videocam e04b +videocam_off e04c +videogame_asset e338 +view_agenda e8e9 +view_array e8ea +view_carousel e8eb +view_column e8ec +view_comfy e42a +view_compact e42b +view_day e8ed +view_headline e8ee +view_list e8ef +view_module e8f0 +view_quilt e8f1 +view_stream e8f2 +view_week e8f3 +vignette e435 +visibility e8f4 +visibility_off e8f5 +voice_chat e62e +voicemail e0d9 +volume_down e04d +volume_mute e04e +volume_off e04f +volume_up e050 +vpn_key e0da +vpn_lock e62f +wallpaper e1bc +warning e002 +watch e334 +watch_later e924 +wb_auto e42c +wb_cloudy e42d +wb_incandescent e42e +wb_iridescent e436 +wb_sunny e430 +wc e63d +web e051 +web_asset e069 +weekend e16b +whatshot e80e +widgets e1bd +wifi e63e +wifi_lock e1e1 +wifi_tethering e1e2 +work e8f9 +wrap_text e25b +youtube_searched_for e8fa +zoom_in e8ff +zoom_out e900 +zoom_out_map e56b diff --git a/app/views/qor/assets/images/bg-transparents.png b/app/views/qor/assets/images/bg-transparents.png new file mode 100644 index 0000000..7d8639d Binary files /dev/null and b/app/views/qor/assets/images/bg-transparents.png differ diff --git a/app/views/qor/assets/images/icon_trangle.svg b/app/views/qor/assets/images/icon_trangle.svg new file mode 100644 index 0000000..d725637 --- /dev/null +++ b/app/views/qor/assets/images/icon_trangle.svg @@ -0,0 +1,10 @@ + + + + Shape + Created with Sketch Beta. + + + + + \ No newline at end of file diff --git a/app/views/qor/assets/images/logo.png b/app/views/qor/assets/images/logo.png new file mode 100644 index 0000000..37da102 Binary files /dev/null and b/app/views/qor/assets/images/logo.png differ diff --git a/app/views/qor/assets/javascripts/app.js b/app/views/qor/assets/javascripts/app.js new file mode 100644 index 0000000..f37769b --- /dev/null +++ b/app/views/qor/assets/javascripts/app.js @@ -0,0 +1 @@ +"use strict";$(function(){$(document).on("click.qor.alert",'[data-dismiss="alert"]',function(){$(this).closest(".qor-alert").removeClass("qor-alert__active")}),setTimeout(function(){$('.qor-alert[data-dismissible="true"]').removeClass("qor-alert__active")},5e3)}),$(function(){$(document).on("click",".qor-dialog--global-search",function(e){e.stopPropagation(),$(e.target).parents(".qor-dialog-content").length||$(e.target).is(".qor-dialog-content")||$(".qor-dialog--global-search").remove()}),$(document).on("click",".qor-global-search--show",function(e){e.preventDefault();var a=$(this).data(),o=window.Mustache.render('',a);$("body").append(o),window.componentHandler.upgradeElement(document.getElementById("global-search-textfield")),$("#globalSearch").focus()})}),$(function(){var l=[],s="qoradmin_menu_status",e=localStorage.getItem(s);e&&e.length&&(l=e.split(",")),$(".qor-menu-container").on("click","> ul > li > a",function(){var e=$(this),a=e.parent(),o=e.next("ul"),t=a.attr("qor-icon-name");o.length&&(o.hasClass("in")?(l.push(t),a.removeClass("is-expanded"),o.one("transitionend",function(){o.removeClass("collapsing in")}).addClass("collapsing").height(0)):(l=_.without(l,t),a.addClass("is-expanded"),o.one("transitionend",function(){o.removeClass("collapsing")}).addClass("collapsing in").height(o.prop("scrollHeight"))),localStorage.setItem(s,l))}).find("> ul > li > a").each(function(){var e=$(this),a=e.parent(),o=e.next("ul"),t=a.attr("qor-icon-name");o.length&&(o.addClass("collapse"),a.addClass("has-menu"),-1!=l.indexOf(t)?o.height(0):(a.addClass("is-expanded"),o.addClass("in").height(o.prop("scrollHeight"))))});var a=$(".qor-page > .qor-page__header"),o=$(".qor-page > .qor-page__body"),t=a.find(".qor-page-subnav__header").length?96:48;a.length&&(a.height()>t&&o.css("padding-top",a.height()),$(".qor-page").addClass("has-header"),$("header.mdl-layout__header").addClass("has-action"))}),$(function(){$(".qor-mobile--show-actions").on("click",function(){$(".qor-page__header").toggleClass("actions-show")})}),$(function(){var p,m,q=$("body"),f="is-selected",b=function(){return q.hasClass("qor-bottomsheets-open")};function _(e){$("[data-url]").removeClass(f),e&&e.length&&e.addClass(f)}q.qorBottomSheets(),q.qorSlideout(),p=q.data("qor.slideout"),m=q.data("qor.bottomsheets"),$(document).on("click.qor.openUrl","[data-url]",function(e){var a,o=$(this),t=$(e.target),l=o.hasClass("qor-button--new"),s=o.hasClass("qor-button--edit"),n=(o.is(".qor-table tr[data-url]")||o.closest(".qor-js-table").length)&&!o.closest(".qor-slideout").length,r=o.data(),i=r.openType,d=o.parents(".qor-theme-slideout").length,c=o.closest(".qor-slideout").length,h=o.hasClass("qor-action-button")||o.hasClass("qor-action--button");if(e.stopPropagation(),!(o.data("ajax-form")||t.closest(".qor-table--bulking").length||t.closest(".qor-button--actions").length||!t.data("url")&&t.is("a")||n&&b()))if("window"!=i){var u,g;if("new_window"!=i)return h&&(u=$(".qor-js-table tbody").find(".mdl-checkbox__input:checked"),g=[],(a=!!u.length&&(u.each(function(){g.push($(this).closest("tr").data("primary-key"))}),g))&&(r=$.extend({},r,{actionData:a}))),r.$target=t,r.method&&"GET"!=r.method.toUpperCase()?void 0:("bottomsheet"!=i&&!h||"slideout"==i?"slideout"==i||n||l&&!b()||s?"slideout"==i||d?o.hasClass(f)?(p.hide(),_()):(p.open(r),_(o)):window.location.href=r.url:q.hasClass("qor-slideout-open")||l&&b()?m.open(r):d?p.open(r):m.open(r):h&&!a&&o.closest('[data-toggle="qor.action.bulk"]').length&&!c?window.QOR.qorConfirm(r.errorNoItem):m.open(r),!1);window.open(r.url,"_blank")}else window.location.href=r.url})}),$(function(){var l=window.location;$(".qor-search").each(function(){var e=$(this),a=e.find(".qor-search__input"),o=e.find(".qor-search__clear"),t=!!a.val();e.closest(".qor-page__header").addClass("has-search"),$("header.mdl-layout__header").addClass("has-search"),o.on("click",function(){a.val()||t?"?"==l.search.replace(new RegExp(a.attr("name")+"\\=?\\w*"),"")?l.href=l.href.split("?")[0]:l.search=l.search.replace(new RegExp(a.attr("name")+"\\=?\\w*"),""):e.removeClass("is-dirty")})})}); \ No newline at end of file diff --git a/app/views/qor/assets/javascripts/app/alert.js b/app/views/qor/assets/javascripts/app/alert.js new file mode 100644 index 0000000..d1563af --- /dev/null +++ b/app/views/qor/assets/javascripts/app/alert.js @@ -0,0 +1,13 @@ +$(function() { + 'use strict'; + + $(document).on('click.qor.alert', '[data-dismiss="alert"]', function() { + $(this) + .closest('.qor-alert') + .removeClass('qor-alert__active'); + }); + + setTimeout(function() { + $('.qor-alert[data-dismissible="true"]').removeClass('qor-alert__active'); + }, 5000); +}); diff --git a/app/views/qor/assets/javascripts/app/global-search.js b/app/views/qor/assets/javascripts/app/global-search.js new file mode 100644 index 0000000..a48c241 --- /dev/null +++ b/app/views/qor/assets/javascripts/app/global-search.js @@ -0,0 +1,36 @@ +$(function () { + + 'use strict'; + + var modal = ( + '' + ); + + $(document).on('click', '.qor-dialog--global-search', function(e){ + e.stopPropagation(); + if (!$(e.target).parents('.qor-dialog-content').length && !$(e.target).is('.qor-dialog-content')){ + $('.qor-dialog--global-search').remove(); + } + }); + + $(document).on('click', '.qor-global-search--show', function(e){ + e.preventDefault(); + + var data = $(this).data(); + var modalHTML = window.Mustache.render(modal, data); + + $('body').append(modalHTML); + window.componentHandler.upgradeElement(document.getElementById('global-search-textfield')); + $('#globalSearch').focus(); + + }); +}); diff --git a/app/views/qor/assets/javascripts/app/menu.js b/app/views/qor/assets/javascripts/app/menu.js new file mode 100644 index 0000000..765f994 --- /dev/null +++ b/app/views/qor/assets/javascripts/app/menu.js @@ -0,0 +1,80 @@ +$(function() { + 'use strict'; + + let menuDatas = [], + storageName = 'qoradmin_menu_status', + lastMenuStatus = localStorage.getItem(storageName); + + if (lastMenuStatus && lastMenuStatus.length) { + menuDatas = lastMenuStatus.split(','); + } + + $('.qor-menu-container') + .on('click', '> ul > li > a', function() { + let $this = $(this), + $li = $this.parent(), + $ul = $this.next('ul'), + menuName = $li.attr('qor-icon-name'); + + if (!$ul.length) { + return; + } + + if ($ul.hasClass('in')) { + menuDatas.push(menuName); + + $li.removeClass('is-expanded'); + $ul + .one('transitionend', function() { + $ul.removeClass('collapsing in'); + }) + .addClass('collapsing') + .height(0); + } else { + menuDatas = _.without(menuDatas, menuName); + + $li.addClass('is-expanded'); + $ul + .one('transitionend', function() { + $ul.removeClass('collapsing'); + }) + .addClass('collapsing in') + .height($ul.prop('scrollHeight')); + } + localStorage.setItem(storageName, menuDatas); + }) + .find('> ul > li > a') + .each(function() { + let $this = $(this), + $li = $this.parent(), + $ul = $this.next('ul'), + menuName = $li.attr('qor-icon-name'); + + if (!$ul.length) { + return; + } + + $ul.addClass('collapse'); + $li.addClass('has-menu'); + + if (menuDatas.indexOf(menuName) != -1) { + $ul.height(0); + } else { + $li.addClass('is-expanded'); + $ul.addClass('in').height($ul.prop('scrollHeight')); + } + }); + + let $pageHeader = $('.qor-page > .qor-page__header'), + $pageBody = $('.qor-page > .qor-page__body'), + triggerHeight = $pageHeader.find('.qor-page-subnav__header').length ? 96 : 48; + + if ($pageHeader.length) { + if ($pageHeader.height() > triggerHeight) { + $pageBody.css('padding-top', $pageHeader.height()); + } + + $('.qor-page').addClass('has-header'); + $('header.mdl-layout__header').addClass('has-action'); + } +}); diff --git a/app/views/qor/assets/javascripts/app/mobile.js b/app/views/qor/assets/javascripts/app/mobile.js new file mode 100644 index 0000000..572fdf3 --- /dev/null +++ b/app/views/qor/assets/javascripts/app/mobile.js @@ -0,0 +1,5 @@ +$(function () { + $('.qor-mobile--show-actions').on('click', function () { + $('.qor-page__header').toggleClass('actions-show'); + }); +}); diff --git a/app/views/qor/assets/javascripts/app/open-url.js b/app/views/qor/assets/javascripts/app/open-url.js new file mode 100644 index 0000000..a98ad67 --- /dev/null +++ b/app/views/qor/assets/javascripts/app/open-url.js @@ -0,0 +1,162 @@ +$(function() { + "use strict"; + + let $body = $("body"), + Slideout, + BottomSheets, + CLASS_IS_SELECTED = "is-selected", + isSlideoutOpened = function() { + return $body.hasClass("qor-slideout-open"); + }, + isBottomsheetsOpened = function() { + return $body.hasClass("qor-bottomsheets-open"); + }; + + $body.qorBottomSheets(); + $body.qorSlideout(); + + Slideout = $body.data("qor.slideout"); + BottomSheets = $body.data("qor.bottomsheets"); + + function toggleSelectedCss(ele) { + $("[data-url]").removeClass(CLASS_IS_SELECTED); + ele && ele.length && ele.addClass(CLASS_IS_SELECTED); + } + + function collectSelectID() { + let $checked = $(".qor-js-table tbody").find( + ".mdl-checkbox__input:checked" + ), + IDs = []; + + if (!$checked.length) { + return false; + } + + $checked.each(function() { + IDs.push( + $(this) + .closest("tr") + .data("primary-key") + ); + }); + + return IDs; + } + + $(document).on("click.qor.openUrl", "[data-url]", function(e) { + let $this = $(this), + $target = $(e.target), + isNewButton = $this.hasClass("qor-button--new"), + isEditButton = $this.hasClass("qor-button--edit"), + isInTable = + ($this.is(".qor-table tr[data-url]") || + $this.closest(".qor-js-table").length) && + !$this.closest(".qor-slideout").length, // if table is in slideout, will open bottom sheet + openData = $this.data(), + actionData, + openType = openData.openType, + hasSlideoutTheme = $this.parents(".qor-theme-slideout").length, + isInSlideout = $this.closest(".qor-slideout").length, + isActionButton = + $this.hasClass("qor-action-button") || + $this.hasClass("qor-action--button"); + + e.stopPropagation(); + + // if clicking item's menu actions + if ( + $this.data("ajax-form") || + $target.closest(".qor-table--bulking").length || + $target.closest(".qor-button--actions").length || + (!$target.data("url") && $target.is("a")) || + (isInTable && isBottomsheetsOpened()) + ) { + return; + } + + if (openType == "window") { + window.location.href = openData.url; + return; + } + + if (openType == "new_window") { + window.open(openData.url, "_blank"); + return; + } + + if (isActionButton) { + actionData = collectSelectID(); + if (actionData) { + openData = $.extend({}, openData, { + actionData: actionData + }); + } + } + + openData.$target = $target; + + if (!openData.method || openData.method.toUpperCase() == "GET") { + // Open in BottmSheet: is action button, open type is bottom-sheet + // is action button but opentype == slideout, should open in slideout\ + // open type is No.1 priority + + if ( + (openType == "bottomsheet" || isActionButton) && + openType != "slideout" + ) { + // if is bulk action and no item selected + if ( + isActionButton && + !actionData && + $this.closest('[data-toggle="qor.action.bulk"]').length && + !isInSlideout + ) { + window.QOR.qorConfirm(openData.errorNoItem); + return false; + } + + BottomSheets.open(openData); + return false; + } + + // Slideout or New Page: table items, new button, edit button + if ( + openType == "slideout" || + isInTable || + (isNewButton && !isBottomsheetsOpened()) || + isEditButton + ) { + if (openType == "slideout" || hasSlideoutTheme) { + if ($this.hasClass(CLASS_IS_SELECTED)) { + Slideout.hide(); + toggleSelectedCss(); + return false; + } else { + Slideout.open(openData); + toggleSelectedCss($this); + return false; + } + } else { + window.location.href = openData.url; + return false; + } + } + + // Open in BottmSheet: slideout is opened or openType is Bottom Sheet + if (isSlideoutOpened() || (isNewButton && isBottomsheetsOpened())) { + BottomSheets.open(openData); + return false; + } + + // Other clicks + if (hasSlideoutTheme) { + Slideout.open(openData); + return false; + } else { + BottomSheets.open(openData); + return false; + } + } + }); +}); diff --git a/app/views/qor/assets/javascripts/app/search.js b/app/views/qor/assets/javascripts/app/search.js new file mode 100644 index 0000000..e5070bc --- /dev/null +++ b/app/views/qor/assets/javascripts/app/search.js @@ -0,0 +1,33 @@ +$(function () { + + 'use strict'; + + var location = window.location; + + $('.qor-search').each(function () { + var $this = $(this); + var $input = $this.find('.qor-search__input'); + var $clear = $this.find('.qor-search__clear'); + var isSearched = !!$input.val(); + + var emptySearch = function () { + var search = location.search.replace(new RegExp($input.attr('name') + '\\=?\\w*'), ''); + if (search == '?'){ + location.href = location.href.split('?')[0]; + } else { + location.search = location.search.replace(new RegExp($input.attr('name') + '\\=?\\w*'), ''); + } + }; + + $this.closest('.qor-page__header').addClass('has-search'); + $('header.mdl-layout__header').addClass('has-search'); + + $clear.on('click', function () { + if ($input.val() || isSearched) { + emptySearch(); + } else { + $this.removeClass('is-dirty'); + } + }); + }); +}); diff --git a/app/views/qor/assets/javascripts/datetimepicker.js b/app/views/qor/assets/javascripts/datetimepicker.js new file mode 100644 index 0000000..5cf8a0c --- /dev/null +++ b/app/views/qor/assets/javascripts/datetimepicker.js @@ -0,0 +1,5 @@ +!function(a){"object"==typeof exports&&exports&&"object"==typeof module&&module&&module.exports===exports?a(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function b(a){var b=a[0];return b.offsetWidth>0&&b.offsetHeight>0}function c(b){if(b.minTime&&(b.minTime=t(b.minTime)),b.maxTime&&(b.maxTime=t(b.maxTime)),b.durationTime&&"function"!=typeof b.durationTime&&(b.durationTime=t(b.durationTime)),"now"==b.scrollDefault)b.scrollDefault=function(){return b.roundingFunction(t(new Date),b)};else if(b.scrollDefault&&"function"!=typeof b.scrollDefault){var c=b.scrollDefault;b.scrollDefault=function(){return b.roundingFunction(t(c),b)}}else b.minTime&&(b.scrollDefault=function(){return b.roundingFunction(b.minTime,b)});if("string"===a.type(b.timeFormat)&&b.timeFormat.match(/[gh]/)&&(b._twelveHourTime=!0),b.showOnFocus===!1&&-1!=b.showOn.indexOf("focus")&&b.showOn.splice(b.showOn.indexOf("focus"),1),b.disableTimeRanges.length>0){for(var d in b.disableTimeRanges)b.disableTimeRanges[d]=[t(b.disableTimeRanges[d][0]),t(b.disableTimeRanges[d][1])];b.disableTimeRanges=b.disableTimeRanges.sort(function(a,b){return a[0]-b[0]});for(var d=b.disableTimeRanges.length-1;d>0;d--)b.disableTimeRanges[d][0]<=b.disableTimeRanges[d-1][1]&&(b.disableTimeRanges[d-1]=[Math.min(b.disableTimeRanges[d][0],b.disableTimeRanges[d-1][0]),Math.max(b.disableTimeRanges[d][1],b.disableTimeRanges[d-1][1])],b.disableTimeRanges.splice(d,1))}return b}function d(b){var c=b.data("timepicker-settings"),d=b.data("timepicker-list");if(d&&d.length&&(d.remove(),b.data("timepicker-list",!1)),c.useSelect){d=a("')})},u.plugin=function(n){return this.each(function(){var t,e=h(this),i=e.data(o);i||e.data(o,i=new u(this,n)),"string"==typeof n&&h.isFunction(t=i[n])&&t.call(i)})},h(function(){var e={},i='[data-toggle="qor.action.bulk"]';h(i).length||h(document).on(n,r,function(t){return(new u).actionSubmit(h(t.target)),!1}),h(document).on("disable.qor.action",function(t){u.plugin.call(h(i,t.target),"destroy")}).on(t,function(t){u.plugin.call(h(i,t.target),e)}).triggerHandler(t)}),u}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(a){var l=window.location,r=window.QOR,o="qor.advancedsearch",t="enable."+o,e="click."+o;function s(t,e){this.$element=a(t),this.options=a.extend({},s.DEFAULTS,a.isPlainObject(e)&&e),this.init()}return s.prototype={constructor:s,init:function(){this.$form=this.$element.find("form"),this.$modal=a(s.MODAL).appendTo("body"),this.bind()},bind:function(){this.$element.on("submit.qor.advancedsearch","form",this.submit.bind(this)).on(e,".qor-advanced-filter__save",this.showSaveFilter.bind(this)).on(e,".qor-advanced-filter__toggle",this.toggleFilterContent).on(e,".qor-advanced-filter__close",this.closeFilter).on(e,".qor-advanced-filter__delete",this.deleteSavedFilter),this.$modal.on("shown.qor.modal",this.start.bind(this))},closeFilter:function(){a(".qor-advanced-filter__dropdown").hide()},toggleFilterContent:function(t){a(t.target).closest(".qor-advanced-filter__toggle").parent().find(">[advanced-search-toggle]").toggle()},showSaveFilter:function(){this.$modal.qorModal("show")},deleteSavedFilter:function(t){var e=a(t.target).closest(".qor-advanced-filter__delete"),i=e.closest(".qor-advanced-filter__savedfilter"),n=e.data("filter-name"),o=l.pathname;return r.qorConfirm({confirm:"Are you sure you want to delete this saved filter?"},function(t){t&&a.get(o,a.param({delete_saved_filter:n})).done(function(){e.closest("li").remove(),0===i.find("li").length&&i.remove()}).fail(function(){r.qorConfirm("Server error, please try again!")})}),!1},start:function(){this.$modal.trigger("enable.qor.material").on(e,".qor-advanced-filter__savefilter",this.saveFilter.bind(this))},saveFilter:function(){var t=this.$modal.find("#qor-advanced-filter__savename").val();t&&this.$form.prepend('')).submit()},submit:function(){var t,e=this.$form,i=e.find("input[name],select[name]"),n=[],o=e.closest(".qor-bottomsheets"),r=e.serialize();if(i.each(function(){n.push(a(this).attr("name"))}),t=function(t){var e,i,n=decodeURIComponent(l.search.substr(1)).split("&"),o={};if(1==n.length&&""==n[0])return!1;for(i in n)""!==n[i]&&(e=n[i].split("="),o[e[0]]=e[1]);return t.forEach(function(t){delete o[t]}),o}(n),!a.isEmptyObject(t))for(var s in t)t.hasOwnProperty(s)&&e.prepend('\n
\n
\n

Save advanced filter

\n
\n
\n \n
\n \n \n
\n\n
\n
\n Save This Filter\n Cancel\n
\n
\n \n
\n
\n ',s.plugin=function(n){return this.each(function(){var t,e=a(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new s(this,n))}"string"==typeof n&&a.isFunction(t=i[n])&&t.apply(i)})},a(function(){var e='[data-toggle="qor.advancedsearch"]';a(document).on("disable.qor.advancedsearch",function(t){s.plugin.call(a(e,t.target),"destroy")}).on(t,function(t){s.plugin.call(a(e,t.target),void 0)}).triggerHandler(t)}),s}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(o){var r="qor.autoheight",t="enable."+r;function s(t,e){this.$element=o(t),this.options=o.extend({},s.DEFAULTS,o.isPlainObject(e)&&e),this.init()}return s.prototype={constructor:s,init:function(){var t=this.$element;this.paddingTop=parseInt(t.css("padding-top"),10),this.paddingBottom=parseInt(t.css("padding-bottom"),10),this.resize(),this.bind()},bind:function(){this.$element.on("input",o.proxy(this.resize,this))},unbind:function(){this.$element.off("input",this.resize)},resize:function(){var t=this.$element,e=t.prop("scrollHeight");e?t.height("auto").height(e-this.paddingTop-this.paddingBottom):t.height("40px")},destroy:function(){this.unbind(),this.$element.removeData(r)}},s.DEFAULTS={},s.plugin=function(n){return this.each(function(){var t,e=o(this),i=e.data(r);if(!i){if(/destroy/.test(n))return;e.data(r,i=new s(this,n))}"string"==typeof n&&o.isFunction(t=i[n])&&t.apply(i)})},o(function(){var e="textarea.qor-js-autoheight";o(document).on("disable.qor.autoheight",function(t){s.plugin.call(o(e,t.target),"destroy")}).on(t,function(t){s.plugin.call(o(e,t.target))}).triggerHandler(t)}),s}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(b){var o=window._,n=window.FormData,i=window.QOR_Translations,r="qor.bottomsheets",t="click."+r,e="submit."+r,v="qor-bottomsheets-open",_=".mdl-layout__content.qor-page",s=".qor-page__body",q=".qor-page__header",a=".qor-bottomsheets__search-input";function l(t,e){var i=[],n=e?"src":"href";return t.each(function(){i.push(b(this).attr(n))}),o.uniq(i)}function d(t,e,i){for(var n=0,o=0,r=t.length;o')},filterChanged:function(t,e,i){i=this.constructloadURL(e,i);return i&&this.reload(i),!1},selectorChanged:function(t,e,i){i=this.constructloadURL(e,i);return i&&this.reload(i),!1},keyup:function(t){var e=this.$bottomsheets.find(a);13===t.which&&e.length&&e.is(":focus")&&this.search()},search:function(){var t=this.$bottomsheets,e=t.data().url,i=b.trim(t.find(a).val()),t=e+"?keyword="+i;/\?/g.test(e)&&(t=e+"&keyword="+i),this.reload(t)},pagination:function(t){t=b(t.target).closest("a").prop("href");return t&&this.reload(t),!1},reload:function(t){var e=this.$bottomsheets.find(s);this.addLoading(e),this.fetchPage(t)},reloadFromUrl:function(t,e){this.reload(e)},fetchPage:function(i){var n=this.$bottomsheets,o=this;b.get(i,function(t){var e=b(t).find(_),t=e.find(q),e=e.find(s);e.length?(n.find(s).html(e.html()),t.length&&(o.$body.find(q).html(t.html()).trigger("enable"),o.addHeaderClass()),n.trigger("reload.qor.bottomsheets")):o.reload(i)}).fail(function(){window.alert("server error, please try again later!")})},constructloadURL:function(t,e){var i,n,o=this.filterURL,r=this.$bottomsheets.data().url;if(!o){if(!r)return;o=r}return i=new URL("http://www.getqor.com/"+t),n=e,r=i.search,n=n.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),t=null===(r=new RegExp("[\\?&]"+n+"=([^&#]*)").exec(decodeURIComponent(r)))?"":r[1].replace(/\+/g," "),o=this.filterURL=(i=e,n=t,r=o,e=String(i).replace(/[\\^$*+?.()|[\]{}]/g,"\\$&"),t=new RegExp("([?&])"+e+"=.*?(&|$)","i"),e=-1!==r.indexOf("?")?"&":"?",r.match(t)?n?r.replace(t,"$1"+i+"="+n+"$2"):"?"===RegExp.$1||RegExp.$1===RegExp.$2?r.replace(t,"$1"):r.replace(t,""):n?r+e+i+"="+n:void 0)},addHeaderClass:function(){this.$body.find(q).hide(),this.$bottomsheets.find(q).children(".qor-bottomsheet__filter").length&&this.$body.addClass("has-header").find(q).show()},addLoading:function(t){t.html(""),b(w.TEMPLATE_LOADING).appendTo(t).trigger("enable.qor.material")},loadExtraResource:function(t){var e,i,n=(e=t.$links,i=b("link"),e=l(e),i=l(i),o.difference(e,i)),i=(e=t.$scripts,i=b("script"),e=l(e,!0),i=l(i,!0),o.difference(e,i));n.length&&function t(e){var i=document.createElement("link"),n=e.shift();i.type="text/css",i.rel="stylesheet",i.onload=function(){e.length&&t(e)},i.href=n,document.getElementsByTagName("head")[0].appendChild(i)}(n),i.length&&d(i,t)},loadMedialibraryJS:function(t){var e,t=t.filter("script"),i=/theme=media_library/g,n=this;t.each(function(){var t;e=b(this).prop("src"),i.test(e)&&((t=document.createElement("script")).src=e,document.body.appendChild(t),n.mediaScriptAdded=!0)})},submit:function(t){var r,e=t.target,s=b(e),a=this,l=s.prop("action"),d=s.closest(".qor-bottomsheets"),c=d.data(),i=c.ajaxType,u=s.find(":submit");c.ingoreSubmit||s.data().normalSubmit||(b(document).trigger("bottomsheetBeforeSend.qor.bottomsheets"),t.preventDefault(),r=new n(e),b.ajax(l,{method:s.prop("method"),data:r,dataType:i||"html",processData:!1,contentType:!1,beforeSend:function(){u.prop("disabled",!0)},success:function(t,e,i){if(c.ajaxMute)d.remove();else if(c.ajaxTakeover)c.$target.parent().trigger("ajaxSuccessed.qor.bottomsheets",[t,d]);else{t=i.getResponseHeader("Content-Disposition");if(t&&-1!==t.indexOf("attachment")){var t=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(t),n=i.getResponseHeader("Content-Type"),o="";return null!=t&&t[1]&&(o=t[1].replace(/['"]/g,"")),window.QOR.qorAjaxHandleFile(l,n,o,r),void u.prop("disabled",!1)}b(".qor-error").remove();n=s.data("returnUrl"),o=s.data("refreshUrl");o?window.location.href=o:"refresh"!=n?(n&&"refresh"!=n?a.load(n):a.refresh(),b(document).trigger("bottomsheetSubmitComplete.qor.bottomsheets")):a.refresh()}},error:function(t){window.QOR.handleAjaxError(t)},complete:function(){u.prop("disabled",!1)}}))},load:function(s,a,l){var d,t,e,c=this.options,u=a.actionData,h=this.resourseData,f=h.selectModal,p=h.ingoreSubmit,m=this.$bottomsheets,y=this.$header,g=this.$body;s&&(this.show(),this.addLoading(g),this.filterURL=s,g.removeClass("has-header has-hint"),a=b.isPlainObject(a)?a:{},d=a.method||"GET",t=a.datatype||"html",e=b.proxy(function(){b.ajax(s,{method:d,dataType:t,success:b.proxy(function(t){var e,i,n,o,r;"GET"===d?(i={$scripts:(e=b(t)).filter("script"),$links:e.filter("link"),url:s,response:t},n=f&&e.find(".qor-search-container").length,o=t.match(/<\s*body.*>[\s\S]*<\s*\/body\s*>/gi),r=e.find(_),o&&(o=o.join("").replace(/<\s*body/gi,"').concat(a.selectBacktolistTitle,"")),f&&(g.find(".qor-button--new").data("ingoreSubmit",!0).data("selectId",h.selectId).data("loadInline",!0),"one"==f||a.selectNohint||void 0!==h.maxItem&&"1"==h.maxItem||g.addClass("has-hint"),"mediabox"!=f||this.mediaScriptAdded||this.loadMedialibraryJS(e)),y.find(".qor-button--new").remove(),this.$title.after(g.find(".qor-button--new")),n&&(m.addClass("has-search"),y.find(".qor-bottomsheets__search").remove(),y.prepend(w.TEMPLATE_SEARCH)),u&&u.length&&this.bindActionData(u),h.bottomsheetClassname&&m.addClass(h.bottomsheetClassname),m.trigger("enable"),m.one("hidden.qor.bottomsheets",function(){b(this).trigger("disable")}),this.addHeaderClass(),m.data(a),l&&b.isFunction(l)&&l(this.$bottomsheets),m.trigger("bottomsheetLoaded.qor.bottomsheets",[s,t]))):a.returnUrl?this.load(a.returnUrl):this.refresh()},this),error:b.proxy(function(){var t;this.$bottomsheets.remove(),b(".qor-bottomsheets").is(":visible")||b("body").removeClass(v),t=0=u&&c&&v.isFunction(c)&&c()}).attr("src",t).data("originalUrl",t),p.show()},start:function(){var o=this.options,r=this.$modal,t=this.$target,e=t.data(),s=e.sizeName||"original",i=e.sizeResolution,n=e&&e.originalUrl&&t.attr("data-original-url")?/\.original\./.test(e.originalUrl)?e.originalUrl:/\.original\./.test(t.attr("data-original-url"))?t.attr("data-original-url"):t.attr("data-original-url").replace(/file\./,"file.original."):t.attr("src"),a=v("")),l=this.data||{},d=this,t=NaN,n=e.sizeResolutionWidth,e=e.sizeResolutionHeight;i&&(n||e||(n=q(i,"width"),e=q(i,"height")),t=n/e),l[o.key]||(l[o.key]={}),r.trigger("enable.qor.material").find(u).html(a),(e=this.getList(t))&&r.find(h).show().append(e),a.cropper({aspectRatio:t,data:function(t){var e,i={};if(v.isPlainObject(t))for(e in t)t.hasOwnProperty(e)&&(i[String(e).toLowerCase()]=t[e]);return i}(l[o.key][s]),background:!1,movable:!1,zoomable:!1,scalable:!1,rotatable:!1,autoCropArea:1,ready:function(){r.find(".qor-cropper__options-toggle").on(c,function(){r.find(".qor-cropper__options-input").prop("checked",v(this).prop("checked"))}).prop("checked",!0),r.find(".qor-cropper__save").one(c,function(){var t,e=a.cropper("getData",!0),i=a.cropper("getCroppedCanvas"),n=[];if(l.Crop=!0,l[o.key][s]=e,d.imageData=a.cropper("getImageData"),d.cropData=e,i)try{t=i.toDataURL()}catch(t){console.log(t),console.log("Please check image Cross-origin setting")}r.find(h+" input").each(function(){var t=v(this);t.prop("checked")&&n.push(t.attr("name"))}),d.output(t,n),r.qorModal("hide")})}})},stop:function(){this.$modal.trigger("disable.qor.material").find(u+" > img").cropper("destroy").remove().end().find(h).hide().find("ul").remove()},getList:function(o){var r=[];return this.$list.find("img").not(this.$target).each(function(){var t=v(this).data(),e=t.sizeResolution,i=t.sizeName,n=t.sizeResolutionWidth,t=t.sizeResolutionHeight;e&&(n||t||(n=q(e,"width"),t=q(e,"height")),n/t===o&&r.push('"))}),r.length?"
  • "+r.join("
  • ")+"
":""},output:function(t,e){var i=this.$target;t?this.center(i.attr("src",t),!0):this.preview(i),v.isArray(e)&&e.length&&this.autoCrop(t,e),this.$output.val(JSON.stringify(this.data)).trigger(o),this.$formCropInput.val(JSON.stringify(this.data))},preview:function(t,e,i){var n=t.parent().parent(),o=n.width(),r=n.height(),s=e||this.imageData,n=v.extend({},i||this.cropData),e=n.width/n.height,i=o;0!=i&&0!=s.naturalWidth&&0!=s.naturalHeight&&(r*e<=o&&(i=r*e),i=n.width/i,t.css({maxWidth:s.naturalWidth/i,maxHeight:s.naturalHeight/i}),this.center(t))},center:function(t,o){t.each(function(){var t=v(this),i=t.parent(),n=i.parent();function e(){var t=n.height(),e=i.height(),e=eclear'))},show:function(){this.$element.find(l).toggle()},close:function(t){var e=s(t.target),i=s(l),n=i.is(":visible"),o=e.closest(l).length,r=e.closest(".qor-filter-toggle").length,t=e.closest(".qor-modal").length,e=e.closest(".ui-timepicker-wrapper").length;n&&(o||r||t||e)||i.hide()},setFilterTime:function(t){var e,i,n=s(t.target),o=n.data(),t=o.filterRange;if(!t)return!1;if(s(this.options.label).removeClass(d),n.addClass(d),"events"==t)return this.$timeStart.val(o.scheduleStartAt||""),this.$timeEnd.val(o.scheduleEndAt||""),this.$searchButton.click(),!1;switch(t){case"today":e=i=new Date;break;case"week":e=this.startWeekDate,i=this.endWeekDate;break;case"month":e=this.startMonthDate,i=this.endMonthDate}if(!e||!i)return!1;o=this.getTime(e)+" 00:00",t=this.getTime(i)+" 23:59",this.$timeStart.val(o),this.$timeEnd.val(t),this.$searchButton.click()},getTime:function(t){var e=(e=t.getMonth()+1)<10?"0"+e:e,i=(i=t.getDate())<10?"0"+i:i;return t.getFullYear()+"-"+e+"-"+i},clear:function(){var t=s(this.options.trigger),e=t.find(".qor-selector-label");return t.removeClass("active clearable"),e.html(e.data("label")),this.$timeStart.val(""),this.$timeEnd.val(""),this.$searchButton.click(),!1},getUrlParameter:function(t){var e=decodeURIComponent(a.search),t=t.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),e=new RegExp("[\\?&]"+t+"=([^&#]*)").exec(e);return null===e?"":e[1].replace(/\+/g," ")},updateQueryStringParameter:function(t,e,i){var n=i||a.href,o=n.match(/#\S*$/)||"",r=String(t).replace(/[\\^$*+?.()|[\]{}]/g,"\\$&"),i=new RegExp("([?&])"+r+"=.*?(&|$)","i"),r=-1!==n.indexOf("?")?"&":"?";return o&&(o=o[0],n=n.replace(o,"")),n.match(i)?n=e?n.replace(i,"$1"+t+"="+e+"$2"):"?"===RegExp.$1||RegExp.$1===RegExp.$2?n.replace(i,"$1"):n.replace(i,""):e&&(n=n+r+t+"="+e),n+o},search:function(){var t=this.$searchParam,i=a.href,n=this;t.length&&(t.each(function(){var t=s(this),e=t.data().searchParam,t=t.val();i=n.updateQueryStringParameter(e,t,i)}),this.$element.closest(r).length?s(r).trigger("filterChanged.qor.filter",[i,"qor.filter.time"]):a.href=i)},destroy:function(){this.unbind(),this.$element.removeData(o)}},c.DEFAULTS={label:!1,trigger:!1,button:!1,clear:!1},c.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new c(this,n))}"string"==typeof n&&s.isFunction(t=i[n])&&t.apply(i)})},s(function(){var e='[data-toggle="qor.filter.time"]',i={label:".qor-filter__block-buttons button",trigger:"a.qor-filter-toggle",button:".qor-filter__button-search",clear:".qor-selector-clear"};s(document).on("disable.qor.filter",function(t){c.plugin.call(s(e,t.target),"destroy")}).on(t,function(t){c.plugin.call(s(e,t.target),i)}).triggerHandler(t)}),c}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(d){var c=window.location,o="qor.filter",t="enable."+o,e="click."+o,i="change."+o,u=".qor-bottomsheets";function h(t,i){var n,e=decodeURI(c.search),o=c.search.match(/per_page=\d+/),e=e.replace(/per_page=\d+/g,"").replace(/page=\d+/,"page=1");return o&&o.length&&(e=e+"&"+o[0]),d.isArray(t)&&(n=f(e),d.each(t,function(t,e){-1===(t=d.inArray(e,n))?n.push(e):i&&n.splice(t,1)}),e="?"+n.join("&")),e}function f(t){var e=[];return t&&-1 thead"),this.$tbody=e.find("> tbody"),this.$header=s(t.header),this.$subHeader=s(t.subHeader),this.$content=s(t.content),this.marginBottomPX=parseInt(this.$subHeader.css("marginBottom")),this.paddingHeight=t.paddingHeight,this.resize(),this.bind())},bind:function(){this.$content.on(i,this.toggle.bind(this)),t.on(e,this.resize.bind(this))},unbind:function(){this.$content.off(i,this.toggle).off(e,this.resize)},isNeedBuild:function(){var t=this.$element;return!!(1 tr:visible").length<=1||t.data("disable-fixer"))},build:function(){var e=[];this.$tbody.find("> tr:first").children().each(function(){var t=s(this).outerWidth();s(this).outerWidth(t),e.push(t)}),this.$thead.find(">tr").children().each(function(t){s(this).outerWidth(e[t])})},toggle:function(){var t,e,i,n,o,r;this.$content.length&&(t=this.$element,e=this.$thead,i=this.$content.scrollTop(),n=this.$subHeader.outerHeight()+this.paddingHeight+this.marginBottomPX,o=s(".qor-page__header").outerHeight(),r=this.$content.offset().top+s(".qor-page__header").height(),n-o\n \n \n "),this.bind()},bind:function(){this.$element.on(i,l,this.showEditButton).on(n,l,this.hideEditButton).on(e,".qor-inlineedit__cancel",this.hideEdit).on(e,".qor-inlineedit__save",this.saveEdit).on(e,r,this.showEdit.bind(this))},unbind:function(){this.$element.off(i).off(n).off(e)},showEditButton:function(t){var e=s(u.TEMPLATE_EDIT);if(s(t.target).closest(a).find("input:disabled, textarea:disabled,select:disabled").length)return!1;e.appendTo(s(this))},hideEditButton:function(){s(".qor-inlineedit__edit").remove()},showEdit:function(t){t=s(t.target).closest(r).hide().closest(a).addClass(c);s(this.TEMPLATE_SAVE).appendTo(t)},hideEdit:function(){s(this).closest(a).removeClass(c).find(d).remove()},saveEdit:function(){var n=s(this),o=n.closest(a),t=n.closest("form"),e=o.closest(".qor-fieldset").find('input.qor-hidden__primary_key[type="hidden"]'),i=o.find('input[name*="QorResource"],textarea[name*="QorResource"],select[name*="QorResource"]'),r=i.length&&i.prop("name").match(/\.\w+/g),i=i.serialize();e.length&&(i="".concat(i,"&").concat(e.serialize())),r.length&&s.ajax(t.prop("action"),{method:t.prop("method"),data:i,dataType:"json",beforeSend:function(){n.prop("disabled",!0)},success:function(t){var e=function(t,e){var i,n=e[t[0].slice(1)];if(1mode_edit',u.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(o);i||e.data(o,i=new u(this,n)),"string"==typeof n&&s.isFunction(t=i[n])&&t.call(i)})},s(function(){var e='[data-toggle="qor.inlineEdit"]',i={};s(document).on("disable.qor.inlineEdit",function(t){u.plugin.call(s(e,t.target),"destroy")}).on(t,function(t){u.plugin.call(s(e,t.target),i)}).triggerHandler(t)}),u}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(e){var i=window.componentHandler,n='[class*="mdl-js"],[class*="mdl-tooltip"]';function o(t){i&&(e(t).is(n)?i.upgradeElements(t):i.upgradeElements(e(n,t).toArray()))}function r(t){i&&(e(t).is(n)?i.downgradeElements(t):i.downgradeElements(e(n,t).toArray()))}e(function(){e(document).on("enable.qor.material",function(t){o(t.target)}).on("disable.qor.material",function(t){r(t.target)}).on("update.qor.material",function(t){r(t.target),o(t.target)})})}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(o){var n=o(document),r="qor.modal",t="click."+r,e="keyup."+r,s="transitionend",a="qor-modal-open",l="in",i="aria-hidden";function d(t,e){this.$element=o(t),this.options=o.extend({},d.DEFAULTS,o.isPlainObject(e)&&e),this.transitioning=!1,this.fadable=!1,this.init()}return d.prototype={constructor:d,init:function(){this.fadable=this.$element.hasClass("fade"),this.options.show?this.show():this.toggle()},bind:function(){this.$element.on(t,o.proxy(this.click,this)),this.options.keyboard&&n.on(e,o.proxy(this.keyup,this))},unbind:function(){this.$element.off(t,this.click),this.options.keyboard&&n.off(e,this.keyup)},click:function(t){var e=this.$element[0],i=t.target;if(i===e&&this.options.backdrop)this.hide();else for(;i!==e;){if("modal"===o(i).data("dismiss")){this.hide();break}i=i.parentNode}},keyup:function(t){27===t.which&&this.hide()},show:function(t){var e,i=this.$element;if(!this.transitioning&&!i.hasClass(l)&&(e=o.Event("show.qor.modal"),i.trigger(e),!e.isDefaultPrevented())){if(n.find("body").addClass(a),i.addClass("shown").scrollTop(0).get(0).offsetHeight,this.transitioning=!0,t||!this.fadable)return i.addClass(l),void this.shown();i.one(s,o.proxy(this.shown,this)),i.addClass(l)}},shown:function(){this.transitioning=!1,this.bind(),this.$element.attr(i,!1).trigger("shown.qor.modal").focus()},hide:function(t){var e,i=this.$element;if(!this.transitioning&&i.hasClass(l)&&(e=o.Event("hide.qor.modal"),i.trigger(e),!e.isDefaultPrevented())){if(n.find("body").removeClass(a),this.transitioning=!0,t||!this.fadable)return i.removeClass(l),void this.hidden();i.one(s,o.proxy(this.hidden,this)),i.removeClass(l)}},hidden:function(){this.transitioning=!1,this.unbind(),this.$element.removeClass("shown").attr(i,!0).trigger("hidden.qor.modal")},toggle:function(){this.$element.hasClass(l)?this.hide():this.show()},destroy:function(){this.$element.removeData(r)}},d.DEFAULTS={backdrop:!1,keyboard:!0,show:!0},d.plugin=function(n){return this.each(function(){var t,e=o(this),i=e.data(r);if(!i){if(/destroy/.test(n))return;e.data(r,i=new d(this,n))}"string"==typeof n&&o.isFunction(t=i[n])&&t.apply(i)})},o.fn.qorModal=d.plugin,o(function(){var e=".qor-modal";o(document).on(t,'[data-toggle="qor.modal"]',function(){var t=o(this),e=t.data(),t=o(e.target||t.attr("href"));d.plugin.call(t,t.data(r)?"toggle":e)}).on("disable.qor.modal",function(t){d.plugin.call(o(e,t.target),"destroy")}).on("enable.qor.modal",function(t){d.plugin.call(o(e,t.target))})}),d}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(r){var o="qor.tabbar.radio",t="enable."+o,e="click."+o,s="[data-tab-target]",a="is-active";function l(t,e){this.$element=r(t),this.options=r.extend({},l.DEFAULTS,r.isPlainObject(e)&&e),this.init()}return l.prototype={constructor:l,init:function(){this.bind()},bind:function(){this.$element.on(e,s,this.switchTab.bind(this))},unbind:function(){this.$element.off(e,s,this.switchTab)},switchTab:function(t){var e=r(t.target),i=this.$element,n=i.find(s),o=i.find("[data-tab-source]"),t=e.data().tabTarget;e.hasClass(a)||(n.removeClass(a),e.addClass(a),o.hide().filter('[data-tab-source="'+t+'"]').show(),i.trigger("switched.qor.tabbar.radio",[i,t]))},destroy:function(){this.unbind()}},l.DEFAULTS={},l.plugin=function(n){return this.each(function(){var t,e=r(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new l(this,n))}"string"==typeof n&&r.isFunction(t=i[n])&&t.apply(i)})},r(function(){var e='[data-toggle="qor.tab.radio"]';r(document).on("disable.qor.tabbar.radio",function(t){l.plugin.call(r(e,t.target),"destroy")}).on(t,function(t){l.plugin.call(r(e,t.target))}).triggerHandler(t)}),l}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(c){var r="qor.redactor",t="enable."+r,l="click."+r,e="addCrop."+r,i="removeCrop."+r,s="scroll."+r,n=".qor-cropper__toggle--redactor";function u(t,e){this.$element=c(t),this.options=c.extend(!0,{},u.DEFAULTS,c.isPlainObject(e)&&e),this.init()}return u.prototype={constructor:u,init:function(){var i,t=this.options,e=this.$element,n=e.closest(t.parent);n.length||(n=e.parent()),this.$parent=n,this.$button=c(u.BUTTON),this.$modal=c((i=u.MODAL,t=t.text,"string"==typeof i&&"object"===_typeof(t)&&c.each(t,function(t,e){i=i.replace("$["+String(t).toLowerCase()+"]",e)}),i)).appendTo("body"),this.bind()},bind:function(){this.$element.on(e,c.proxy(this.addButton,this)).on(i,c.proxy(this.removeButton,this))},unbind:function(){this.$element.off(e).off(i).off(s)},addButton:function(t,e){var i=c(e);this.$button.css("left",c(e).width()/2).prependTo(i.parent()).find(n).one(l,c.proxy(this.crop,this,i))},removeButton:function(){this.$button.find(n).off(l),this.$button.detach()},crop:function(n){var o,r=this.options,s=n.attr("src"),t=s,a=this.$modal;c.isFunction(r.replace)&&(t=r.replace(t)),o=c("")),a.one("shown.qor.modal",function(){var t,e;o.cropper({data:(t=n.attr("data-crop-options"),e=t&&t.split(","),t=null,e&&4===e.length&&(t={x:Number(e[0]),y:Number(e[1]),width:Number(e[2]),height:Number(e[3])}),t),background:!1,movable:!1,zoomable:!1,scalable:!1,rotatable:!1,checkImageOrigin:!1,ready:function(){a.find(".qor-cropper__save").one(l,function(){var i=o.cropper("getData",!0);c.ajax(r.remote,{type:"POST",contentType:"application/json",data:JSON.stringify({Url:s,CropOptions:{original:function(t){var e,i,n={};if(c.isPlainObject(t))for(e in t)t.hasOwnProperty(e)&&(n["string"==typeof(i=e)&&(i=i.charAt(0).toUpperCase()+i.substr(1)),i]=t[e]);return n}(i)},Crop:!0}),dataType:"json",success:function(t){var e;c.isPlainObject(t)&&t.url&&(n.attr("src",t.url).attr("data-crop-options",(t=i,e=[],c.isPlainObject(t)&&c.each(t,function(){e.push(arguments[1])}),e.join())).removeAttr("style").removeAttr("rel"),c.isFunction(r.complete)&&r.complete(),a.qorModal("hide"))}})})}})}).one("hidden.qor.modal",function(){o.cropper("destroy").remove()}).qorModal("show").find(".qor-cropper__wrapper").append(o)},destroy:function(){this.unbind(),this.$modal.qorModal("hide").remove(),this.$element.removeData(r)}},u.DEFAULTS={remote:!1,parent:!1,toggle:!1,replace:null,complete:null,text:{title:"Crop the image",ok:"OK",cancel:"Cancel"}},u.BUTTON='
\n Edit\n Crop\n
',u.MODAL='',u.plugin=function(o){return this.each(function(){var t,i=c(this),n=i.data(r);if(n)/destroy/.test(o)&&window.$R(this,"destroy");else{if(!window.$R)return;if(/destroy/.test(o))return;i.data(r,n={});var e={imageUpload:i.data("uploadUrl"),fileUpload:i.data("uploadUrl"),buttons:["html","format","bold","italic","deleted","lists","image","file","link"],linkNewTab:!0,linkTitle:!1,autoparsePaste:!1,autoparseLinks:!1,multipleUpload:!1,toolbarFixedTarget:!i.closest(".qor-slideout").length&&!i.closest(".qor-bottomsheets").length&&c("main.mdl-layout__content").length?"main.mdl-layout__content":document,callbacks:{started:function(){var t,a=c(this.container.$container.nodes[0]),l=c(this.toolbar.$toolbar.nodes[0]),e=c(".qor-slideout").is(":visible"),d=64;e?d=0!=i.closest(".qor-bottomsheets").length?(t=i.closest(".qor-page__body"),i.closest(".qor-page__body").offset().top):(t=".qor-slideout__body",c(".qor-slideout__header").height()):d+=c(t=".qor-layout main.qor-page").find(".qor-page__header").height(),c(t).on(s,function(){var t,e,i,n,o,r,s;t=l,i=d,n=(e=a).offset().top,o=e.outerHeight(),r={position:"relative",top:"auto",width:"auto"},s={position:"fixed",top:i,width:e.width(),boxShadow:"none"},n .qor-field__block > .qor-fieldset--new");this.singlePage=!(t.closest(".qor-slideout").length&&t.closest(".qor-bottomsheets").length),this.maxitems=t.data("maxItem"),this.isSortable=t.hasClass("qor-fieldset-sortable"),e.length&&!t.closest(".qor-fieldset--new").length&&(e.trigger("disable"),e.find("select[data-toggle]").removeAttr("data-select2-id"),this.isMultipleTemplate=t.data("isMultiple"),this.isMultipleTemplate?(this.fieldsetName=[],this.template={},this.index=[],e.each(function(t,e){(i=c(e).data("fieldsetName"))&&(n.template[i]=c(e).prop("outerHTML"),n.fieldsetName.push(i))}),this.parseMultiple()):this.parse(e.prop("outerHTML")),e.hide(),this.bind(),this.resetButton(),this.resetPositionButton())},resetPositionButton:function(){var t=this.$element.find("> .qor-sortable__button");this.isSortable&&(1 .qor-field__block > .qor-fieldset").not(".qor-fieldset--new,.is-deleted").length},toggleButton:function(t){var e=this.$element.find("> .qor-field__block > .qor-fieldset__add");t?e.hide():e.show()},resetButton:function(){this.maxitems<=this.getCurrentItems()?this.toggleButton(!0):this.toggleButton()},parse:function(t){t&&(t=this.initTemplate(t),this.template=t.template,this.index=t.index)},parseMultiple:function(){for(var t,e,i=this.fieldsetName,n=0,o=i.length;n .qor-field__block > .qor-sortable__item").not(".qor-fieldset--new").length,e.attr("order-index",t).attr("order-item","item_".concat(t)).css("order",t)),e.data("itemIndex",this.index).removeClass("qor-fieldset--new"),e}},del:function(t){var e,i=this.options,n=c(t.target).closest(i.itemClass),o=this,t={confirm:c(t.target).closest(i.delClass).data("confirm")||"Are you sure?"};s.qorConfirm(t,function(t){t&&(n.addClass("is-deleted").children(":visible").addClass("hidden").hide(),(e=c(i.alertTemplate.replace("{{name}}",o.parseName(n)))).find(i.undoClass).one(a,function(){if(o.maxitems<=o.getCurrentItems())return window.QOR.qorConfirm(o.$element.data("maxItemHint")),!1;n.find("> .qor-fieldset__alert").remove(),n.removeClass("is-deleted").children(".hidden").removeClass("hidden").show(),o.resetButton(),o.resetPositionButton()}.bind(this)),o.resetButton(),o.resetPositionButton(),n.append(e))})},parseName:function(t){t=t.find("input[name]").attr("name")||t.find("textarea[name]").attr("name");if(t)return t.replace(/[^\[\]]+$/,"")},destroy:function(){this.unbind(),this.$element.removeData(o)}},d.DEFAULTS={itemClass:".qor-fieldset",newClass:".qor-fieldset--new",addClass:".qor-fieldset__add",delClass:".qor-fieldset__delete",childrenClass:".qor-field__block",undoClass:".qor-fieldset__undo",alertTemplate:'
'},d.plugin=function(n){return this.each(function(){var t,e=c(this),i=e.data(o);i||e.data(o,i=new d(this,n)),"string"==typeof n&&c.isFunction(t=i[n])&&t.call(i)})},c(function(){var e=l,i={};c(document).on("disable.qor.replicator",function(t){d.plugin.call(c(e,t.target),"destroy")}).on(t,function(t){d.plugin.call(c(e,t.target),i)}).triggerHandler(t)}),d}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(s){var a=window.location,o=window.componentHandler,l=window.history,r="qor.globalSearch",t="enable."+r,e="click."+r,d=".qor-global-search--resource",c=".qor-global-search--results",u="is-active";function h(t,e){this.$element=s(t),this.options=s.extend({},h.DEFAULTS,s.isPlainObject(e)&&e),this.init()}return h.prototype={constructor:h,init:function(){this.bind(),this.initTab()},bind:function(){this.$element.on(e,s.proxy(this.click,this))},unbind:function(){this.$element.off(e,this.check)},initTab:function(){var t=a.search;/resource_name/.test(t)&&(t=t.match(/resource_name=\w+/g).toString().split("=")[1],s(d).removeClass(u),s('[data-resource="'+t+'"]').addClass(u))},click:function(t){var e,i,n,o=s(t.target),r=o.data();o.is(d)&&(n=a.href.replace(/#/g,""),e=r.resource,i=/resource_name/.test(n),t="resource_name="+e,r=/keyword/.test(n)?"&":"?keyword=&",n=e?i?n.replace(/resource_name=\w+/g,t):n+r+t:n.replace(/&resource_name=\w+/g,""),l.pushState?this.fetchSearch(n,o):a.href=n)},fetchSearch:function(e,i){var n=document.title;s.ajax(e,{method:"GET",dataType:"html",beforeSend:function(){s(".mdl-spinner").remove(),s(c).prepend('
').find(".qor-section").hide(),o.upgradeElement(document.querySelector(".mdl-spinner"))},success:function(t){t=s(t).find(c).html();s(d).removeClass(u),i.addClass(u),l.pushState({Page:e,Title:n},n,e),s(".mdl-spinner").remove(),s(c).removeClass("loading").html(t),o.upgradeElements(document.querySelectorAll(".qor-table"))},error:function(t,e,i){s(c).find(".qor-section").show(),s(".mdl-spinner").remove(),window.alert([e,i].join(": "))}})},destroy:function(){this.unbind(),this.$element.removeData(r)}},h.DEFAULTS={},h.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(r);i||e.data(r,i=new h(this,n)),"string"==typeof n&&s.isFunction(t=i[n])&&t.call(i)})},s(function(){var e='[data-toggle="qor.global.search"]',i={};s(document).on("disable.qor.globalSearch",function(t){h.plugin.call(s(e,t.target),"destroy")}).on(t,function(t){h.plugin.call(s(e,t.target),i)}).triggerHandler(t)}),h}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(l){var d=window.FormData,c=window.QOR,o="qor.selectcore",s="afterSelected."+o,t="click."+o,e="submit."+o,i="table.qor-js-table tr";function r(t,e){this.$element=l(t),this.options=l.extend({},r.DEFAULTS,l.isPlainObject(e)&&e),this.init()}return r.prototype={constructor:r,init:function(){this.bind()},bind:function(){this.$element.on(t,i,this.processingData.bind(this)).on(e,"form",this.submit.bind(this))},unbind:function(){this.$element.off(t,i).off(e,"form")},processingData:function(e){var t=l(e.target).closest("tr"),i=t.closest(".qor-bottomsheets"),n={},o=this.options,r=o.onSelect,o=o.loading;return(n=l.extend({},n,t.data())).$clickElement=t,t=n.mediaLibraryUrl||n.url,o&&l.isFunction(o)&&o(i),t?l.getJSON(t,function(t){t.MediaOption&&(t.MediaOption=JSON.parse(t.MediaOption)),n=l.extend({},t,n),r&&l.isFunction(r)&&(r(n,e),l(document).trigger(s))}).always(function(){i.find(".qor-media-loading").remove()}):r&&l.isFunction(r)&&(r(n,e),l(document).trigger(s)),!1},submit:function(e){var i,t=e.target,n=l(t),o=this,r=n.find(":submit"),s=l(c.$formLoading),a=this.options.onSubmit;l(document).trigger("selectcoreBeforeSend.qor.selectcore"),n.find(".qor-fieldset--new").remove(),d&&(e.preventDefault(),l.ajax(n.prop("action"),{method:n.prop("method"),data:new d(t),dataType:"json",processData:!1,contentType:!1,beforeSend:function(){l(".qor-submit-loading").remove(),s.appendTo(r.prop("disabled",!0).closest(".qor-form__actions")).trigger("enable.qor.material")},success:function(t){t.MediaOption&&(t.MediaOption=JSON.parse(t.MediaOption)),(i=t).primaryKey=i.ID,l(".qor-error").remove(),a&&l.isFunction(a)?(a(i,e),l(document).trigger("afterSubmitted.qor.selectcore")):o.refresh()},error:function(t){c.handleAjaxError(t)},complete:function(){r.prop("disabled",!1)}}))},refresh:function(){setTimeout(function(){window.location.reload()},350)},destroy:function(){this.unbind()}},r.plugin=function(n){return this.each(function(){var t,e=l(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new r(this,n))}"string"==typeof n&&l.isFunction(t=i[n])&&t.apply(i)})},l.fn.qorSelectCore=r.plugin,r}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(s){var i=s("body"),t=s(document),a=window.Mustache,o="qor.selectone",n="click."+o,r="enable."+o,e="reload.qor.bottomsheets",l=".qor-selected-many__remove",d=".qor-selected-many__undo",c="qor-selected-many__deleted",u=".qor-field__selectmany",h="is_selected",f="qor-bottomsheets__select-many";function p(t,e){this.$element=s(t),this.options=s.extend({},p.DEFAULTS,s.isPlainObject(e)&&e),this.init()}return p.prototype={constructor:p,init:function(){this.bind()},bind:function(){t.on(e,".".concat(f),this.reloadData.bind(this)),this.$element.on(n,l,this.clearSelect.bind(this)).on(n,'[data-select-modal="many"]',this.openBottomSheets.bind(this)).on(n,d,this.undoDelete.bind(this))},unbind:function(){t.off(n,'[data-select-modal="many"]').off(e,".".concat(f)),this.$element.off(n,l).off(n,d)},clearSelect:function(t){var e=s(t.target),t=e.closest(u);return e.closest("[data-primary-key]").addClass(c),this.updateSelectInputData(t),!1},undoDelete:function(t){var e=s(t.target),t=e.closest(u);return e.closest("[data-primary-key]").removeClass(c),this.updateSelectInputData(t),!1},openBottomSheets:function(t){var e=s(t.target),t=e.data();this.BottomSheets=i.data("qor.bottomsheets"),this.bottomsheetsData=t,this.$selector=t.selectId?s(t.selectId):e.closest(u).find("select"),this.$selectFeild=this.$selector.closest(u).find(".qor-field__selected-many"),this.SELECT_MANY_SELECTED_ICON=s('[name="select-many-selected-icon"]').html(),this.SELECT_MANY_UNSELECTED_ICON=s('[name="select-many-unselected-icon"]').html(),this.SELECT_MANY_HINT=s('[name="select-many-hint"]').html(),this.SELECT_MANY_TEMPLATE=s('[name="select-many-template"]').html(),t.url=t.selectListingUrl,t.selectDefaultCreating&&(t.url=t.selectCreatingUrl),this.BottomSheets.open(t,this.handleSelectMany.bind(this))},reloadData:function(){this.initItems()},renderSelectMany:function(t){return a.render(this.SELECT_MANY_TEMPLATE,t)},renderHint:function(t){return a.render(this.SELECT_MANY_HINT,t)},initItems:function(){var i,t=this.$bottomsheets.find("tbody tr"),n=this.SELECT_MANY_SELECTED_ICON,o=this.SELECT_MANY_UNSELECTED_ICON,r=[];this.$selectFeild.find("[data-primary-key]").not("."+c).each(function(){r.push(s(this).data().primaryKey)}),t.each(function(){var t=s(this),e=t.find("td:first");i=t.data().primaryKey,"-1"!=r.indexOf(i)?(t.addClass(h),e.append(n)):e.append(o)}),this.updateHint(this.getSelectedItemData())},getSelectedItemData:function(){return{selectedNum:this.$selectFeild.find("[data-primary-key]").not("."+c).length}},updateHint:function(t){s.extend(t,this.bottomsheetsData),t=this.renderHint(t),this.$bottomsheets.find(".qor-selectmany__hint").remove(),this.$bottomsheets.find(".qor-page__body").before(t)},updateSelectInputData:function(t){var e,i,n=(t||this.$selectFeild).find("[data-primary-key]").not("."+c),o=t?t.find(".qor-field__selectmany-input"):this.$selector,r=o.find("option");r.prop("selected",!1),n.each(function(){i=s(this).data().primaryKey,(e=r.filter('[value="'+i+'"]')).length||(i={primaryKey:i,displayName:""},e=s(a.render(p.SELECT_MANY_OPTION_TEMPLATE,i)),o.append(e)),e.prop("selected",!0)})},changeIcon:function(t,e){t.find(".qor-select__select-icon").remove(),t.find("td:first").prepend(e)},removeItem:function(t){var e=t.primaryKey;this.$selectFeild.find('[data-primary-key="'+e+'"]').find(l).click(),this.changeIcon(t.$clickElement,this.SELECT_MANY_UNSELECTED_ICON)},addItem:function(t,e){var i=this.renderSelectMany(t),n=this.$selectFeild.find('[data-primary-key="'+t.primaryKey+'"]');return n.length?n.hasClass(c)?(n.removeClass(c),this.updateSelectInputData(),void this.changeIcon(t.$clickElement,this.SELECT_MANY_SELECTED_ICON)):void 0:(this.$selectFeild.append(i),e?((e=s(a.render(p.SELECT_MANY_OPTION_TEMPLATE,t))).appendTo(this.$selector),e.prop("selected",!0),this.$bottomsheets.remove(),void(s(".qor-bottomsheets").is(":visible")||s("body").removeClass("qor-bottomsheets-open"))):void this.changeIcon(t.$clickElement,this.SELECT_MANY_SELECTED_ICON))},handleSelectMany:function(t){var e={onSelect:this.onSelectResults.bind(this),onSubmit:this.onSubmitResults.bind(this)};t.qorSelectCore(e).addClass(f),t.on(n,".qor-selectmany__selectall",this.handleSelectAll.bind(this)),this.$bottomsheets=t,this.initItems()},handleSelectAll:function(){var t=this.$bottomsheets.find(".qor-table tbody tr"),e=t.not(".is_selected");(e.length?e:t).click()},onSelectResults:function(t){this.handleResults(t)},onSubmitResults:function(t){this.handleResults(t,!0)},handleResults:function(t,e){t.displayName=t.Text||t.Name||t.Title||t.Code||t[Object.keys(t)[0]],t.displayName=t.displayName.escapeSymbol(),e?this.addItem(t,!0):((e=t.$clickElement).toggleClass(h),e.hasClass(h)?this.addItem(t):this.removeItem(t),this.updateHint(this.getSelectedItemData()),this.updateSelectInputData())},destroy:function(){this.unbind(),this.$element.removeData(o)}},p.SELECT_MANY_OPTION_TEMPLATE='',p.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new p(this,n))}"string"==typeof n&&s.isFunction(t=i[n])&&t.apply(i)})},s(function(){var e='[data-toggle="qor.selectmany"]';s(document).on("disable.qor.selectone",function(t){p.plugin.call(s(e,t.target),"destroy")}).on(r,function(t){p.plugin.call(s(e,t.target))}).triggerHandler(r)}),p}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(r){var i=r("body"),t=r(document),s=window.Mustache,o="qor.selectone",e="click."+o,n="enable."+o,a="reload.qor.bottomsheets",l=".qor-selected__remove",d=".qor-selected__change",c=".qor-field__selected",u=".qor-field__selectone-input",h=".qor-field__selectone-trigger",f=".qor-field__selectone",p="qor-bottomsheets__select-one";function m(t,e){this.$element=r(t),this.options=r.extend({},m.DEFAULTS,r.isPlainObject(e)&&e),this.init()}return m.prototype={constructor:m,init:function(){this.bind()},bind:function(){t.on(a,".".concat(p),this.reloadData.bind(this)),this.$element.on(e,l,this.clearSelect.bind(this)).on(e,"[data-selectone-url]",this.openBottomSheets.bind(this)).on(e,d,this.changeSelect)},unbind:function(){t.off(e,"[data-selectone-url]").off(a,".".concat(p)),this.$element.off(e,l).off(e,d)},clearSelect:function(t){t=r(t.target).closest(f);return t.find(c).remove(),t.find(u).html(""),t.find(u)[0].value="",t.find(h).show(),t.trigger("qor.selectone.unselected"),!1},changeSelect:function(){r(this).closest(f).find(h).trigger("click")},openBottomSheets:function(t){var e=r(t.target),t=e.data();this.BottomSheets=i.data("qor.bottomsheets"),this.$parent=e.closest(f),t.url=t.selectoneUrl,this.SELECT_ONE_SELECTED_ICON=r('[name="select-one-selected-icon"]').html(),this.BottomSheets.open(t,this.handleSelectOne.bind(this))},initItem:function(){var t,e=this.$parent.find(c);e.length&&(t=e.data().primaryKey)&&this.$bottomsheets.find('tr[data-primary-key="'+t+'"]').addClass("is_selected").find("td:first").append(this.SELECT_ONE_SELECTED_ICON)},reloadData:function(){this.initItem()},renderSelectOne:function(t){return s.render(r('[name="select-one-selected-template"]').html(),t)},handleSelectOne:function(t){var e={onSelect:this.onSelectResults.bind(this),onSubmit:this.onSubmitResults.bind(this)};t.qorSelectCore(e).addClass(p),this.$bottomsheets=t,this.initItem()},onSelectResults:function(t){this.handleResults(t)},onSubmitResults:function(t){this.handleResults(t,!0)},handleResults:function(t){var e,i=this.$parent,n=i.find("select"),o=i.find(c);t.displayName=t.Text||t.Name||t.Title||t.Code||t[Object.keys(t)[0]],t.selectoneValue=t.primaryKey||t.ID,t.displayName=t.displayName.escapeSymbol(),n.length&&(e=this.renderSelectOne(t),o.length&&o.remove(),i.prepend(e),i.find(h).hide(),n.html(s.render(m.SELECT_ONE_OPTION_TEMPLATE,t)),n[0].value=t.primaryKey||t.ID,i.trigger("qor.selectone.selected",[t]),this.$bottomsheets.qorSelectCore("destroy").remove(),r(".qor-bottomsheets").is(":visible")||r("body").removeClass("qor-bottomsheets-open"))},destroy:function(){this.unbind(),this.$element.removeData(o)}},m.SELECT_ONE_OPTION_TEMPLATE='',m.plugin=function(n){return this.each(function(){var t,e=r(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new m(this,n))}"string"==typeof n&&r.isFunction(t=i[n])&&t.apply(i)})},r(function(){var e='[data-toggle="qor.selectone"]';r(document).on("disable.qor.selectone",function(t){m.plugin.call(r(e,t.target),"destroy")}).on(n,function(t){m.plugin.call(r(e,t.target))}).triggerHandler(n)}),m}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(l){var t=l(document),r="qor.selector",i="enable."+r,e="click."+r,d="selected",c="disabled",s="clearable",a="."+d,u=".qor-selector-toggle",h=".qor-selector-label",f=".qor-selector-menu",p=".qor-bottomsheets";function m(t,e){this.options=e,this.$element=l(t),this.init()}return m.prototype={constructor:m,init:function(){var t=this.$element;this.placeholder=t.attr("placeholder")||t.attr("name")||"Select",this.build()},build:function(){var t=this.$element,e=l(m.TEMPLATE),i=this.options.aligned+"-aligned",s={},n=t.data(),o=n.hover,a=t.attr("name");this.isBottom="bottom"==n.position,o&&e.addClass("hover"),e.addClass(i).find(f).html(function(){var r=[];return t.children().each(function(){var t=l(this),e=t.attr("selected"),i=t.attr("disabled"),n=t.attr("value"),o=t.text(),t=[];e&&(t.push(d),s.value=n,s.label=o,s.paramName=a),i&&t.push(c),r.push("'+o+"")}),r.join("")}),this.$selector=e,t.hide().after(e),e.find(u).data("paramName",a),this.pick(s,!0),this.bind()},unbuild:function(){this.unbind(),this.$selector.remove(),this.$element.show()},bind:function(){this.$selector.on(e,l.proxy(this.click,this)),t.on(e,l.proxy(this.close,this))},unbind:function(){this.$selector.off(e,this.click)},click:function(t){var e=l(t.target);t.stopPropagation(),e.is(".qor-selector-clear")?this.clear():e.is("li")?(e.hasClass(d)||e.hasClass(c)||this.pick(e.data()),this.close()):e.closest(u).length&&this.open()},pick:function(t,e){var i=this.$selector,n=!!t.value,o=this.$element;i.find(u).toggleClass("active",n).toggleClass(s,n&&this.options.clearable).find(h).text(t.label||this.placeholder),e||(i.find(f).children('[data-value="'+t.value+'"]').addClass(d).siblings(a).removeClass(d),o.val(t.value),o.closest(p).length&&!o.closest('[data-toggle="qor.filter"]').length?l(p).trigger("selectorChanged.qor.selector",[t.value,t.paramName]):o.trigger("change"))},clear:function(){var t=this.$element;this.$selector.find(u).removeClass("active").removeClass(s).find(h).text(this.placeholder).end().end().find(f).children(a).removeClass(d),t.val("").trigger("change")},open:function(){t.triggerHandler(e),l(".qor-filter__dropdown").hide(),this.$selector.addClass("open"),this.isBottom&&this.$selector.addClass("bottom")},close:function(){this.$selector.removeClass("open"),this.isBottom&&this.$selector.removeClass("bottom")},destroy:function(){this.unbuild(),this.$element.removeData(r)}},m.DEFAULTS={aligned:"left",clearable:!1},m.TEMPLATE='',m.plugin=function(o){return this.each(function(){var t,e,i=l(this),n=i.data(r);if(!n){if(/destroy/.test(o))return;t=l.extend({},m.DEFAULTS,i.data(),"object"===_typeof(o)&&o),i.data(r,n=new m(this,t))}"string"==typeof o&&l.isFunction(e=n[o])&&e.apply(n)})},l(function(){var e='[data-toggle="qor.selector"]';l(document).on("disable.qor.selector",function(t){m.plugin.call(l(e,t.target),"destroy")}).on(i,function(t){m.plugin.call(l(e,t.target))}).triggerHandler(i)}),m}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(p){var t=p(document),l=window.FormData,m=window.QOR_Translations,o=window._,d=window.QOR,r="qor.slideout",e="keyup."+r,i="click."+r,n="submit."+r,y="shown."+r,g="hidden."+r,s="transitionend",a="qor-slideout-open",c="qor-slideout-mini",u="is-shown",h="is-slided",b=".qor-body__loading";function f(t,e){var i=[],n=e?"src":"href";return t.each(function(){i.push(p(this).attr(n))}),o.uniq(i)}function v(t,e,i){for(var n=0,o=0,r=t.length;o\s]+))?)+\s*|\s*)>/g))for(var r=0;r[\s\S]*<\s*\/body\s*>/gi);r&&(r=r.join("").replace(/<\s*body/gi," thead > tr > th",o.proxy(this.sort,this))},unbind:function(){this.$element.off(e,this.sort)},sort:function(t){var e=o(t.currentTarget).data("orderBy"),t=n.search,i="order_by="+e;e&&(/order_by/.test(t)?t=t.replace(/order_by(=\w+)?/,function(){return i}):t+=-1this.slideoutWidth&&this.$element.find(d).append(f.ARROW_RIGHT)},scrollTabLeft:function(t){t.stopPropagation();var e=o(d),i=e.scrollLeft(),t=i-this.slideoutWidth;0=i&&o(c).hide()}),o(u).length||this.$element.find(d).prepend(f.ARROW_LEFT))},switchTab:function(t){var e=o(t.target),i=this.$element,t=e.data(),n=r.data().tabScopeActive;if(o(".qor-slideout").is(":visible"))return e.hasClass(h)||(i.find(a).removeClass(h),e.addClass(h),o.ajax(t.tabUrl,{method:"GET",dataType:"html",processData:!1,contentType:!1,beforeSend:function(){o(".qor-layout__tab-spinner").remove();o(l).hide().before('
'),window.componentHandler.upgradeElement(o(".qor-layout__tab-spinner")[0])},success:function(t){o(".qor-layout__tab-spinner").remove(),r.data("tabScopeActive",e.data("name"));t=o(t).find(l).html();o(l).show().html(t).trigger("enable")},error:function(){o(".qor-layout__tab-spinner").remove(),r.data("tabScopeActive",n)}})),!1},destroy:function(){this.unbind(),r.removeData("tabScopeActive")}},f.ARROW_RIGHT='',f.ARROW_LEFT='',f.DEFAULTS={},f.plugin=function(n){return this.each(function(){var t,e=o(this),i=e.data(s);if(!i){if(/destroy/.test(n))return;e.data(s,i=new f(this,n))}"string"==typeof n&&o.isFunction(t=i[n])&&t.apply(i)})},o(function(){var e='[data-toggle="qor.tab"]';o(document).on("disable.qor.tabbar",function(t){f.plugin.call(o(e,t.target),"destroy")}).on(t,function(t){f.plugin.call(o(e,t.target))}).triggerHandler(t)}),f}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(r){var s="qor.timepicker",t="enable."+s,e="click."+s,i="focus."+s,n="keydown."+s,o="blur."+s,a="selectTime."+s,l="[data-picker-type]";function d(t,e){this.$element=r(t),this.options=r.extend(!0,{},d.DEFAULTS,r.isPlainObject(e)&&e),this.formatDate=null,this.pickerData=this.$element.data(),this.parent=this.$element.closest(l),this.isDateTimePicker="datetime"==this.parent.data("picker-type"),this.$targetInput=this.parent.find(this.pickerData.targetInput||(this.isDateTimePicker?".qor-datetimepicker__input":".qor-datepicker__input")),this.init()}return d.prototype={init:function(){var t,e,i;this.$targetInput.is(":disabled")?this.$element.remove():(this.bind(),this.oldValue=this.$targetInput.val(),e=(e=(t=new Date).getMonth()+1)<8?"0"+e:e,i=(i=t.getDate())<10?"0"+i:i,this.dateValueNow=t.getFullYear()+"-"+e+"-"+i)},bind:function(){this.isDateTimePicker&&this.$targetInput.qorTimepicker({timeFormat:"H:i",showOn:null,wrapHours:!1,scrollDefault:"now"}).on(a,r.proxy(this.changeTime,this)).on(o,r.proxy(this.blur,this)).on(i,r.proxy(this.focus,this)).on(n,r.proxy(this.keydown,this)),this.$element.on(e,r.proxy(this.show,this))},unbind:function(){this.$element.off(e,this.show),this.isDateTimePicker&&this.$targetInput.off(a,this.changeTime).off(o,this.blur).off(i,this.focus).off(n,this.keydown)},focus:function(){},blur:function(){var t,e,i,n,o,r,s=this.$targetInput.val(),a=s.split(" "),l=a.length,d=/\d{1,2}:\d{1,2}/,c=/^\d{4}-\d{1,2}-\d{1,2}/;if(s){if(1==l)c.test(a[0])&&(e=a[0],i="00:00"),d.test(a[0])&&(e=this.dateValueNow,i=a[0]);else for(var u=0;u endDate.getTime()) { + date = new Date(endDate); + } + + this.endDate = endDate; + } + + this.date = date; + this.viewDate = new Date(date); + this.initialDate = new Date(this.date); + + this.bind(); + + if (options.autoshow || this.isInline) { + this.show(); + } + + if (options.autopick) { + this.pick(); + } + }, + + build: function () { + var options = this.options; + var $this = this.$element; + var $picker; + + if (this.isBuilt) { + return; + } + + this.isBuilt = true; + + this.$picker = $picker = $(options.template); + this.$week = $picker.find('[data-view="week"]'); + + // Years view + this.$yearsPicker = $picker.find('[data-view="years picker"]'); + this.$yearsPrev = $picker.find('[data-view="years prev"]'); + this.$yearsNext = $picker.find('[data-view="years next"]'); + this.$yearsCurrent = $picker.find('[data-view="years current"]'); + this.$years = $picker.find('[data-view="years"]'); + + // Months view + this.$monthsPicker = $picker.find('[data-view="months picker"]'); + this.$yearPrev = $picker.find('[data-view="year prev"]'); + this.$yearNext = $picker.find('[data-view="year next"]'); + this.$yearCurrent = $picker.find('[data-view="year current"]'); + this.$months = $picker.find('[data-view="months"]'); + + // Days view + this.$daysPicker = $picker.find('[data-view="days picker"]'); + this.$monthPrev = $picker.find('[data-view="month prev"]'); + this.$monthNext = $picker.find('[data-view="month next"]'); + this.$monthCurrent = $picker.find('[data-view="month current"]'); + this.$days = $picker.find('[data-view="days"]'); + + if (this.isInline) { + $(options.container || $this).append($picker.addClass(CLASS_INLINE)); + } else { + $(document.body).append($picker.addClass(CLASS_DROPDOWN)); + $picker.addClass(CLASS_HIDE); + } + + this.fillWeek(); + }, + + unbuild: function () { + if (!this.isBuilt) { + return; + } + + this.isBuilt = false; + this.$picker.remove(); + }, + + bind: function () { + var options = this.options; + var $this = this.$element; + + if ($.isFunction(options.show)) { + $this.on(EVENT_SHOW, options.show); + } + + if ($.isFunction(options.hide)) { + $this.on(EVENT_HIDE, options.hide); + } + + if ($.isFunction(options.pick)) { + $this.on(EVENT_PICK, options.pick); + } + + if (this.isInput) { + $this.on(EVENT_KEYUP, $.proxy(this.keyup, this)); + + if (!options.trigger) { + $this.on(EVENT_FOCUS, $.proxy(this.show, this)); + } + } + + this.$trigger.on(EVENT_CLICK, $.proxy(this.show, this)); + }, + + unbind: function () { + var options = this.options; + var $this = this.$element; + + if ($.isFunction(options.show)) { + $this.off(EVENT_SHOW, options.show); + } + + if ($.isFunction(options.hide)) { + $this.off(EVENT_HIDE, options.hide); + } + + if ($.isFunction(options.pick)) { + $this.off(EVENT_PICK, options.pick); + } + + if (this.isInput) { + $this.off(EVENT_KEYUP, this.keyup); + + if (!options.trigger) { + $this.off(EVENT_FOCUS, this.show); + } + } + + this.$trigger.off(EVENT_CLICK, this.show); + }, + + showView: function (view) { + var $yearsPicker = this.$yearsPicker; + var $monthsPicker = this.$monthsPicker; + var $daysPicker = this.$daysPicker; + var format = this.format; + + if (format.hasYear || format.hasMonth || format.hasDay) { + switch (Number(view)) { + case 2: + case 'years': + $monthsPicker.addClass(CLASS_HIDE); + $daysPicker.addClass(CLASS_HIDE); + + if (format.hasYear) { + this.fillYears(); + $yearsPicker.removeClass(CLASS_HIDE); + } else { + this.showView(0); + } + + break; + + case 1: + case 'months': + $yearsPicker.addClass(CLASS_HIDE); + $daysPicker.addClass(CLASS_HIDE); + + if (format.hasMonth) { + this.fillMonths(); + $monthsPicker.removeClass(CLASS_HIDE); + } else { + this.showView(2); + } + + break; + + // case 0: + // case 'days': + default: + $yearsPicker.addClass(CLASS_HIDE); + $monthsPicker.addClass(CLASS_HIDE); + + if (format.hasDay) { + this.fillDays(); + $daysPicker.removeClass(CLASS_HIDE); + } else { + this.showView(1); + } + } + } + }, + + hideView: function () { + if (this.options.autohide) { + this.hide(); + } + }, + + place: function () { + var options = this.options; + var $this = this.$element; + var $picker = this.$picker; + var containerWidth = $document.outerWidth(); + var containerHeight = $document.outerHeight(); + var elementWidth = $this.outerWidth(); + var elementHeight = $this.outerHeight(); + var width = $picker.width(); + var height = $picker.height(); + var offsets = $this.offset(); + var left = offsets.left; + var top = offsets.top; + var offset = parseFloat(options.offset) || 10; + var placement = CLASS_TOP_LEFT; + + if (top > height && top + elementHeight + height > containerHeight) { + top -= height + offset; + placement = CLASS_BOTTOM_LEFT; + } else { + top += elementHeight + offset; + } + + if (left + width > containerWidth) { + left = left + elementWidth - width; + placement = placement.replace('left', 'right'); + } + + $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({ + top: top, + left: left, + zIndex: parseInt(options.zIndex, 10) + }); + }, + + // A shortcut for triggering custom events + trigger: function (type, data) { + var e = $.Event(type, data); + + this.$element.trigger(e); + + return e; + }, + + createItem: function (data) { + var options = this.options; + var itemTag = options.itemTag; + var defaults = { + text: '', + view: '', + muted: false, + picked: false, + disabled: false + }; + + $.extend(defaults, data); + + return ( + '<' + itemTag + ' ' + + (defaults.disabled ? 'class="' + options.disabledClass + '"' : + defaults.picked ? 'class="' + options.pickedClass + '"' : + defaults.muted ? 'class="' + options.mutedClass + '"' : '') + + (defaults.view ? ' data-view="' + defaults.view + '"' : '') + + '>' + + defaults.text + + '' + ); + }, + + fillAll: function () { + this.fillYears(); + this.fillMonths(); + this.fillDays(); + }, + + fillWeek: function () { + var options = this.options; + var weekStart = parseInt(options.weekStart, 10) % 7; + var days = options.daysMin; + var list = ''; + var i; + + days = $.merge(days.slice(weekStart), days.slice(0, weekStart)); + + for (i = 0; i <= 6; i++) { + list += this.createItem({ + text: days[i] + }); + } + + this.$week.html(list); + }, + + fillYears: function () { + var options = this.options; + var disabledClass = options.disabledClass || ''; + var suffix = options.yearSuffix || ''; + var filter = $.isFunction(options.filter) && options.filter; + var startDate = this.startDate; + var endDate = this.endDate; + var viewDate = this.viewDate; + var viewYear = viewDate.getFullYear(); + var viewMonth = viewDate.getMonth(); + var viewDay = viewDate.getDate(); + var date = this.date; + var year = date.getFullYear(); + var isPrevDisabled = false; + var isNextDisabled = false; + var isDisabled = false; + var isPicked = false; + var isMuted = false; + var list = ''; + var start = -5; + var end = 6; + var i; + + for (i = start; i <= end; i++) { + date = new Date(viewYear + i, viewMonth, viewDay); + isMuted = i === start || i === end; + isPicked = (viewYear + i) === year; + isDisabled = false; + + if (startDate) { + isDisabled = date.getFullYear() < startDate.getFullYear(); + + if (i === start) { + isPrevDisabled = isDisabled; + } + } + + if (!isDisabled && endDate) { + isDisabled = date.getFullYear() > endDate.getFullYear(); + + if (i === end) { + isNextDisabled = isDisabled; + } + } + + if (!isDisabled && filter) { + isDisabled = filter.call(this.$element, date) === false; + } + + list += this.createItem({ + text: viewYear + i, + view: isDisabled ? 'year disabled' : isPicked ? 'year picked' : 'year', + muted: isMuted, + picked: isPicked, + disabled: isDisabled + }); + } + + this.$yearsPrev.toggleClass(disabledClass, isPrevDisabled); + this.$yearsNext.toggleClass(disabledClass, isNextDisabled); + this.$yearsCurrent. + toggleClass(disabledClass, true). + html((viewYear + start) + suffix + ' - ' + (viewYear + end) + suffix); + this.$years.html(list); + }, + + fillMonths: function () { + var options = this.options; + var disabledClass = options.disabledClass || ''; + var months = options.monthsShort; + var filter = $.isFunction(options.filter) && options.filter; + var startDate = this.startDate; + var endDate = this.endDate; + var viewDate = this.viewDate; + var viewYear = viewDate.getFullYear(); + var viewDay = viewDate.getDate(); + var date = this.date; + var year = date.getFullYear(); + var month = date.getMonth(); + var isPrevDisabled = false; + var isNextDisabled = false; + var isDisabled = false; + var isPicked = false; + var list = ''; + var i; + + for (i = 0; i <= 11; i++) { + date = new Date(viewYear, i, viewDay); + isPicked = viewYear === year && i === month; + isDisabled = false; + + if (startDate) { + isPrevDisabled = date.getFullYear() === startDate.getFullYear(); + isDisabled = isPrevDisabled && date.getMonth() < startDate.getMonth(); + } + + if (!isDisabled && endDate) { + isNextDisabled = date.getFullYear() === endDate.getFullYear(); + isDisabled = isNextDisabled && date.getMonth() > endDate.getMonth(); + } + + if (!isDisabled && filter) { + isDisabled = filter.call(this.$element, date) === false; + } + + list += this.createItem({ + index: i, + text: months[i], + view: isDisabled ? 'month disabled' : isPicked ? 'month picked' : 'month', + picked: isPicked, + disabled: isDisabled + }); + } + + this.$yearPrev.toggleClass(disabledClass, isPrevDisabled); + this.$yearNext.toggleClass(disabledClass, isNextDisabled); + this.$yearCurrent. + toggleClass(disabledClass, isPrevDisabled && isNextDisabled). + html(viewYear + options.yearSuffix || ''); + this.$months.html(list); + }, + + fillDays: function () { + var options = this.options; + var disabledClass = options.disabledClass || ''; + var suffix = options.yearSuffix || ''; + var months = options.monthsShort; + var weekStart = parseInt(options.weekStart, 10) % 7; + var filter = $.isFunction(options.filter) && options.filter; + var startDate = this.startDate; + var endDate = this.endDate; + var viewDate = this.viewDate; + var viewYear = viewDate.getFullYear(); + var viewMonth = viewDate.getMonth(); + var prevViewYear = viewYear; + var prevViewMonth = viewMonth; + var nextViewYear = viewYear; + var nextViewMonth = viewMonth; + var date = this.date; + var year = date.getFullYear(); + var month = date.getMonth(); + var day = date.getDate(); + var isPrevDisabled = false; + var isNextDisabled = false; + var isDisabled = false; + var isPicked = false; + var prevItems = []; + var nextItems = []; + var items = []; + var total = 42; // 6 rows and 7 columns on the days picker + var length; + var i; + var n; + + // Days of previous month + // ----------------------------------------------------------------------- + + if (viewMonth === 0) { + prevViewYear -= 1; + prevViewMonth = 11; + } else { + prevViewMonth -= 1; + } + + // The length of the days of previous month + length = getDaysInMonth(prevViewYear, prevViewMonth); + + // The first day of current month + date = new Date(viewYear, viewMonth, 1); + + // The visible length of the days of previous month + // [0,1,2,3,4,5,6] - [0,1,2,3,4,5,6] => [-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6] + n = date.getDay() - weekStart; + + // [-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6] => [1,2,3,4,5,6,7] + if (n <= 0) { + n += 7; + } + + if (startDate) { + isPrevDisabled = date.getTime() <= startDate.getTime(); + } + + for (i = length - (n - 1); i <= length; i++) { + date = new Date(prevViewYear, prevViewMonth, i); + isDisabled = false; + + if (startDate) { + isDisabled = date.getTime() < startDate.getTime(); + } + + if (!isDisabled && filter) { + isDisabled = filter.call(this.$element, date) === false; + } + + prevItems.push(this.createItem({ + text: i, + view: 'day prev', + muted: true, + disabled: isDisabled + })); + } + + // Days of next month + // ----------------------------------------------------------------------- + + if (viewMonth === 11) { + nextViewYear += 1; + nextViewMonth = 0; + } else { + nextViewMonth += 1; + } + + // The length of the days of current month + length = getDaysInMonth(viewYear, viewMonth); + + // The visible length of next month + n = total - (prevItems.length + length); + + // The last day of current month + date = new Date(viewYear, viewMonth, length); + + if (endDate) { + isNextDisabled = date.getTime() >= endDate.getTime(); + } + + for (i = 1; i <= n; i++) { + date = new Date(nextViewYear, nextViewMonth, i); + isDisabled = false; + + if (endDate) { + isDisabled = date.getTime() > endDate.getTime(); + } + + if (!isDisabled && filter) { + isDisabled = filter.call(this.$element, date) === false; + } + + nextItems.push(this.createItem({ + text: i, + view: 'day next', + muted: true, + disabled: isDisabled + })); + } + + // Days of current month + // ----------------------------------------------------------------------- + + for (i = 1; i <= length; i++) { + date = new Date(viewYear, viewMonth, i); + isPicked = viewYear === year && viewMonth === month && i === day; + isDisabled = false; + + if (startDate) { + isDisabled = date.getTime() < startDate.getTime(); + } + + if (!isDisabled && endDate) { + isDisabled = date.getTime() > endDate.getTime(); + } + + if (!isDisabled && filter) { + isDisabled = filter.call(this.$element, date) === false; + } + + items.push(this.createItem({ + text: i, + view: isDisabled ? 'day disabled' : isPicked ? 'day picked' : 'day', + picked: isPicked, + disabled: isDisabled + })); + } + + // Render days picker + // ----------------------------------------------------------------------- + + this.$monthPrev.toggleClass(disabledClass, isPrevDisabled); + this.$monthNext.toggleClass(disabledClass, isNextDisabled); + this.$monthCurrent. + toggleClass(disabledClass, isPrevDisabled && isNextDisabled). + html( + options.yearFirst ? + viewYear + suffix + ' ' + months[viewMonth] : + months[viewMonth] + ' ' + viewYear + suffix + ); + this.$days.html(prevItems.join('') + items.join(' ') + nextItems.join('')); + }, + + click: function (e) { + var $target = $(e.target); + var viewDate = this.viewDate; + var viewYear; + var viewMonth; + var viewDay; + var isYear; + var year; + var view; + + e.stopPropagation(); + e.preventDefault(); + + if ($target.hasClass('disabled')) { + return; + } + + viewYear = viewDate.getFullYear(); + viewMonth = viewDate.getMonth(); + viewDay = viewDate.getDate(); + view = $target.data('view'); + + switch (view) { + case 'years prev': + case 'years next': + viewYear = view === 'years prev' ? viewYear - 10 : viewYear + 10; + year = $target.text(); + isYear = REGEXP_YEAR.test(year); + + if (isYear) { + viewYear = parseInt(year, 10); + this.date = new Date(viewYear, viewMonth, min(viewDay, 28)); + } + + this.viewDate = new Date(viewYear, viewMonth, min(viewDay, 28)); + this.fillYears(); + + if (isYear) { + this.showView(1); + this.pick('year'); + } + + break; + + case 'year prev': + case 'year next': + viewYear = view === 'year prev' ? viewYear - 1 : viewYear + 1; + this.viewDate = new Date(viewYear, viewMonth, min(viewDay, 28)); + this.fillMonths(); + break; + + case 'year current': + + if (this.format.hasYear) { + this.showView(2); + } + + break; + + case 'year picked': + + if (this.format.hasMonth) { + this.showView(1); + } else { + this.hideView(); + } + + break; + + case 'year': + viewYear = parseInt($target.text(), 10); + this.date = new Date(viewYear, viewMonth, min(viewDay, 28)); + this.viewDate = new Date(viewYear, viewMonth, min(viewDay, 28)); + + if (this.format.hasMonth) { + this.showView(1); + } else { + this.hideView(); + } + + this.pick('year'); + break; + + case 'month prev': + case 'month next': + viewMonth = view === 'month prev' ? viewMonth - 1 : view === 'month next' ? viewMonth + 1 : viewMonth; + this.viewDate = new Date(viewYear, viewMonth, min(viewDay, 28)); + this.fillDays(); + break; + + case 'month current': + + if (this.format.hasMonth) { + this.showView(1); + } + + break; + + case 'month picked': + + if (this.format.hasDay) { + this.showView(0); + } else { + this.hideView(); + } + + break; + + case 'month': + viewMonth = $.inArray($target.text(), this.options.monthsShort); + this.date = new Date(viewYear, viewMonth, min(viewDay, 28)); + this.viewDate = new Date(viewYear, viewMonth, min(viewDay, 28)); + + if (this.format.hasDay) { + this.showView(0); + } else { + this.hideView(); + } + + this.pick('month'); + break; + + case 'day prev': + case 'day next': + case 'day': + viewMonth = view === 'day prev' ? viewMonth - 1 : view === 'day next' ? viewMonth + 1 : viewMonth; + viewDay = parseInt($target.text(), 10); + this.date = new Date(viewYear, viewMonth, viewDay); + this.viewDate = new Date(viewYear, viewMonth, viewDay); + this.fillDays(); + + if (view === 'day') { + this.hideView(); + } + + this.pick('day'); + break; + + case 'day picked': + this.hideView(); + this.pick('day'); + break; + + // No default + } + }, + + clickDoc: function (e) { + var target = e.target; + var trigger = this.$trigger[0]; + var ignored; + + while (target !== document) { + if (target === trigger) { + ignored = true; + break; + } + + target = target.parentNode; + } + + if (!ignored) { + this.hide(); + } + }, + + keyup: function () { + this.update(); + }, + + getValue: function () { + var $this = this.$element; + var val = ''; + + if (this.isInput) { + val = $this.val(); + } else if (this.isInline) { + if (this.options.container) { + val = $this.text(); + } + } else { + val = $this.text(); + } + + return val; + }, + + setValue: function (val) { + var $this = this.$element; + + val = isString(val) ? val : ''; + + if (this.isInput) { + $this.val(val); + } else if (this.isInline) { + if (this.options.container) { + $this.text(val); + } + } else { + $this.text(val); + } + }, + + + // Methods + // ------------------------------------------------------------------------- + + // Show the datepicker + show: function () { + if (!this.isBuilt) { + this.build(); + } + + if (this.isShown) { + return; + } + + if (this.trigger(EVENT_SHOW).isDefaultPrevented()) { + return; + } + + this.isShown = true; + this.$picker.removeClass(CLASS_HIDE).on(EVENT_CLICK, $.proxy(this.click, this)); + this.showView(this.options.startView); + + if (!this.isInline) { + $window.on(EVENT_RESIZE, (this._place = proxy(this.place, this))); + $document.on(EVENT_CLICK, (this._clickDoc = proxy(this.clickDoc, this))); + this.place(); + } + }, + + // Hide the datepicker + hide: function () { + if (!this.isShown) { + return; + } + + if (this.trigger(EVENT_HIDE).isDefaultPrevented()) { + return; + } + + this.isShown = false; + this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click); + + if (!this.isInline) { + $window.off(EVENT_RESIZE, this._place); + $document.off(EVENT_CLICK, this._clickDoc); + } + }, + + // Update the datepicker with the current input value + update: function () { + this.setDate(this.getValue(), true); + }, + + /** + * Pick the current date to the element + * + * @param {String} _view (private) + */ + pick: function (_view) { + var $this = this.$element; + var date = this.date; + + if (this.trigger(EVENT_PICK, { + view: _view || '', + date: date + }).isDefaultPrevented()) { + return; + } + + this.setValue(date = this.formatDate(this.date)); + + if (this.isInput) { + $this.trigger('change'); + } + }, + + // Reset the datepicker + reset: function () { + this.setDate(this.initialDate, true); + this.setValue(this.initialValue); + + if (this.isShown) { + this.showView(this.options.startView); + } + }, + + /** + * Get the month name with given argument or the current date + * + * @param {Number} month (optional) + * @param {Boolean} short (optional) + * @return {String} (month name) + */ + getMonthName: function (month, short) { + var options = this.options; + var months = options.months; + + if ($.isNumeric(month)) { + month = Number(month); + } else if (isUndefined(short)) { + short = month; + } + + if (short === true) { + months = options.monthsShort; + } + + return months[isNumber(month) ? month : this.date.getMonth()]; + }, + + /** + * Get the day name with given argument or the current date + * + * @param {Number} day (optional) + * @param {Boolean} short (optional) + * @param {Boolean} min (optional) + * @return {String} (day name) + */ + getDayName: function (day, short, min) { + var options = this.options; + var days = options.days; + + if ($.isNumeric(day)) { + day = Number(day); + } else { + if (isUndefined(min)) { + min = short; + } + + if (isUndefined(short)) { + short = day; + } + } + + days = min === true ? options.daysMin : short === true ? options.daysShort : days; + + return days[isNumber(day) ? day : this.date.getDay()]; + }, + + /** + * Get the current date + * + * @param {Boolean} formated (optional) + * @return {Date|String} (date) + */ + getDate: function (formated) { + var date = this.date; + + return formated ? this.formatDate(date) : new Date(date); + }, + + /** + * Set the current date with a new date + * + * @param {Date} date + * @param {Boolean} _isUpdated (private) + */ + setDate: function (date, _isUpdated) { + var filter = this.options.filter; + + if (isDate(date) || isString(date)) { + date = this.parseDate(date); + + if ($.isFunction(filter) && filter.call(this.$element, date) === false) { + return; + } + + this.date = date; + this.viewDate = new Date(date); + + if (!_isUpdated) { + this.pick(); + } + + if (this.isBuilt) { + this.fillAll(); + } + } + }, + + /** + * Set the start view date with a new date + * + * @param {Date} date + */ + setStartDate: function (date) { + if (isDate(date) || isString(date)) { + this.startDate = this.parseDate(date); + + if (this.isBuilt) { + this.fillAll(); + } + } + }, + + /** + * Set the end view date with a new date + * + * @param {Date} date + */ + setEndDate: function (date) { + if (isDate(date) || isString(date)) { + this.endDate = this.parseDate(date); + + if (this.isBuilt) { + this.fillAll(); + } + } + }, + + /** + * Parse a date string with the set date format + * + * @param {String} date + * @return {Date} (parsed date) + */ + parseDate: function (date) { + var format = this.format; + var parts = []; + var length; + var year; + var day; + var month; + var val; + var i; + + if (isDate(date)) { + return new Date(date.getFullYear(), date.getMonth(), date.getDate()); + } else if (isString(date)) { + parts = date.match(REGEXP_DIGITS) || []; + } + + date = new Date(); + year = date.getFullYear(); + day = date.getDate(); + month = date.getMonth(); + length = format.parts.length; + + if (parts.length === length) { + for (i = 0; i < length; i++) { + val = parseInt(parts[i], 10) || 1; + + switch (format.parts[i]) { + case 'dd': + case 'd': + day = val; + break; + + case 'mm': + case 'm': + month = val - 1; + break; + + case 'yy': + year = 2000 + val; + break; + + case 'yyyy': + year = val; + break; + + // No default + } + } + } + + return new Date(year, month, day); + }, + + /** + * Format a date object to a string with the set date format + * + * @param {Date} date + * @return {String} (formated date) + */ + formatDate: function (date) { + var format = this.format; + var formated = ''; + var length; + var year; + var part; + var val; + var i; + + if (isDate(date)) { + formated = format.source; + year = date.getFullYear(); + val = { + d: date.getDate(), + m: date.getMonth() + 1, + yy: year.toString().substring(2), + yyyy: year + }; + + val.dd = (val.d < 10 ? '0' : '') + val.d; + val.mm = (val.m < 10 ? '0' : '') + val.m; + length = format.parts.length; + + for (i = 0; i < length; i++) { + part = format.parts[i]; + formated = formated.replace(part, val[part]); + } + } + + return formated; + }, + + // Destroy the datepicker and remove the instance from the target element + destroy: function () { + this.unbind(); + this.unbuild(); + this.$element.removeData(NAMESPACE); + } + }; + + Datepicker.LANGUAGES = {}; + + Datepicker.DEFAULTS = { + // Show the datepicker automatically when initialized + autoshow: false, + + // Hide the datepicker automatically when picked + autohide: false, + + // Pick the initial date automatically when initialized + autopick: false, + + // Enable inline mode + inline: false, + + // A element (or selector) for putting the datepicker + container: null, + + // A element (or selector) for triggering the datepicker + trigger: null, + + // The ISO language code (built-in: en-US) + language: '', + + // The date string format + format: 'yyyy-mm-dd', + + // The initial date + date: null, + + // The start view date + startDate: null, + + // The end view date + endDate: null, + + // The start view when initialized + startView: 0, // 0 for days, 1 for months, 2 for years + + // The start day of the week + weekStart: 0, // 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, 4 for Thursday, 5 for Friday, 6 for Saturday + + // Show year before month on the datepicker header + yearFirst: false, + + // A string suffix to the year number. + yearSuffix: '', + + // Days' name of the week. + days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], + + // Shorter days' name + daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], + + // Shortest days' name + daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], + + // Months' name + months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + + // Shorter months' name + monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], + + // A element tag for each item of years, months and days + itemTag: 'li', + + // A class (CSS) for muted date item + mutedClass: 'muted', + + // A class (CSS) for picked date item + pickedClass: 'picked', + + // A class (CSS) for disabled date item + disabledClass: 'disabled', + + // The template of the datepicker + template: ( + '
' + + '
' + + '
    ' + + '
  • ' + + '
  • ' + + '
  • ' + + '
' + + '
    ' + + '
    ' + + '
    ' + + '
      ' + + '
    • ' + + '
    • ' + + '
    • ' + + '
    ' + + '
      ' + + '
      ' + + '
      ' + + '
        ' + + '
      • ' + + '
      • ' + + '
      • ' + + '
      ' + + '
        ' + + '
          ' + + '
          ' + + '
          ' + ), + + // The offset top or bottom of the datepicker from the element + offset: 10, + + // The `z-index` of the datepicker + zIndex: 1000, + + // Filter each date item (return `false` to disable a date item) + filter: null, + + // Event shortcuts + show: null, + hide: null, + pick: null + }; + + Datepicker.setDefaults = function (options) { + $.extend(Datepicker.DEFAULTS, $.isPlainObject(options) && options); + }; + + // Save the other datepicker + Datepicker.other = $.fn.qorDatepicker; + + // Register as jQuery plugin + $.fn.qorDatepicker = function (option) { + var args = toArray(arguments, 1); + var result; + + this.each(function () { + var $this = $(this); + var data = $this.data(NAMESPACE); + var options; + var fn; + + if (!data) { + if (/destroy/.test(option)) { + return; + } + + options = $.extend({}, $this.data(), $.isPlainObject(option) && option); + $this.data(NAMESPACE, (data = new Datepicker(this, options))); + } + + if (isString(option) && $.isFunction(fn = data[option])) { + result = fn.apply(data, args); + } + }); + + return isUndefined(result) ? this : result; + }; + + $.fn.qorDatepicker.Constructor = Datepicker; + $.fn.qorDatepicker.languages = Datepicker.LANGUAGES; + $.fn.qorDatepicker.setDefaults = Datepicker.setDefaults; + + // No conflict + $.fn.qorDatepicker.noConflict = function () { + $.fn.qorDatepicker = Datepicker.other; + return this; + }; + +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-action.js b/app/views/qor/assets/javascripts/qor/qor-action.js new file mode 100644 index 0000000..ee02664 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-action.js @@ -0,0 +1,408 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + let Mustache = window.Mustache, + QOR = window.QOR, + NAMESPACE = 'qor.action', + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_UNDO = 'undo.' + NAMESPACE, + CLASS_ACTION_FORMS = '.qor-action-forms', + CLASS_MENU_ACTIONS = '[data-ajax-form="true"][data-method]', + CLASS_BUTTON_BULKS = '.qor-action-bulk-buttons', + CLASS_TABLE = '.qor-page .qor-table-container', + CLASS_TABLE_BULK = '.qor-table--bulking', + CLASS_TABLE_BULK_TR = '.qor-table--bulking tbody tr', + CLASS_IS_UNDO = 'is_undo', + CLASS_TABLE_MDL = 'mdl-data-table--selectable', + CLASS_SLIDEOUT = '.qor-slideout', + ACTION_FORM_DATA = 'primary_values[]', + CLASS_HEADER_TOGGLE = '.qor-page__header .qor-actions, .qor-page__header .qor-search-container', + CLASS_BODY_LOADING = ".qor-body__loading"; + + function QorAction(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorAction.DEFAULTS, $.isPlainObject(options) && options); + this.ajaxForm = {}; + this.init(); + } + + QorAction.prototype = { + constructor: QorAction, + + init: function() { + this.bind(); + this.initActions(); + }, + + bind: function() { + this.$element.on(EVENT_CLICK, '.qor-action--bulk', this.renderBulkTable.bind(this)).on(EVENT_CLICK, '.qor-action--exit-bulk', this.removeBulkTable.bind(this)); + + $(document) + .on(EVENT_CLICK, CLASS_TABLE_BULK_TR, this.handleBulkTableClick.bind(this)) + .on(EVENT_CLICK, CLASS_MENU_ACTIONS, this.clickAjaxButton.bind(this)); + }, + + unbind: function() { + this.$element.off(EVENT_CLICK); + + $(document) + .off(EVENT_CLICK, CLASS_TABLE_BULK_TR, this.handleBulkTableClick) + .off(EVENT_CLICK, CLASS_MENU_ACTIONS, this.clickAjaxButton); + }, + + initActions: function() { + if (!$(CLASS_TABLE).find('table').length) { + $(CLASS_BUTTON_BULKS).hide(); + $('.qor-page__header a.qor-action--button').hide(); + } + }, + + collectFormData: function() { + let checkedInputs = $(CLASS_TABLE_BULK).find('.mdl-checkbox__input:checked'), + formData = [], + normalFormData = [], + tempObj; + + if (checkedInputs.length) { + checkedInputs.each(function() { + let id = $(this) + .closest('tr') + .data('primary-key'); + + tempObj = {}; + if (id) { + formData.push({ + name: ACTION_FORM_DATA, + value: id.toString() + }); + + tempObj[ACTION_FORM_DATA] = id.toString(); + normalFormData.push(tempObj); + } + }); + } + this.ajaxForm.formData = formData; + this.ajaxForm.normalFormData = normalFormData; + return this.ajaxForm; + }, + + actionSubmit: function($action) { + this.submit($action); + return false; + }, + + handleBulkTableClick: function(e) { + let $target = $(e.target).closest('tr'), + $firstTd = $target.find('td').first(), + $checkbox = $firstTd.find('.mdl-js-checkbox'); + + $checkbox.toggleClass('is-checked'); + $target.toggleClass('is-selected'); + $firstTd.find('input').prop('checked', $checkbox.hasClass('is-checked')); + + return false; + }, + + adjustPageBodyStyle: function(isRender) { + let $pageHeader = $('.qor-page > .qor-page__header'), + $pageBody = $('.qor-page > .qor-page__body'), + triggerHeight = $pageHeader.find('.qor-page-subnav__header').length ? 96 : 48; + + if (isRender) { + if ($pageHeader.height() > triggerHeight) { + $pageBody.css('padding-top', $pageHeader.height()); + } + } else { + if (parseInt($pageBody.css('padding-top')) > triggerHeight) { + $pageBody.css('padding-top', ''); + } + } + }, + + renderBulkTable: function() { + let $body = $('body'); + + if ($body.hasClass('qor-slideout-open')) { + $body.data('qor.slideout').hide(); + } + + $('.qor-table__inner-list').remove(); + this.toggleBulkButtons(); + this.enableTableMDL(); + this.adjustPageBodyStyle(true); + }, + + removeBulkTable: function() { + this.toggleBulkButtons(); + this.disableTableMDL(); + this.adjustPageBodyStyle(); + }, + + enableTableMDL: function() { + $(CLASS_TABLE) + .find('table') + .removeAttr('data-upgraded') + .addClass(CLASS_TABLE_MDL) + .trigger('enable'); + }, + + disableTableMDL: function() { + $(CLASS_TABLE) + .find('table') + .removeClass(CLASS_TABLE_MDL) + .find('tr') + .removeClass('is-selected') + .find('td:first,th:first') + .remove(); + }, + + toggleBulkButtons: function() { + this.$element.find(CLASS_ACTION_FORMS).toggle(); + $(CLASS_BUTTON_BULKS) + .find('button') + .toggleClass('hidden'); + + $(CLASS_TABLE) + .toggleClass('qor-table--bulking') + .find('.qor-table__actions') + .toggle(); + + $(CLASS_HEADER_TOGGLE).toggle(); + }, + + clickAjaxButton: function(e) { + let $target = $(e.target); + + this.collectFormData(); + this.ajaxForm.properties = $target.data(); + this.submit($target); + return false; + }, + + renderFlashMessage: function(data) { + let flashMessageTmpl = QorAction.FLASHMESSAGETMPL; + Mustache.parse(flashMessageTmpl); + return Mustache.render(flashMessageTmpl, data); + }, + + addLoading: function() { + $(CLASS_BODY_LOADING).remove(); + var $loading = $(QorAction.TEMPLATE_LOADING); + $loading.appendTo($("body")).trigger("enable.qor.material"); + }, + + submit: function($actionButton) { + let _this = this, + ajaxForm = this.ajaxForm || {}, + properties = ajaxForm.properties || $actionButton.data(); + + + if($actionButton.hasClass("qor-action-disabled")){ + return false; + } + + if (properties.fromIndex && (!ajaxForm.formData || !ajaxForm.formData.length)) { + QOR.qorConfirm(ajaxForm.properties.errorNoItem); + return; + } + + if (properties.confirm) { + QOR.qorConfirm(properties, function(confirm) { + if (confirm) { + _this.handleAjaxSubmit(ajaxForm, $actionButton); + } else { + return; + } + }); + } else { + this.handleAjaxSubmit(ajaxForm, $actionButton); + } + }, + + handleAjaxSubmit: function(ajaxForm, $actionButton) { + let _this = this, + $element = this.$element, + $parent = $actionButton.closest(".qor-action-forms"), + properties = ajaxForm.properties || $actionButton.data(), + url = properties.url, + undoUrl = properties.undoUrl, + isUndo = $actionButton.hasClass(CLASS_IS_UNDO), + isInSlideout = $actionButton.closest(CLASS_SLIDEOUT).length, + needDisableButtons = $element.length && !isInSlideout; + + if (isUndo) { + url = undoUrl; // notification has undo url + } + + this.addLoading(); + if($parent.length){ + $parent.find('[data-ajax-form="true"][data-method]').addClass("qor-action-disabled"); + } else { + $actionButton.addClass("qor-action-disabled"); + } + + + $.ajax(url, { + method: properties.method, + data: ajaxForm.formData, + dataType: properties.datatype || 'json', + beforeSend: function() { + if (undoUrl) { + $actionButton.prop('disabled', true); + } else if (needDisableButtons) { + _this.switchButtons($element, 1); + } + + }, + success: function(data) { + // has undo action + if (undoUrl) { + $element.trigger(EVENT_UNDO, [$actionButton, isUndo, data]); + isUndo ? $actionButton.removeClass(CLASS_IS_UNDO) : $actionButton.addClass(CLASS_IS_UNDO); + $actionButton.prop('disabled', false); + return; + } + + window.location.reload(); + }, + error: function(err) { + if (err.status == 200) { + return; + } + if (undoUrl) { + $actionButton.prop('disabled', false); + } else if (needDisableButtons) { + _this.switchButtons($element); + } + + QOR.handleAjaxError(err); + }, + complete: function(response) { + let contentType = response.getResponseHeader('content-type'), + disposition = response.getResponseHeader('Content-Disposition'); + + $(CLASS_BODY_LOADING).remove(); + $actionButton.prop('disabled', false); + if($parent.length){ + $parent.find('[data-ajax-form="true"][data-method]').removeClass("qor-action-disabled"); + } else { + $actionButton.removeClass("qor-action-disabled"); + } + + // handle file download from form submit + if (disposition && disposition.indexOf('attachment') !== -1) { + var fileNameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/, + matches = fileNameRegex.exec(disposition), + fileData = {}, + fileName = ''; + + if (matches != null && matches[1]) { + fileName = matches[1].replace(/['"]/g, ''); + } + + if (properties.method) { + fileData = $.extend({}, ajaxForm.normalFormData, { + _method: properties.method + }); + } + + QOR.qorAjaxHandleFile(url, contentType, fileName, fileData); + + if (undoUrl) { + $actionButton.prop('disabled', false); + } else { + _this.switchButtons($element); + } + } + } + }); + }, + + switchButtons: function($element, disbale) { + let needDisbale = disbale ? true : false; + $element.find('.qor-action-button').prop('disabled', needDisbale); + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorAction.DEFAULTS = {}; + + QorAction.TEMPLATE_LOADING = `
          +
          +
          +
          `; + + $.fn.qorSliderAfterShow.qorInsertActionData = function(url, html) { + let $action = $(html).find('[data-toggle="qor-action-slideout"]'), + $actionForm = $action.find('form'), + $checkedItem = $(CLASS_TABLE_BULK).find('.mdl-checkbox__input:checked'); + + if ($action.length && $checkedItem.length) { + // insert checked value into sliderout form + $checkedItem.each(function() { + let id = $(this) + .closest('tr') + .data('primary-key'); + + if (id) { + $actionForm.prepend(''); + } + }); + } + }; + + QorAction.plugin = function(options) { + return this.each(function() { + let $this = $(this), + data = $this.data(NAMESPACE), + fn; + + if (!data) { + $this.data(NAMESPACE, (data = new QorAction(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.call(data); + } + }); + }; + + $(function() { + let options = {}, + selector = '[data-toggle="qor.action.bulk"]'; + + if (!$(selector).length) { + $(document).on(EVENT_CLICK, CLASS_MENU_ACTIONS, function(e) { + new QorAction().actionSubmit($(e.target)); + return false; + }); + } + + $(document) + .on(EVENT_DISABLE, function(e) { + QorAction.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorAction.plugin.call($(selector, e.target), options); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorAction; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-advanced-search.js b/app/views/qor/assets/javascripts/qor/qor-advanced-search.js new file mode 100644 index 0000000..10ddb37 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-advanced-search.js @@ -0,0 +1,272 @@ +(function(factory) { + if (typeof define === "function" && define.amd) { + // AMD. Register as anonymous module. + define(["jquery"], factory); + } else if (typeof exports === "object") { + // Node / CommonJS + factory(require("jquery")); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + "use strict"; + + let location = window.location, + QOR = window.QOR, + NAMESPACE = "qor.advancedsearch", + EVENT_ENABLE = "enable." + NAMESPACE, + EVENT_DISABLE = "disable." + NAMESPACE, + EVENT_CLICK = "click." + NAMESPACE, + EVENT_SHOWN = "shown.qor.modal", + EVENT_SUBMIT = "submit." + NAMESPACE; + + function getExtraPairs(names) { + let pairs = decodeURIComponent(location.search.substr(1)).split("&"), + pairsObj = {}, + pair, + i; + + if (pairs.length == 1 && pairs[0] == "") { + return false; + } + + for (i in pairs) { + if (pairs[i] === "") continue; + + pair = pairs[i].split("="); + pairsObj[pair[0]] = pair[1]; + } + + names.forEach(function(item) { + delete pairsObj[item]; + }); + + return pairsObj; + } + + function QorAdvancedSearch(element, options) { + this.$element = $(element); + this.options = $.extend( + {}, + QorAdvancedSearch.DEFAULTS, + $.isPlainObject(options) && options + ); + this.init(); + } + + QorAdvancedSearch.prototype = { + constructor: QorAdvancedSearch, + + init: function() { + this.$form = this.$element.find("form"); + this.$modal = $(QorAdvancedSearch.MODAL).appendTo("body"); + this.bind(); + }, + + bind: function() { + this.$element + .on(EVENT_SUBMIT, "form", this.submit.bind(this)) + .on( + EVENT_CLICK, + ".qor-advanced-filter__save", + this.showSaveFilter.bind(this) + ) + .on( + EVENT_CLICK, + ".qor-advanced-filter__toggle", + this.toggleFilterContent + ) + .on(EVENT_CLICK, ".qor-advanced-filter__close", this.closeFilter) + .on( + EVENT_CLICK, + ".qor-advanced-filter__delete", + this.deleteSavedFilter + ); + + this.$modal.on(EVENT_SHOWN, this.start.bind(this)); + }, + + closeFilter: function() { + $(".qor-advanced-filter__dropdown").hide(); + }, + + toggleFilterContent: function(e) { + $(e.target) + .closest(".qor-advanced-filter__toggle") + .parent() + .find(">[advanced-search-toggle]") + .toggle(); + }, + + showSaveFilter: function() { + this.$modal.qorModal("show"); + }, + + deleteSavedFilter: function(e) { + let $target = $(e.target).closest(".qor-advanced-filter__delete"), + $savedFilter = $target.closest(".qor-advanced-filter__savedfilter"), + name = $target.data("filter-name"), + url = location.pathname, + message = { + confirm: "Are you sure you want to delete this saved filter?" + }; + + QOR.qorConfirm(message, function(confirm) { + if (confirm) { + $.get(url, $.param({ delete_saved_filter: name })) + .done(function() { + $target.closest("li").remove(); + if ($savedFilter.find("li").length === 0) { + $savedFilter.remove(); + } + }) + .fail(function() { + QOR.qorConfirm("Server error, please try again!"); + }); + } + }); + return false; + }, + + start: function() { + this.$modal + .trigger("enable.qor.material") + .on( + EVENT_CLICK, + ".qor-advanced-filter__savefilter", + this.saveFilter.bind(this) + ); + }, + + saveFilter: function() { + let name = this.$modal.find("#qor-advanced-filter__savename").val(); + + if (!name) { + return; + } + + this.$form + .prepend( + `` + ) + .submit(); + }, + + submit: function() { + let $form = this.$form, + formArr = $form.find("input[name],select[name]"), + names = [], + extraPairs, + $bottomsheet = $form.closest(".qor-bottomsheets"), + params = $form.serialize(); + + formArr.each(function() { + names.push($(this).attr("name")); + }); + + extraPairs = getExtraPairs(names); + + if (!$.isEmptyObject(extraPairs)) { + for (let key in extraPairs) { + if (extraPairs.hasOwnProperty(key)) { + $form.prepend( + `` + ); + } + } + } + + this.$element.find(".qor-advanced-filter__dropdown").hide(); + + this.removeEmptyPairs($form); + + if ($bottomsheet.length) { + if ($bottomsheet.data().url) { + let reloadUrl = `${$bottomsheet.data().url}?${params}`; + $bottomsheet.trigger("reloadFromUrl.qor.bottomsheets", [reloadUrl]); + return false; + } else { + console.log("dont have base URL! advancedsearch reload failed"); + } + } + }, + + removeEmptyPairs: function($form) { + $form.find("advanced-filter-group").each(function() { + let $this = $(this), + $input = $this.find("[filter-required]"); + if ($input.val() == "") { + $this.remove(); + } + }); + }, + + destroy: function() { + this.$element.removeData(NAMESPACE); + } + }; + + QorAdvancedSearch.DEFAULTS = {}; + + QorAdvancedSearch.MODAL = ``; + + QorAdvancedSearch.plugin = function(options) { + return this.each(function() { + let $this = $(this), + data = $this.data(NAMESPACE), + fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorAdvancedSearch(this, options))); + } + + if (typeof options === "string" && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $(function() { + let selector = '[data-toggle="qor.advancedsearch"]', + options; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorAdvancedSearch.plugin.call($(selector, e.target), "destroy"); + }) + .on(EVENT_ENABLE, function(e) { + QorAdvancedSearch.plugin.call($(selector, e.target), options); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorAdvancedSearch; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-autoheight.js b/app/views/qor/assets/javascripts/qor/qor-autoheight.js new file mode 100644 index 0000000..d45a29f --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-autoheight.js @@ -0,0 +1,101 @@ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function ($) { + + 'use strict'; + + var NAMESPACE = 'qor.autoheight'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + var EVENT_INPUT = 'input'; + + function QorAutoheight(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorAutoheight.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorAutoheight.prototype = { + constructor: QorAutoheight, + + init: function () { + var $this = this.$element; + + this.paddingTop = parseInt($this.css('padding-top'), 10); + this.paddingBottom = parseInt($this.css('padding-bottom'), 10); + this.resize(); + this.bind(); + }, + + bind: function () { + this.$element.on(EVENT_INPUT, $.proxy(this.resize, this)); + }, + + unbind: function () { + this.$element.off(EVENT_INPUT, this.resize); + }, + + resize: function () { + var $this = this.$element; + var scrollHeight = $this.prop('scrollHeight'); + + if(scrollHeight){ + $this.height('auto').height(scrollHeight - this.paddingTop - this.paddingBottom); + } else { + $this.height('40px'); + } + }, + + destroy: function () { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorAutoheight.DEFAULTS = {}; + + QorAutoheight.plugin = function (options) { + return this.each(function () { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorAutoheight(this, options))); + } + + if (typeof options === 'string' && $.isFunction(fn = data[options])) { + fn.apply(data); + } + }); + }; + + $(function () { + var selector = 'textarea.qor-js-autoheight'; + + $(document). + on(EVENT_DISABLE, function (e) { + QorAutoheight.plugin.call($(selector, e.target), 'destroy'); + }). + on(EVENT_ENABLE, function (e) { + QorAutoheight.plugin.call($(selector, e.target)); + }). + triggerHandler(EVENT_ENABLE); + }); + + return QorAutoheight; + +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-bottomsheets.js b/app/views/qor/assets/javascripts/qor/qor-bottomsheets.js new file mode 100644 index 0000000..e67be63 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-bottomsheets.js @@ -0,0 +1,754 @@ +(function(factory) { + if (typeof define === "function" && define.amd) { + // AMD. Register as anonymous module. + define(["jquery"], factory); + } else if (typeof exports === "object") { + // Node / CommonJS + factory(require("jquery")); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + "use strict"; + + let _ = window._, + FormData = window.FormData, + QOR_Translations = window.QOR_Translations, + NAMESPACE = "qor.bottomsheets", + EVENT_CLICK = "click." + NAMESPACE, + EVENT_SUBMIT = "submit." + NAMESPACE, + EVENT_SUBMITED = "ajaxSuccessed." + NAMESPACE, + EVENT_RELOAD = "reload." + NAMESPACE, + EVENT_RELOADFROMURL = "reloadFromUrl." + NAMESPACE, + EVENT_BOTTOMSHEET_BEFORESEND = "bottomsheetBeforeSend." + NAMESPACE, + EVENT_BOTTOMSHEET_LOADED = "bottomsheetLoaded." + NAMESPACE, + EVENT_BOTTOMSHEET_CLOSED = "bottomsheetClosed." + NAMESPACE, + EVENT_BOTTOMSHEET_SUBMIT = "bottomsheetSubmitComplete." + NAMESPACE, + EVENT_HIDDEN = "hidden." + NAMESPACE, + EVENT_KEYUP = "keyup." + NAMESPACE, + CLASS_OPEN = "qor-bottomsheets-open", + CLASS_IS_SHOWN = "is-shown", + CLASS_IS_SLIDED = "is-slided", + CLASS_MAIN_CONTENT = ".mdl-layout__content.qor-page", + CLASS_BODY_CONTENT = ".qor-page__body", + CLASS_BODY_HEAD = ".qor-page__header", + CLASS_BOTTOMSHEETS_FILTER = ".qor-bottomsheet__filter", + CLASS_BOTTOMSHEETS_BUTTON = ".qor-bottomsheets__search-button", + CLASS_BOTTOMSHEETS_INPUT = ".qor-bottomsheets__search-input", + URL_GETQOR = "http://www.getqor.com/"; + + function getUrlParameter(name, search) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); + var results = regex.exec(decodeURIComponent(search)); + return results === null + ? "" + : results[1].replace(/\+/g, " "); + } + + function updateQueryStringParameter(key, value, uri) { + var escapedkey = String(key).replace(/[\\^$*+?.()|[\]{}]/g, "\\$&"), + re = new RegExp("([?&])" + escapedkey + "=.*?(&|$)", "i"), + separator = uri.indexOf("?") !== -1 ? "&" : "?"; + + if (uri.match(re)) { + if (value) { + return uri.replace(re, "$1" + key + "=" + value + "$2"); + } else { + if (RegExp.$1 === "?" || RegExp.$1 === RegExp.$2) { + return uri.replace(re, "$1"); + } else { + return uri.replace(re, ""); + } + } + } else if (value) { + return uri + separator + key + "=" + value; + } + } + + function pushArrary($ele, isScript) { + let array = [], + prop = "href"; + + isScript && (prop = "src"); + $ele.each(function() { + array.push($(this).attr(prop)); + }); + return _.uniq(array); + } + + function execSlideoutEvents(url, response) { + // exec qorSliderAfterShow after script loaded + var qorSliderAfterShow = $.fn.qorSliderAfterShow; + for (var name in qorSliderAfterShow) { + if ( + qorSliderAfterShow.hasOwnProperty(name) && + !qorSliderAfterShow[name]["isLoadedInBottomSheet"] && + name != "initPublishForm" && + name != "qorActivityinit" + ) { + qorSliderAfterShow[name]["isLoadedInBottomSheet"] = true; + qorSliderAfterShow[name].call(this, url, response); + } + } + } + + function loadScripts(srcs, data, callback) { + let scriptsLoaded = 0; + + for (let i = 0, len = srcs.length; i < len; i++) { + let script = document.createElement("script"); + + script.onload = function() { + scriptsLoaded++; + + if (scriptsLoaded === srcs.length) { + if ($.isFunction(callback)) { + callback(); + } + } + + if (data && data.url && data.response) { + execSlideoutEvents(data.url, data.response); + } + }; + + script.src = srcs[i]; + document.body.appendChild(script); + } + } + + function loadStyles(srcs) { + let ss = document.createElement("link"), + src = srcs.shift(); + + ss.type = "text/css"; + ss.rel = "stylesheet"; + ss.onload = function() { + if (srcs.length) { + loadStyles(srcs); + } + }; + ss.href = src; + document.getElementsByTagName("head")[0].appendChild(ss); + } + + function compareScripts($scripts) { + let $currentPageScripts = $("script"), + slideoutScripts = pushArrary($scripts, true), + currentPageScripts = pushArrary($currentPageScripts, true), + scriptDiff = _.difference(slideoutScripts, currentPageScripts); + return scriptDiff; + } + + function compareLinks($links) { + let $currentStyles = $("link"), + slideoutStyles = pushArrary($links), + currentStyles = pushArrary($currentStyles), + styleDiff = _.difference(slideoutStyles, currentStyles); + + return styleDiff; + } + + function QorBottomSheets(element, options) { + this.$element = $(element); + this.options = $.extend( + {}, + QorBottomSheets.DEFAULTS, + $.isPlainObject(options) && options + ); + this.resourseData = {}; + this.init(); + } + + QorBottomSheets.prototype = { + constructor: QorBottomSheets, + + init: function() { + this.build(); + this.bind(); + }, + + build: function() { + let $bottomsheets; + + this.$bottomsheets = $bottomsheets = $(QorBottomSheets.TEMPLATE).appendTo( + "body" + ); + this.$body = $bottomsheets.find(".qor-bottomsheets__body"); + this.$title = $bottomsheets.find(".qor-bottomsheets__title"); + this.$header = $bottomsheets.find(".qor-bottomsheets__header"); + this.$bodyClass = $("body").prop("class"); + this.filterURL = ""; + this.searchParams = ""; + }, + + bind: function() { + this.$bottomsheets + .on(EVENT_SUBMIT, "form", this.submit.bind(this)) + .on(EVENT_CLICK, '[data-dismiss="bottomsheets"]', this.hide.bind(this)) + .on(EVENT_CLICK, ".qor-pagination-container a", this.pagination.bind(this)) + .on(EVENT_CLICK, CLASS_BOTTOMSHEETS_BUTTON, this.search.bind(this)) + .on(EVENT_KEYUP, this.keyup.bind(this)) + .on("selectorChanged.qor.selector", this.selectorChanged.bind(this)) + .on("filterChanged.qor.filter", this.filterChanged.bind(this)) + .on(EVENT_RELOADFROMURL, this.reloadFromUrl.bind(this)); + }, + + unbind: function() { + this.$bottomsheets + .off(EVENT_SUBMIT, "form") + .off(EVENT_CLICK) + .off("selectorChanged.qor.selector") + .off("filterChanged.qor.filter"); + }, + + bindActionData: function(actiondData) { + var $form = this.$body + .find('[data-toggle="qor-action-slideout"]') + .find("form"); + for (var i = actiondData.length - 1; i >= 0; i--) { + $form.prepend( + '' + ); + } + }, + + filterChanged: function(e, search, key) { + // if this event triggered: + // search: ?locale_mode=locale, ?filters[Color].Value=2 + // key: search param name: locale_mode + + var loadUrl; + + loadUrl = this.constructloadURL(search, key); + loadUrl && this.reload(loadUrl); + return false; + }, + + selectorChanged: function(e, url, key) { + // if this event triggered: + // url: /admin/!remote_data_searcher/products/Collections?locale=en-US + // key: search param key: locale + + var loadUrl; + + loadUrl = this.constructloadURL(url, key); + loadUrl && this.reload(loadUrl); + return false; + }, + + keyup: function(e) { + var searchInput = this.$bottomsheets.find(CLASS_BOTTOMSHEETS_INPUT); + + if (e.which === 13 && searchInput.length && searchInput.is(":focus")) { + this.search(); + } + }, + + search: function() { + var $bottomsheets = this.$bottomsheets, + param = "?keyword=", + baseUrl = $bottomsheets.data().url, + searchValue = $.trim( + $bottomsheets.find(CLASS_BOTTOMSHEETS_INPUT).val() + ), + url = baseUrl + param + searchValue; + + if(/\?/g.test(baseUrl)){ + url = baseUrl + "&keyword=" + searchValue; + } + + this.reload(url); + }, + + pagination: function(e) { + var $ele = $(e.target).closest("a"), + url = $ele.prop("href"); + if (url) { + this.reload(url); + } + return false; + }, + + reload: function(url) { + var $content = this.$bottomsheets.find(CLASS_BODY_CONTENT); + + this.addLoading($content); + this.fetchPage(url); + }, + + reloadFromUrl: function(e, url) { + this.reload(url); + }, + + fetchPage: function(url) { + var $bottomsheets = this.$bottomsheets, + _this = this; + + $.get(url, function(response) { + var $response = $(response).find(CLASS_MAIN_CONTENT), + $responseHeader = $response.find(CLASS_BODY_HEAD), + $responseBody = $response.find(CLASS_BODY_CONTENT); + + if ($responseBody.length) { + $bottomsheets.find(CLASS_BODY_CONTENT).html($responseBody.html()); + + if ($responseHeader.length) { + _this.$body + .find(CLASS_BODY_HEAD) + .html($responseHeader.html()) + .trigger("enable"); + _this.addHeaderClass(); + } + // will trigger this event(relaod.qor.bottomsheets) when bottomsheets reload complete: like pagination, filter, action etc. + $bottomsheets.trigger(EVENT_RELOAD); + } else { + _this.reload(url); + } + }).fail(function() { + window.alert("server error, please try again later!"); + }); + }, + + constructloadURL: function(url, key) { + var fakeURL, + value, + filterURL = this.filterURL, + bindUrl = this.$bottomsheets.data().url; + + if (!filterURL) { + if (bindUrl) { + filterURL = bindUrl; + } else { + return; + } + } + + fakeURL = new URL(URL_GETQOR + url); + value = getUrlParameter(key, fakeURL.search); + filterURL = this.filterURL = updateQueryStringParameter( + key, + value, + filterURL + ); + + return filterURL; + }, + + addHeaderClass: function() { + this.$body.find(CLASS_BODY_HEAD).hide(); + if ( + this.$bottomsheets + .find(CLASS_BODY_HEAD) + .children(CLASS_BOTTOMSHEETS_FILTER).length + ) { + this.$body + .addClass("has-header") + .find(CLASS_BODY_HEAD) + .show(); + } + }, + + addLoading: function($element) { + $element.html(""); + $(QorBottomSheets.TEMPLATE_LOADING) + .appendTo($element) + .trigger("enable.qor.material"); + }, + + loadExtraResource: function(data) { + let styleDiff = compareLinks(data.$links), + scriptDiff = compareScripts(data.$scripts); + + styleDiff.length && loadStyles(styleDiff); + scriptDiff.length && loadScripts(scriptDiff, data); + }, + + loadMedialibraryJS: function($response) { + var $script = $response.filter("script"), + theme = /theme=media_library/g, + src, + _this = this; + + $script.each(function() { + src = $(this).prop("src"); + if (theme.test(src)) { + var script = document.createElement("script"); + script.src = src; + document.body.appendChild(script); + _this.mediaScriptAdded = true; + } + }); + }, + + submit: function(e) { + let form = e.target, + $form = $(form), + _this = this, + url = $form.prop("action"), + formData, + $bottomsheets = $form.closest(".qor-bottomsheets"), + resourseData = $bottomsheets.data(), + ajaxType = resourseData.ajaxType, + $submit = $form.find(":submit"); + + // will ingore submit event if need handle with other submit event: like select one, many... + if (resourseData.ingoreSubmit) { + return; + } + + // will submit form as normal, + // if you need download file after submit form or other things, please add + // data-use-normal-submit="true" to form tag + //
          + var normalSubmit = $form.data().normalSubmit; + + if (normalSubmit) { + return; + } + + $(document).trigger(EVENT_BOTTOMSHEET_BEFORESEND); + e.preventDefault(); + + formData = new FormData(form); + + $.ajax(url, { + method: $form.prop("method"), + data: formData, + dataType: ajaxType ? ajaxType : "html", + processData: false, + contentType: false, + beforeSend: function() { + $submit.prop("disabled", true); + }, + success: function(data, textStatus, jqXHR) { + if (resourseData.ajaxMute) { + $bottomsheets.remove(); + return; + } + + if (resourseData.ajaxTakeover) { + resourseData.$target + .parent() + .trigger(EVENT_SUBMITED, [data, $bottomsheets]); + return; + } + + // handle file download from form submit + var disposition = jqXHR.getResponseHeader("Content-Disposition"); + if (disposition && disposition.indexOf("attachment") !== -1) { + var fileNameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/, + matches = fileNameRegex.exec(disposition), + contentType = jqXHR.getResponseHeader("Content-Type"), + fileName = ""; + + if (matches != null && matches[1]) { + fileName = matches[1].replace(/['"]/g, ""); + } + + window.QOR.qorAjaxHandleFile(url, contentType, fileName, formData); + $submit.prop("disabled", false); + + return; + } + + $(".qor-error").remove(); + + var returnUrl = $form.data("returnUrl"); + var refreshUrl = $form.data("refreshUrl"); + + if (refreshUrl) { + window.location.href = refreshUrl; + return; + } + + if (returnUrl == "refresh") { + _this.refresh(); + return; + } + + if (returnUrl && returnUrl != "refresh") { + _this.load(returnUrl); + } else { + _this.refresh(); + } + + $(document).trigger(EVENT_BOTTOMSHEET_SUBMIT); + }, + error: function(err) { + window.QOR.handleAjaxError(err); + }, + complete: function() { + $submit.prop("disabled", false); + } + }); + }, + + load: function(url, data, callback) { + var options = this.options, + method, + dataType, + load, + actionData = data.actionData, + resourseData = this.resourseData, + selectModal = resourseData.selectModal, + ingoreSubmit = resourseData.ingoreSubmit, + $bottomsheets = this.$bottomsheets, + $header = this.$header, + $body = this.$body; + + if (!url) { + return; + } + + this.show(); + this.addLoading($body); + + this.filterURL = url; + $body.removeClass("has-header has-hint"); + + data = $.isPlainObject(data) ? data : {}; + + method = data.method ? data.method : "GET"; + dataType = data.datatype ? data.datatype : "html"; + + load = $.proxy(function() { + $.ajax(url, { + method: method, + dataType: dataType, + success: $.proxy(function(response) { + if (method === "GET") { + let $response = $(response), + $content, + bodyClass, + loadExtraResourceData = { + $scripts: $response.filter("script"), + $links: $response.filter("link"), + url: url, + response: response + }, + hasSearch = + selectModal && $response.find(".qor-search-container").length, + bodyHtml = response.match(/<\s*body.*>[\s\S]*<\s*\/body\s*>/gi); + + $content = $response.find(CLASS_MAIN_CONTENT); + + if (bodyHtml) { + bodyHtml = bodyHtml + .join("") + .replace(/<\s*body/gi, "${ + data.selectBacktolistTitle + }` + ); + } + + if (selectModal) { + $body + .find(".qor-button--new") + .data("ingoreSubmit", true) + .data("selectId", resourseData.selectId) + .data("loadInline", true); + if ( + selectModal != "one" && + !data.selectNohint && + (typeof resourseData.maxItem === "undefined" || + resourseData.maxItem != "1") + ) { + $body.addClass("has-hint"); + } + if (selectModal == "mediabox" && !this.mediaScriptAdded) { + this.loadMedialibraryJS($response); + } + } + + $header.find(".qor-button--new").remove(); + this.$title.after($body.find(".qor-button--new")); + + if (hasSearch) { + $bottomsheets.addClass("has-search"); + $header.find(".qor-bottomsheets__search").remove(); + $header.prepend(QorBottomSheets.TEMPLATE_SEARCH); + } + + if (actionData && actionData.length) { + this.bindActionData(actionData); + } + + if (resourseData.bottomsheetClassname) { + $bottomsheets.addClass(resourseData.bottomsheetClassname); + } + + $bottomsheets.trigger("enable"); + + $bottomsheets.one(EVENT_HIDDEN, function() { + $(this).trigger("disable"); + }); + + this.addHeaderClass(); + $bottomsheets.data(data); + + // handle after opened callback + if (callback && $.isFunction(callback)) { + callback(this.$bottomsheets); + } + + // callback for after bottomSheets loaded HTML + $bottomsheets.trigger(EVENT_BOTTOMSHEET_LOADED, [url, response]); + } else { + if (data.returnUrl) { + this.load(data.returnUrl); + } else { + this.refresh(); + } + } + }, this), + + error: $.proxy(function() { + this.$bottomsheets.remove(); + if (!$(".qor-bottomsheets").is(":visible")) { + $("body").removeClass(CLASS_OPEN); + } + var errors; + if ($(".qor-error span").length > 0) { + errors = $(".qor-error span") + .map(function() { + return $(this).text(); + }) + .get() + .join(", "); + } else { + errors = QOR_Translations.serverError; + } + window.alert(errors); + }, this) + }); + }, this); + + load(); + }, + + open: function(options, callback) { + if (!options.loadInline) { + this.init(); + } + this.resourseData = options; + this.load(options.url, options, callback); + }, + + show: function() { + this.$bottomsheets.addClass(CLASS_IS_SHOWN).get(0).offsetHeight; + this.$bottomsheets.addClass(CLASS_IS_SLIDED); + $("body").addClass(CLASS_OPEN); + }, + + hide: function(e) { + let $bottomsheets = $(e.target).closest(".qor-bottomsheets"), + $datePicker = $(".qor-datepicker").not(".hidden"); + + if ($datePicker.length) { + $datePicker.addClass("hidden"); + } + + $bottomsheets.qorSelectCore("destroy"); + + $bottomsheets.trigger(EVENT_BOTTOMSHEET_CLOSED).remove(); + if (!$(".qor-bottomsheets").is(":visible")) { + $("body").removeClass(CLASS_OPEN); + } + return false; + }, + + refresh: function() { + this.$bottomsheets.remove(); + $("body").removeClass(CLASS_OPEN); + + setTimeout(function() { + window.location.reload(); + }, 350); + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorBottomSheets.DEFAULTS = { + title: ".qor-form-title, .mdl-layout-title", + content: false + }; + + QorBottomSheets.TEMPLATE_ERROR = `
          `; + QorBottomSheets.TEMPLATE_LOADING = `
          `; + QorBottomSheets.TEMPLATE_SEARCH = ``; + + QorBottomSheets.TEMPLATE = `
          +
          +

          + +
          +
          +
          `; + + QorBottomSheets.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorBottomSheets(this, options))); + } + + if (typeof options === "string" && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $.fn.qorBottomSheets = QorBottomSheets.plugin; + + return QorBottomSheets; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-chooser.js b/app/views/qor/assets/javascripts/qor/qor-chooser.js new file mode 100644 index 0000000..2fa4adb --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-chooser.js @@ -0,0 +1,131 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + var NAMESPACE = 'qor.chooser'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + + function QorChooser(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorChooser.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorChooser.prototype = { + constructor: QorChooser, + + init: function() { + let $this = this.$element, + select2Data = $this.data(), + resetSelect2Width, + option = { + minimumResultsForSearch: 8, + dropdownParent: $this.parent() + }; + let getSelect2AjaxDynamicURL = window.getSelect2AjaxDynamicURL; + let remoteImage = select2Data.remoteImage; + + if (select2Data.remoteData) { + option.ajax = $.fn.select2.ajaxCommonOptions(select2Data); + if (getSelect2AjaxDynamicURL && $.isFunction(getSelect2AjaxDynamicURL)) { + option.ajax.url = function() { + return getSelect2AjaxDynamicURL(select2Data); + }; + } else { + option.ajax.url = select2Data.remoteUrl; + } + + option.templateResult = function(data) { + let tmpl = $this.parents('.qor-field').find('[name="select2-result-template"]'); + return $.fn.select2.ajaxFormatResult(data, tmpl, remoteImage); + }; + + option.templateSelection = function(data) { + if (data.loading) return data.text; + let tmpl = $this.parents('.qor-field').find('[name="select2-selection-template"]'); + return $.fn.select2.ajaxFormatResult(data, tmpl, remoteImage); + }; + } + + $this + .on('select2:select', function(evt) { + $(evt.target).attr('chooser-selected', 'true'); + }) + .on('select2:unselect', function(evt) { + $(evt.target).attr('chooser-selected', ''); + }); + + $this.select2(option); + + // reset select2 container width + this.resetSelect2Width(); + resetSelect2Width = window._.debounce(this.resetSelect2Width.bind(this), 300); + $(window).resize(resetSelect2Width); + + if ($this.val()) { + $this.attr('chooser-selected', 'true'); + } + }, + + resetSelect2Width: function() { + var $container, + select2 = this.$element.data().select2; + if (select2 && select2.$container) { + $container = select2.$container; + $container.width($container.parent().width()); + } + }, + + destroy: function() { + this.$element.select2('destroy').removeData(NAMESPACE); + } + }; + + QorChooser.DEFAULTS = {}; + + QorChooser.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorChooser(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = 'select[data-toggle="qor.chooser"]'; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorChooser.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorChooser.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorChooser; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-common.js b/app/views/qor/assets/javascripts/qor/qor-common.js new file mode 100644 index 0000000..7ee7744 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-common.js @@ -0,0 +1,218 @@ +$(function() { + let _ = window._, + QOR = window.QOR, + QOR_Translations = window.QOR_Translations, + html = ``, + $dialog = $(html).appendTo("body"); + + // ************************************ Refactor window.confirm ************************************ + $(document) + .on("keyup.qor.confirm", function(e) { + if (!$dialog.is(":visible")) { + return; + } + if (e.which === 27) { + setTimeout(function() { + $dialog.hide(); + QOR.qorConfirmCallback = undefined; + }, 100); + } + if (e.which === 13) { + setTimeout(function() { + $('.dialog-button[data-type="confirm"]').click(); + }, 100); + } + }) + .on("click.qor.confirm", ".dialog-button", function() { + let value = $(this).data("type"), + callback = QOR.qorConfirmCallback; + + $.isFunction(callback) && callback(value); + $dialog.hide(); + QOR.qorConfirmCallback = undefined; + return false; + }); + + QOR.qorConfirm = function(data, callback) { + let okBtn = $dialog.find(".dialog-ok"), + cancelBtn = $dialog.find(".dialog-cancel"); + + if (_.isString(data)) { + $dialog.find(".dialog-message").text(data); + okBtn.text(QOR_Translations.okButton); + cancelBtn.text(QOR_Translations.cancelButton); + } else if (_.isObject(data)) { + if (data.confirmOk && data.confirmCancel) { + okBtn.text(data.confirmOk); + cancelBtn.text(data.confirmCancel); + } else { + okBtn.text(QOR_Translations.okButton); + cancelBtn.text(QOR_Translations.cancelButton); + } + + if(data.icon){ + $dialog.find('i.material-icons').addClass(data.icon).html(data.icon); + } + + $dialog.find(".dialog-message").text(data.confirm); + } + + $dialog.show(); + QOR.qorConfirmCallback = callback; + return false; + }; + + // ******************************************************************************* + + // ****************Handle download file from AJAX POST**************************** + let objectToFormData = function(obj, form) { + let formdata = form || new FormData(), + key; + + for (var variable in obj) { + if (obj.hasOwnProperty(variable) && obj[variable]) { + key = variable; + } + + if (obj[variable] instanceof Date) { + formdata.append(key, obj[variable].toISOString()); + } else if ( + typeof obj[variable] === "object" && + !(obj[variable] instanceof File) + ) { + objectToFormData(obj[variable], formdata); + } else { + formdata.append(key, obj[variable]); + } + } + + return formdata; + }; + + QOR.qorAjaxHandleFile = function(url, contentType, fileName, data) { + let request = new XMLHttpRequest(); + + request.responseType = "arraybuffer"; + request.open("POST", url, true); + request.onload = function() { + if (this.status === 200) { + let blob = new Blob([this.response], { + type: contentType + }), + url = window.URL.createObjectURL(blob), + a = document.createElement("a"); + + document.body.appendChild(a); + a.href = url; + a.download = fileName || "download-" + $.now(); + a.click(); + } else { + window.alert(QOR_Translations.serverError); + } + }; + + if (_.isObject(data)) { + if (Object.prototype.toString.call(data) != "[object FormData]") { + data = objectToFormData(data); + } + + request.send(data); + } + }; + + // ********************************convert video link******************** + // linkyoutube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.\-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig, + // linkvimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/, + + let converVideoLinks = function() { + let $ele = $(".qor-linkify-object"), + linkyoutube = /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.\-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/gi; + + if (!$ele.length) { + return; + } + + $ele.each(function() { + let url = $(this).data("video-link"); + if (url.match(linkyoutube)) { + $(this).html( + `` + ); + } + }); + }; + + $.fn.qorSliderAfterShow.converVideoLinks = converVideoLinks; + converVideoLinks(); + + // ********************************Qor Handle AJAX error******************** + QOR.handleAjaxError = function(err) { + let $body = $("body"), + rJSON = err.responseJSON, + rText = err.responseText, + $error = $(`
          `); + + $body.find(".qor-alert").remove(); + + if (err.status === 422) { + if (rJSON) { + let errors = rJSON.errors, + $errorContent = ""; + + if ($.isArray(errors)) { + for (let i = 0; i < errors.length; i++) { + $errorContent += `
        • + error + ${errors[i]} +
        • `; + } + } else { + $errorContent = `
        • + error + ${errors} +
        • `; + } + $error.append($errorContent); + } else { + $error = $(rText).find(".qor-error"); + } + } else { + $error.append(`
        • + error + ${err.statusText} +
        • `); + } + + $error.prependTo($body); + setTimeout(function() { + $error.addClass("qor-alert__active"); + }, 50); + + setTimeout(function() { + $('.qor-alert[data-dismissible="true"]').removeClass("qor-alert__active"); + $("#qor-submit-loading").remove(); + }, 6000); + }; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-config.js b/app/views/qor/assets/javascripts/qor/qor-config.js new file mode 100644 index 0000000..439ac80 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-config.js @@ -0,0 +1,126 @@ +// init for slideout after show event +$.fn.qorSliderAfterShow = $.fn.qorSliderAfterShow || {}; +window.QOR = { + $formLoading: '
          ' +}; + +String.prototype.escapeSymbol = function() { + var tagsToReplace = { + '&': '&', + '<': '<', + '>': '>', + '"' : '"', + "'" : ''', + '/' : '/' + }; + return this.replace(/[&<>"']/g, function(tag) { + return tagsToReplace[tag] || tag; + }); +}; + +// change Mustache tags from {{}} to [[]] +window.Mustache && (window.Mustache.tags = ['[[', ']]']); + +// clear close alert after ajax complete +$(document).ajaxComplete(function(event, xhr, settings) { + if (settings.type == 'POST' || settings.type == 'PUT') { + if ($.fn.qorSlideoutBeforeHide) { + $.fn.qorSlideoutBeforeHide = null; + window.onbeforeunload = null; + } + } +}); + +// select2 ajax common options +// $.fn.select2 = $.fn.select2 || function(){}; +$.fn.select2.ajaxCommonOptions = function(select2Data) { + let remoteDataPrimaryKey = select2Data.remoteDataPrimaryKey; + + return { + dataType: 'json', + headers: getSelect2Header(select2Data), + cache: true, + delay: 250, + data: function(params) { + return { + keyword: params.term, // search term + page: params.page, + per_page: 20 + }; + }, + processResults: function(data, params) { + // parse the results into the format expected by Select2 + // since we are using custom formatting functions we do not need to + // alter the remote JSON data, except to indicate that infinite + // scrolling can be used + params.page = params.page || 1; + + var processedData = $.map(data, function(obj) { + obj.id = obj[remoteDataPrimaryKey] || obj.primaryKey || obj.Id || obj.ID; + return obj; + }); + + return { + results: processedData, + pagination: { + more: processedData.length >= 20 + } + }; + } + }; +}; + +// select2 ajax common options +// format ajax template data +$.fn.select2.ajaxFormatResult = function(data, tmpl, remoteDataImage) { + var result = ''; + + if (data.loading) { + return data.text; + } + + console.log('select2.ajaxFormatResult: Data'); + console.log(data); + + console.log('select2.ajaxFormatResult: has remote image'); + console.log(remoteDataImage); + + if (remoteDataImage) { + var resultName = data.text || data.Name || data.Title || data.Code || data[Object.keys(data)[0]]; + var imageUrl = data.Image; + if (imageUrl) { + result = '
          ' + '' + '' + resultName + '
          '; + } else { + result = '
          ' + resultName + '
          '; + } + + return $(result); + } else { + if (tmpl.length > 0) { + result = window.Mustache.render(tmpl.html().replace(/{{(.*?)}}/g, '[[$1]]'), data); + } else { + result = data.text || data.Name || data.Title || data.Code || data[Object.keys(data)[0]]; + } + + // if is HTML + if (/<(.*)(\/>|<\/.+>)/.test(result)) { + return $(result); + } + + return result; + } +}; + +function getSelect2Header() { + let data = $('body').data(); + let selectAjaxHeader = data.selectAjaxHeader; + let getSelect2HeaderFunction = window.getSelect2HeaderFunction; + let headers = {}; + + if (selectAjaxHeader && getSelect2HeaderFunction && $.isFunction(getSelect2HeaderFunction)) { + headers[selectAjaxHeader] = getSelect2HeaderFunction(); + return headers; + } else { + return {}; + } +} diff --git a/app/views/qor/assets/javascripts/qor/qor-cropper.js b/app/views/qor/assets/javascripts/qor/qor-cropper.js new file mode 100644 index 0000000..7f43cb3 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-cropper.js @@ -0,0 +1,766 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let URL = window.URL || window.webkitURL, + NAMESPACE = 'qor.cropper', + // Events + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_CHANGE = 'change.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_SHOWN = 'shown.qor.modal', + EVENT_HIDDEN = 'hidden.qor.modal', + // Classes + CLASS_TOGGLE = '.qor-cropper__toggle', + CLASS_CANVAS = '.qor-cropper__canvas', + CLASS_WRAPPER = '.qor-cropper__wrapper', + CLASS_OPTIONS = '.qor-cropper__options', + CLASS_SAVE = '.qor-cropper__save', + CLASS_DELETE = '.qor-cropper__toggle--delete', + CLASS_CROP = '.qor-cropper__toggle--crop', + CLASS_UNDO = '.qor-fieldset__undo', + HIDDEN_DATA_INPUT = 'input[name="QorResource.MediaOption"]:hidden'; + + function capitalize(str) { + if (typeof str === 'string') { + str = str.charAt(0).toUpperCase() + str.substr(1); + } + + return str; + } + + function getLowerCaseKeyObject(obj) { + let newObj = {}, + key; + + if ($.isPlainObject(obj)) { + for (key in obj) { + if (obj.hasOwnProperty(key)) { + newObj[String(key).toLowerCase()] = obj[key]; + } + } + } + + return newObj; + } + + function getValueByNoCaseKey(obj, key) { + let originalKey = String(key), + lowerCaseKey = originalKey.toLowerCase(), + upperCaseKey = originalKey.toUpperCase(), + capitalizeKey = capitalize(originalKey); + + if ($.isPlainObject(obj)) { + return obj[lowerCaseKey] || obj[capitalizeKey] || obj[upperCaseKey]; + } + } + + function replaceText(str, data) { + if (typeof str === 'string') { + if (typeof data === 'object') { + $.each(data, function(key, val) { + str = str.replace('$[' + String(key).toLowerCase() + ']', val); + }); + } + } + + return str; + } + + function isSVG(url) { + return /.svg$/.test(url); + } + + function QorCropper(element, options) { + this.$element = $(element); + this.options = $.extend(true, {}, QorCropper.DEFAULTS, $.isPlainObject(options) && options); + this.data = null; + this.init(); + } + + QorCropper.prototype = { + constructor: QorCropper, + + init: function() { + let options = this.options, + $this = this.$element, + $parent = $this.closest(options.parent), + data, + outputValue, + fetchUrl, + _this = this, + imageData; + + if (!$parent.length) { + $parent = $this.parent(); + } + + this.$parent = $parent; + this.$output = $parent.find(options.output); + this.$formCropInput = $parent.closest('form').find(HIDDEN_DATA_INPUT); + this.$list = $parent.find(options.list); + + fetchUrl = this.$output.data('fetchSizedata'); + + if (fetchUrl) { + $.getJSON(fetchUrl, function(data) { + imageData = JSON.parse(data.MediaOption); + _this.$output.val(JSON.stringify(data)); + _this.$formCropInput.val(JSON.stringify(data)); + _this.data = imageData || {}; + if (isSVG(imageData.URL || imageData.Url)) { + _this.resetImage(); + } + _this.build(); + _this.bind(); + }); + } else { + outputValue = $.trim(this.$output.val()); + if (outputValue) { + data = JSON.parse(outputValue); + if (isSVG(data.URL || data.Url)) { + this.resetImage(); + } + } + + this.data = data || {}; + + this.build(); + this.bind(); + } + }, + + resetImage: function() { + this.$parent.addClass('is-svg'); + }, + + build: function() { + let textData = this.$output.data(), + text = {}, + replaceTexts; + + if (textData) { + text = { + title: textData.cropperTitle, + ok: textData.cropperOk, + cancel: textData.cropperCancel + }; + replaceTexts = this.options.text; + } + + if (text.ok && text.title && text.cancel) { + replaceTexts = text; + } + + this.wrap(); + this.$modal = $(replaceText(QorCropper.MODAL, replaceTexts)).appendTo('body'); + }, + + unbuild: function() { + this.$modal.remove(); + this.unwrap(); + }, + + wrap: function() { + let $list = this.$list, + $img; + + $img = $list.find('img').not('.is-svg'); + + if ($img.length) { + $list.find('li').append(QorCropper.TOGGLE); + $img.wrap(QorCropper.CANVAS); + this.center($img); + } else { + $list.find(CLASS_CROP).remove(); + } + }, + + unwrap: function() { + let $list = this.$list; + + $list.find(CLASS_TOGGLE).remove(); + $list.find(CLASS_CANVAS).each(function() { + let $this = $(this); + + $this.before($this.html()).remove(); + }); + }, + + bind: function() { + this.$element.on(EVENT_CHANGE, $.proxy(this.read, this)); + this.$list.on(EVENT_CLICK, $.proxy(this.click, this)); + this.$modal.on(EVENT_SHOWN, $.proxy(this.start, this)).on(EVENT_HIDDEN, $.proxy(this.stop, this)); + }, + + unbind: function() { + this.$element.off(EVENT_CHANGE, this.read); + this.$list.off(EVENT_CLICK, this.click); + this.$modal.off(EVENT_SHOWN, this.start).off(EVENT_HIDDEN, this.stop); + }, + + click: function(e) { + let target = e.target, + $target, + data = this.data, + $alert; + + if (target === this.$list[0]) { + return; + } + + $target = $(target); + + if ($target.closest(CLASS_DELETE).length) { + data.Delete = true; + + this.$output.val(JSON.stringify(data)); + this.$formCropInput.val(JSON.stringify(data)); + + this.$list.hide(); + + $alert = $(QorCropper.ALERT); + $alert.find(CLASS_UNDO).one( + EVENT_CLICK, + function() { + $alert.remove(); + this.$list.show(); + delete data.Delete; + this.$output.val(JSON.stringify(data)); + this.$formCropInput.val(JSON.stringify(data)); + }.bind(this) + ); + this.$parent.find('.qor-fieldset').append($alert); + } + + if ($target.closest(CLASS_CROP).length) { + $target = $target.closest('li').find('img'); + this.$target = $target; + this.$modal.qorModal('show'); + } + }, + + read: function(e) { + let files = e.target.files, + file, + $list = this.$list, + $alert = this.$parent.find('.qor-fieldset__alert'); + + $list.show(); + + if ($alert.length) { + $alert.remove(); + } + + if (files && files.length) { + file = files[0]; + + if (/^image\//.test(file.type) && URL) { + this.fileType = file.type; + this.load(URL.createObjectURL(file)); + this.$parent.find('.qor-medialibrary__image-desc').show(); + } else { + $list.empty().html(QorCropper.FILE_LIST.replace('{{filename}}', file.name)); + } + } + }, + + load: function(url, fromExternal, callback) { + let options = this.options, + _this = this, + $list = this.$list, + $ul = $(QorCropper.LIST), + data = this.data || {}, + outputOriginalData = this.$output.val() ? JSON.parse(this.$output.val()) : {}, + outputOriginalDataType = ['Video', 'SelectedType', 'Description'], + fileType = this.fileType, + $image, + imageLength; + + // media box will use load method, has it's own html structure. + if (!fromExternal) { + $list.find('ul').remove(); + $list.html($ul); + } + + $image = $list.find('img'); + this.wrap(); + + imageLength = $image.length; + $image + .one('load', function() { + if (fileType === 'image/svg+xml') { + $list.find(CLASS_TOGGLE).remove(); + return false; + } + + let $this = $(this), + naturalWidth = this.naturalWidth, + naturalHeight = this.naturalHeight, + sizeData = $this.data(), + sizeResolution = sizeData.sizeResolution, + sizeName = sizeData.sizeName, + emulateImageData = {}, + emulateCropData = {}, + aspectRatio, + width = sizeData.sizeResolutionWidth, + height = sizeData.sizeResolutionHeight; + + if (sizeResolution) { + if (!width && !height) { + width = getValueByNoCaseKey(sizeResolution, 'width'); + height = getValueByNoCaseKey(sizeResolution, 'height'); + } + if (height && width) { + aspectRatio = width / height; + } else { + aspectRatio = naturalWidth / naturalHeight; + } + + if (naturalHeight * aspectRatio > naturalWidth) { + width = naturalWidth; + height = width / aspectRatio; + } else { + height = naturalHeight; + width = height * aspectRatio; + } + + emulateImageData = { + naturalWidth: naturalWidth, + naturalHeight: naturalHeight + }; + + emulateCropData = { + x: Math.round((naturalWidth - width) / 2), + y: Math.round((naturalHeight - height) / 2), + width: Math.round(width), + height: Math.round(height) + }; + + _this.preview($this, emulateImageData, emulateCropData); + + if (sizeName) { + data.Crop = true; + + if (!data[options.key]) { + data[options.key] = {}; + } + + if (sizeName != 'original') { + data[options.key][sizeName] = emulateCropData; + } + } + } else { + _this.center($this); + } + + // Crop, CropOptions and Delete should be BOOL type, if empty should delete, + if (data.Crop === '' || !fromExternal) { + delete data.Crop; + } + + if (!fromExternal) { + data.CropOptions = null; + delete data.Sizes; + } + + delete data.Delete; + + // Fix media upload image other property missing bug: ["Video", "SelectedType", "Description"] + outputOriginalDataType.forEach((type) => { + if (outputOriginalData[type]) { + data[type] = outputOriginalData[type]; + } + }); + + _this.$output.val(JSON.stringify(data)); + _this.$formCropInput.val(JSON.stringify(data)); + + // callback after load complete + if (sizeName && data[options.key] && Object.keys(data[options.key]).length >= imageLength) { + if (callback && $.isFunction(callback)) { + callback(); + } + } + }) + .attr('src', url) + .data('originalUrl', url); + + $list.show(); + }, + + start: function() { + let options = this.options, + $modal = this.$modal, + $target = this.$target, + sizeData = $target.data(), + sizeName = sizeData.sizeName || 'original', + sizeResolution = sizeData.sizeResolution, + originalUrl = (sizeData && sizeData.originalUrl && $target.attr('data-original-url')) + ? (/\.original\./.test(sizeData.originalUrl) ? sizeData.originalUrl + : /\.original\./.test($target.attr('data-original-url')) + ? $target.attr('data-original-url') + : $target.attr('data-original-url').replace(/file\./, 'file.original.')) + : $target.attr('src'), + $clone = $(``), + data = this.data || {}, + _this = this, + sizeAspectRatio = NaN, + sizeWidth = sizeData.sizeResolutionWidth, + sizeHeight = sizeData.sizeResolutionHeight, + list; + + if (sizeResolution) { + if (!sizeWidth && !sizeHeight) { + sizeWidth = getValueByNoCaseKey(sizeResolution, 'width'); + sizeHeight = getValueByNoCaseKey(sizeResolution, 'height'); + } + sizeAspectRatio = sizeWidth / sizeHeight; + } + + if (!data[options.key]) { + data[options.key] = {}; + } + + $modal + .trigger('enable.qor.material') + .find(CLASS_WRAPPER) + .html($clone); + + list = this.getList(sizeAspectRatio); + + if (list) { + $modal + .find(CLASS_OPTIONS) + .show() + .append(list); + } + + $clone.cropper({ + aspectRatio: sizeAspectRatio, + data: getLowerCaseKeyObject(data[options.key][sizeName]), + background: false, + movable: false, + zoomable: false, + scalable: false, + rotatable: false, + autoCropArea: 1, + + ready: function() { + $modal + .find('.qor-cropper__options-toggle') + .on(EVENT_CLICK, function() { + $modal.find('.qor-cropper__options-input').prop('checked', $(this).prop('checked')); + }) + .prop('checked', true); + + $modal.find(CLASS_SAVE).one(EVENT_CLICK, function() { + let cropData = $clone.cropper('getData', true), + croppedCanvas = $clone.cropper('getCroppedCanvas'), + syncData = [], + url; + + data.Crop = true; + data[options.key][sizeName] = cropData; + _this.imageData = $clone.cropper('getImageData'); + _this.cropData = cropData; + + if (croppedCanvas) { + try { + url = croppedCanvas.toDataURL(); + } catch (error) { + console.log(error); + console.log('Please check image Cross-origin setting'); + } + } + + $modal.find(CLASS_OPTIONS + ' input').each(function() { + let $this = $(this); + + if ($this.prop('checked')) { + syncData.push($this.attr('name')); + } + }); + + _this.output(url, syncData); + $modal.qorModal('hide'); + }); + } + }); + }, + + stop: function() { + this.$modal + .trigger('disable.qor.material') + .find(CLASS_WRAPPER + ' > img') + .cropper('destroy') + .remove() + .end() + .find(CLASS_OPTIONS) + .hide() + .find('ul') + .remove(); + }, + + getList: function(aspectRatio) { + let list = []; + + this.$list + .find('img') + .not(this.$target) + .each(function() { + let data = $(this).data(), + resolution = data.sizeResolution, + name = data.sizeName, + width = data.sizeResolutionWidth, + height = data.sizeResolutionHeight; + + if (resolution) { + if (!width && !height) { + width = getValueByNoCaseKey(resolution, 'width'); + height = getValueByNoCaseKey(resolution, 'height'); + } + + if (width / height === aspectRatio) { + list.push( + '' + ); + } + } + }); + + return list.length ? '
          • ' + list.join('
          • ') + '
          ' : ''; + }, + + output: function(url, data) { + let $target = this.$target; + + if (url) { + this.center($target.attr('src', url), true); + } else { + this.preview($target); + } + + if ($.isArray(data) && data.length) { + this.autoCrop(url, data); + } + + this.$output.val(JSON.stringify(this.data)).trigger(EVENT_CHANGE); + this.$formCropInput.val(JSON.stringify(this.data)); + }, + + preview: function($target, emulateImageData, emulateCropData) { + let $canvas = $target.parent(), + $container = $canvas.parent(), + containerWidth = $container.width(), + containerHeight = $container.height(), + imageData = emulateImageData || this.imageData, + cropData = $.extend({}, emulateCropData || this.cropData), // Clone one to avoid changing it + aspectRatio = cropData.width / cropData.height, + canvasWidth = containerWidth, + scaledRatio; + + if (canvasWidth == 0 || imageData.naturalWidth == 0 || imageData.naturalHeight == 0) { + return; + } + + if (containerHeight * aspectRatio <= containerWidth) { + canvasWidth = containerHeight * aspectRatio; + } + + scaledRatio = cropData.width / canvasWidth; + + $target.css({ + maxWidth: imageData.naturalWidth / scaledRatio, + maxHeight: imageData.naturalHeight / scaledRatio + }); + + this.center($target); + }, + + center: function($target, reset) { + $target.each(function() { + let $this = $(this), + $canvas = $this.parent(), + $container = $canvas.parent(); + + function center() { + let containerHeight = $container.height(), + canvasHeight = $canvas.height(), + marginTop = 'auto'; + + if (canvasHeight < containerHeight) { + marginTop = (containerHeight - canvasHeight) / 2; + } + + $canvas.css('margin-top', marginTop); + } + + if (reset) { + $canvas.add($this).removeAttr('style'); + } + + if (this.complete) { + center.call(this); + } else { + this.onload = center; + } + }); + }, + + autoCrop: function(url, data) { + let cropData = this.cropData, + cropOptions = this.data[this.options.key], + _this = this; + + this.$list + .find('img') + .not(this.$target) + .each(function() { + let $this = $(this), + sizeName = $this.data('sizeName'); + + if ($.inArray(sizeName, data) > -1) { + cropOptions[sizeName] = $.extend({}, cropData); + + if (url) { + _this.center($this.attr('src', url), true); + } else { + _this.preview($this); + } + } + }); + }, + + destroy: function() { + if (!isSVG) { + this.unbind(); + this.unbuild(); + } + this.$element.removeData(NAMESPACE); + } + }; + + QorCropper.DEFAULTS = { + parent: false, + output: false, + list: false, + key: 'data', + data: null, + text: { + title: 'Crop the image', + ok: 'OK', + cancel: 'Cancel' + } + }; + + QorCropper.TOGGLE = `
          +
          crop
          +
          delete
          +
          `; + + QorCropper.ALERT = `
          + +
          `; + + QorCropper.CANVAS = '
          '; + QorCropper.LIST = '
          '; + QorCropper.FILE_LIST = `
          + {{filename}} +
          +
          delete
          +
          +
          `; + QorCropper.MODAL = ``; + + QorCropper.plugin = function(option) { + return this.each(function() { + let $this = $(this), + data = $this.data(NAMESPACE), + options, + fn; + + if (!data) { + if (!$.fn.cropper) { + return; + } + + if (/destroy/.test(option)) { + return; + } + + options = $.extend(true, {}, $this.data(), typeof option === 'object' && option); + $this.data(NAMESPACE, (data = new QorCropper(this, options))); + } + + if (typeof option === 'string' && $.isFunction((fn = data[option]))) { + fn.apply(data); + } + }); + }; + + $(function() { + let selector = '.qor-file__input', + options = { + parent: '.qor-file', + output: '.qor-file__options', + list: '.qor-file__list', + key: 'CropOptions' + }; + + $(document) + .on(EVENT_ENABLE, function(e) { + QorCropper.plugin.call($(selector, e.target), options); + }) + .on(EVENT_DISABLE, function(e) { + QorCropper.plugin.call($(selector, e.target), 'destroy'); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorCropper; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-datepicker.js b/app/views/qor/assets/javascripts/qor/qor-datepicker.js new file mode 100644 index 0000000..70153fd --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-datepicker.js @@ -0,0 +1,242 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let NAMESPACE = 'qor.datepicker', + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_CHANGE = 'pick.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + CLASS_EMBEDDED = '.qor-datepicker__embedded', + CLASS_SAVE = '.qor-datepicker__save', + CLASS_PARENT = '[data-picker-type]'; + + function replaceText(str, data) { + if (typeof str === 'string') { + if (typeof data === 'object') { + $.each(data, function(key, val) { + str = str.replace('$[' + String(key).toLowerCase() + ']', val); + }); + } + } + + return str; + } + + function QorDatepicker(element, options) { + this.$element = $(element); + this.options = $.extend(true, {}, QorDatepicker.DEFAULTS, $.isPlainObject(options) && options); + this.date = null; + this.formatDate = null; + this.built = false; + this.pickerData = this.$element.data(); + this.$parent = this.$element.closest(CLASS_PARENT); + this.isDateTimePicker = this.$parent.data('picker-type') == 'datetime'; + this.$targetInput = this.$parent.find(this.pickerData.targetInput || (this.isDateTimePicker ? '.qor-datetimepicker__input' : '.qor-datepicker__input')); + this.init(); + } + + QorDatepicker.prototype = { + init: function() { + if (this.$targetInput.is(':disabled')) { + this.$element.remove(); + return; + } + this.bind(); + }, + + bind: function() { + this.$element.on(EVENT_CLICK, $.proxy(this.show, this)); + }, + + unbind: function() { + this.$element.off(EVENT_CLICK, this.show); + }, + + build: function() { + let $modal, + $ele = this.$element, + $targetInput = this.$targetInput, + defaultDate = $targetInput.val(), + datepickerOptions = { + date: new Date(), + inline: true + }; + + if (this.built) { + return; + } + + if ($ele.is(':input') && Date.parse($ele.val())) { + datepickerOptions.date = new Date($ele.val()); + } else if (defaultDate && Date.parse(defaultDate)) { + datepickerOptions.date = new Date(defaultDate); + } + + this.$modal = $modal = $(replaceText(QorDatepicker.TEMPLATE, this.options.text)).appendTo('body'); + + if ($targetInput.data('start-date')) { + datepickerOptions.startDate = new Date($targetInput.data('start-date')); + } + + if ($targetInput.data('end-date')) { + datepickerOptions.endDate = new Date($targetInput.data('end-date')); + } + + + $modal + .find(CLASS_EMBEDDED) + .on(EVENT_CHANGE, $.proxy(this.change, this)) + .qorDatepicker(datepickerOptions) + .triggerHandler(EVENT_CHANGE); + + $modal.find(CLASS_SAVE).on(EVENT_CLICK, $.proxy(this.pick, this)); + + this.built = true; + }, + + unbuild: function() { + if (!this.built) { + return; + } + + this.$modal + .find(CLASS_EMBEDDED) + .off(EVENT_CHANGE, this.change) + .qorDatepicker('destroy') + .end() + .find(CLASS_SAVE) + .off(EVENT_CLICK, this.pick) + .end() + .remove(); + }, + + change: function(e) { + var $modal = this.$modal; + var $target = $(e.target); + var date; + + this.date = date = $target.qorDatepicker('getDate'); + this.formatDate = $target.qorDatepicker('getDate', true); + + $modal.find('.qor-datepicker__picked-year').text(date.getFullYear()); + $modal + .find('.qor-datepicker__picked-date') + .text( + [$target.qorDatepicker('getDayName', date.getDay(), true) + ',', String($target.qorDatepicker('getMonthName', date.getMonth(), true)), date.getDate()].join(' ') + ); + }, + + show: function() { + if (!this.built) { + this.build(); + } + + this.$modal.qorModal('show'); + }, + + pick: function() { + let $targetInput = this.$targetInput, + newValue = this.formatDate; + + if (this.isDateTimePicker) { + var regDate = /^\d{4}-\d{1,2}-\d{1,2}/; + var oldValue = $targetInput.val(); + var hasDate = regDate.test(oldValue); + + if (hasDate) { + newValue = oldValue.replace(regDate, newValue); + } else { + newValue = newValue + ' 00:00'; + } + } + + $targetInput.val(newValue).trigger('change'); + this.$modal.qorModal('hide'); + }, + + destroy: function() { + this.unbind(); + this.unbuild(); + this.$element.removeData(NAMESPACE); + } + }; + + QorDatepicker.DEFAULTS = { + text: { + title: 'Pick a date', + ok: 'OK', + cancel: 'Cancel' + } + }; + + QorDatepicker.TEMPLATE = ``; + + QorDatepicker.plugin = function(option) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var options; + var fn; + + if (!data) { + if (!$.fn.qorDatepicker) { + return; + } + + if (/destroy/.test(option)) { + return; + } + + options = $.extend(true, {}, $this.data(), typeof option === 'object' && option); + $this.data(NAMESPACE, (data = new QorDatepicker(this, options))); + } + + if (typeof option === 'string' && $.isFunction((fn = data[option]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = '[data-toggle="qor.datepicker"]'; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorDatepicker.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorDatepicker.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorDatepicker; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-dirtyform.js b/app/views/qor/assets/javascripts/qor/qor-dirtyform.js new file mode 100644 index 0000000..4814168 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-dirtyform.js @@ -0,0 +1,106 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + var dirtyForm = function(ele, options) { + var hasChangedObj = false; + + if (this instanceof jQuery) { + options = ele; + ele = this; + } else if (!(ele instanceof jQuery)) { + ele = $(ele); + } + + ele.each(function(item, element) { + var $ele = $(element); + + if ($ele.is('form')) { + if ($ele.hasClass('ignore-dirtyform')) { + return false; + } + hasChangedObj = dirtyForm( + $ele.find( + 'input:not([type="hidden"]):not(".search-field input"):not(".chosen-search input"):not(".ignore-dirtyform"), textarea, select' + ), + options + ); + if (hasChangedObj) { + return false; + } + } else if ($ele.is(':checkbox') || $ele.is(':radio')) { + if ($ele.hasClass('ignore-dirtyform')) { + return false; + } + + if (element.checked != element.defaultChecked) { + hasChangedObj = true; + return false; + } + } else if ($ele.is('input') || $ele.is('textarea')) { + if ($ele.hasClass('ignore-dirtyform')) { + return false; + } + + if (element.value != element.defaultValue) { + hasChangedObj = true; + return false; + } + } else if ($ele.is('select')) { + if ($ele.hasClass('ignore-dirtyform')) { + return false; + } + + var option; + var defaultSelectedIndex = 0; + var numberOfOptions = element.options.length; + + for (var i = 0; i < numberOfOptions; i++) { + option = element.options[i]; + hasChangedObj = hasChangedObj || option.selected != option.defaultSelected; + if (option.defaultSelected) { + defaultSelectedIndex = i; + } + } + + if (hasChangedObj && !element.multiple) { + hasChangedObj = defaultSelectedIndex != element.selectedIndex; + } + + if (hasChangedObj) { + return false; + } + } + }); + + return hasChangedObj; + }; + + $.fn.extend({ + dirtyForm: dirtyForm + }); + + $(function() { + $(document).on('submit', 'form', function() { + $.fn.qorSlideoutBeforeHide = null; + }); + + $(document).on('change', 'form', function() { + if ($(this).dirtyForm()) { + $.fn.qorSlideoutBeforeHide = true; + } else { + $.fn.qorSlideoutBeforeHide = null; + } + }); + }); +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-filter-time.js b/app/views/qor/assets/javascripts/qor/qor-filter-time.js new file mode 100644 index 0000000..c8455ab --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-filter-time.js @@ -0,0 +1,302 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let location = window.location, + $document = $(document), + NAMESPACE = 'qor.filter', + EVENT_FILTER_CHANGE = 'filterChanged.' + NAMESPACE, + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + CLASS_BOTTOMSHEETS = '.qor-bottomsheets', + CLASS_DATE_START = '.qor-filter__start', + CLASS_DATE_END = '.qor-filter__end', + CLASS_SEARCH_PARAM = '[data-search-param]', + CLASS_FILTER_SELECTOR = '.qor-filter__dropdown', + CLASS_FILTER_TOGGLE = '.qor-filter-toggle', + CLASS_IS_SELECTED = 'is-selected'; + + function QorFilterTime(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorFilterTime.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorFilterTime.prototype = { + constructor: QorFilterTime, + + init: function() { + this.bind(); + let $element = this.$element, + lcoal_moment = window.moment(); + + this.$timeStart = $element.find(CLASS_DATE_START); + this.$timeEnd = $element.find(CLASS_DATE_END); + this.$searchParam = $element.find(CLASS_SEARCH_PARAM); + this.$searchButton = $element.find(this.options.button); + + this.startWeekDate = lcoal_moment.startOf('isoweek').toDate(); + this.endWeekDate = lcoal_moment.endOf('isoweek').toDate(); + + this.startMonthDate = lcoal_moment.startOf('month').toDate(); + this.endMonthDate = lcoal_moment.endOf('month').toDate(); + this.initActionTemplate(); + }, + + bind: function() { + var options = this.options; + + this.$element + .on(EVENT_CLICK, options.trigger, this.show.bind(this)) + .on(EVENT_CLICK, options.label, this.setFilterTime.bind(this)) + .on(EVENT_CLICK, options.clear, this.clear.bind(this)) + .on(EVENT_CLICK, options.button, this.search.bind(this)); + + $document.on(EVENT_CLICK, this.close); + }, + + unbind: function() { + this.$element.off(EVENT_CLICK); + }, + + initActionTemplate: function() { + let paramFrom = this.$element.data('schedule-from'); + let paramTo = this.$element.data('schedule-to'); + + + let scheduleStartAt = this.getUrlParameter(paramFrom || 'schedule_start_at'); + let scheduleEndAt = this.getUrlParameter(paramTo || 'schedule_end_at'); + let $filterToggle = $(this.options.trigger); + + if (scheduleStartAt || scheduleEndAt) { + this.$timeStart.val(scheduleStartAt); + this.$timeEnd.val(scheduleEndAt); + + scheduleEndAt = !scheduleEndAt ? '' : ' - ' + scheduleEndAt; + $filterToggle + .addClass('active clearable') + .find('.qor-selector-label') + .html(scheduleStartAt + scheduleEndAt); + $filterToggle.append('clear'); + } + }, + + show: function() { + this.$element.find(CLASS_FILTER_SELECTOR).toggle(); + }, + + close: function(e) { + var $target = $(e.target), + $filter = $(CLASS_FILTER_SELECTOR), + filterVisible = $filter.is(':visible'), + isInFilter = $target.closest(CLASS_FILTER_SELECTOR).length, + isInToggle = $target.closest(CLASS_FILTER_TOGGLE).length, + isInModal = $target.closest('.qor-modal').length, + isInTimePicker = $target.closest('.ui-timepicker-wrapper').length; + + if (filterVisible && (isInFilter || isInToggle || isInModal || isInTimePicker)) { + return; + } + $filter.hide(); + }, + + setFilterTime: function(e) { + let $target = $(e.target), + data = $target.data(), + range = data.filterRange, + startTime, + endTime, + startDate, + endDate; + + if (!range) { + return false; + } + + $(this.options.label).removeClass(CLASS_IS_SELECTED); + $target.addClass(CLASS_IS_SELECTED); + + if (range == 'events') { + this.$timeStart.val(data.scheduleStartAt || ''); + this.$timeEnd.val(data.scheduleEndAt || ''); + this.$searchButton.click(); + return false; + } + + switch (range) { + case 'today': + startDate = endDate = new Date(); + break; + case 'week': + startDate = this.startWeekDate; + endDate = this.endWeekDate; + break; + case 'month': + startDate = this.startMonthDate; + endDate = this.endMonthDate; + break; + } + + if (!startDate || !endDate) { + return false; + } + + startTime = this.getTime(startDate) + ' 00:00'; + endTime = this.getTime(endDate) + ' 23:59'; + + this.$timeStart.val(startTime); + this.$timeEnd.val(endTime); + this.$searchButton.click(); + }, + + getTime: function(dateNow) { + var month = dateNow.getMonth() + 1, + date = dateNow.getDate(); + + month = month < 10 ? '0' + month : month; + date = date < 10 ? '0' + date : date; + + return dateNow.getFullYear() + '-' + month + '-' + date; + }, + + clear: function() { + var $trigger = $(this.options.trigger), + $label = $trigger.find('.qor-selector-label'); + + $trigger.removeClass('active clearable'); + $label.html($label.data('label')); + this.$timeStart.val(''); + this.$timeEnd.val(''); + + this.$searchButton.click(); + return false; + }, + + getUrlParameter: function(name) { + let search = decodeURIComponent(location.search), + parameterName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'), + regex = new RegExp('[\\?&]' + parameterName + '=([^&#]*)'), + results = regex.exec(search); + + return results === null ? '' : results[1].replace(/\+/g, ' '); + }, + + updateQueryStringParameter: function(key, value, url) { + let href = url || location.href, + local_hash = href.match(/#\S*$/) || '', + escapedkey = String(key).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'), + re = new RegExp('([?&])' + escapedkey + '=.*?(&|$)', 'i'), + separator = href.indexOf('?') !== -1 ? '&' : '?'; + + if (local_hash) { + local_hash = local_hash[0]; + href = href.replace(local_hash, ''); + } + + if (href.match(re)) { + if (value) { + href = href.replace(re, '$1' + key + '=' + value + '$2'); + } else { + if (RegExp.$1 === '?' || RegExp.$1 === RegExp.$2) { + href = href.replace(re, '$1'); + } else { + href = href.replace(re, ''); + } + } + } else if (value) { + href = href + separator + key + '=' + value; + } + + return href + local_hash; + }, + + search: function() { + var $searchParam = this.$searchParam, + href = location.href, + _this = this, + type = 'qor.filter.time'; + + if (!$searchParam.length) { + return; + } + + $searchParam.each(function() { + var $this = $(this), + searchParam = $this.data().searchParam, + val = $this.val(); + + href = _this.updateQueryStringParameter(searchParam, val, href); + }); + + if (this.$element.closest(CLASS_BOTTOMSHEETS).length) { + $(CLASS_BOTTOMSHEETS).trigger(EVENT_FILTER_CHANGE, [href, type]); + } else { + location.href = href; + } + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorFilterTime.DEFAULTS = { + label: false, + trigger: false, + button: false, + clear: false + }; + + QorFilterTime.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorFilterTime(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = '[data-toggle="qor.filter.time"]'; + var options = { + label: '.qor-filter__block-buttons button', + trigger: 'a.qor-filter-toggle', + button: '.qor-filter__button-search', + clear: '.qor-selector-clear' + }; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorFilterTime.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorFilterTime.plugin.call($(selector, e.target), options); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorFilterTime; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-filter.js b/app/views/qor/assets/javascripts/qor/qor-filter.js new file mode 100644 index 0000000..ad9d0d5 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-filter.js @@ -0,0 +1,237 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let location = window.location, + NAMESPACE = 'qor.filter', + EVENT_FILTER_CHANGE = 'filterChanged.' + NAMESPACE, + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_CHANGE = 'change.' + NAMESPACE, + CLASS_IS_ACTIVE = 'is-active', + CLASS_BOTTOMSHEETS = '.qor-bottomsheets'; + + function encodeSearch(data, detached) { + var search = decodeURI(location.search); + var per_page = location.search.match(/per_page=\d+/); + var params; + + search = search.replace(/per_page=\d+/g,'').replace(/page=\d+/,'page=1'); + + + if(per_page && per_page.length){ + search = search + "&" + per_page[0]; + } + + + if ($.isArray(data)) { + params = decodeSearch(search); + + $.each(data, function(i, param) { + i = $.inArray(param, params); + + if (i === -1) { + params.push(param); + } else if (detached) { + params.splice(i, 1); + } + }); + + search = '?' + params.join('&'); + } + + return search; + } + + function decodeSearch(search) { + var data = []; + + if (search && search.indexOf('?') > -1) { + search = search.replace(/\+/g, ' ').split('?')[1]; + + if (search && search.indexOf('#') > -1) { + search = search.split('#')[0]; + } + + if (search) { + // search = search.toLowerCase(); + data = $.map(search.split('&'), function(n) { + var param = []; + var value; + + n = n.split('='); + value = n[1]; + param.push(n[0]); + + if (value) { + value = $.trim(decodeURIComponent(value)); + + if (value) { + param.push(value); + } + } + + return param.join('='); + }); + } + } + + return data; + } + + function QorFilter(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorFilter.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorFilter.prototype = { + constructor: QorFilter, + + init: function() { + // this.parse(); + this.bind(); + }, + + bind: function() { + var options = this.options; + + this.$element.on(EVENT_CLICK, options.label, $.proxy(this.toggle, this)).on(EVENT_CHANGE, options.group, $.proxy(this.toggle, this)); + }, + + unbind: function() { + this.$element.off(EVENT_CLICK, this.toggle).off(EVENT_CHANGE, this.toggle); + }, + + toggle: function(e) { + let $target = $(e.currentTarget), + data = [], + params, + param, + search, + name, + value, + index, + matched, + paramName; + + if ($target.is('select')) { + params = decodeSearch(decodeURI(location.search)); + + paramName = name = $target.attr('name'); + value = $target.val(); + param = [name]; + + if (value) { + param.push(value); + } + + param = param.join('='); + + if (value) { + data.push(param); + } + + $target.children().each(function() { + var $this = $(this); + var param = [name]; + var value = $.trim($this.prop('value')); + + if (value) { + param.push(value); + } + + param = param.join('='); + index = $.inArray(param, params); + + if (index > -1) { + matched = param; + return false; + } + }); + + if (matched) { + data.push(matched); + search = encodeSearch(data, true); + } else { + search = encodeSearch(data); + } + } else if ($target.is('a')) { + e.preventDefault(); + paramName = $target.data().paramName; + data = decodeSearch($target.attr('href')); + if ($target.hasClass(CLASS_IS_ACTIVE)) { + search = encodeSearch(data, true); // set `true` to detach + } else { + search = encodeSearch(data); + } + } + + if (this.$element.closest(CLASS_BOTTOMSHEETS).length) { + $(CLASS_BOTTOMSHEETS).trigger(EVENT_FILTER_CHANGE, [search, paramName]); + } else { + location.search = search; + } + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorFilter.DEFAULTS = { + label: false, + group: false + }; + + QorFilter.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorFilter(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = '[data-toggle="qor.filter"]'; + var options = { + label: 'a', + group: 'select' + }; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorFilter.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorFilter.plugin.call($(selector, e.target), options); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorFilter; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-fixer.js b/app/views/qor/assets/javascripts/qor/qor-fixer.js new file mode 100644 index 0000000..c214b9c --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-fixer.js @@ -0,0 +1,169 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let $window = $(window), + NAMESPACE = 'qor.fixer', + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_RESIZE = 'resize.' + NAMESPACE, + EVENT_SCROLL = 'scroll.' + NAMESPACE, + CLASS_FIXED_TABLE = 'qor-table-fixed-header', + CLASS_HEADER = '.qor-page__header'; + + function QorFixer(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorFixer.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorFixer.prototype = { + constructor: QorFixer, + + init: function() { + var options = this.options; + var $this = this.$element; + if (this.isNeedBuild()) { + return; + } + this.$thead = $this.find('> thead'); + this.$tbody = $this.find('> tbody'); + + this.$header = $(options.header); + this.$subHeader = $(options.subHeader); + this.$content = $(options.content); + this.marginBottomPX = parseInt(this.$subHeader.css('marginBottom')); + this.paddingHeight = options.paddingHeight; + + this.resize(); + this.bind(); + }, + + bind: function() { + this.$content.on(EVENT_SCROLL, this.toggle.bind(this)); + $window.on(EVENT_RESIZE, this.resize.bind(this)); + }, + + unbind: function() { + this.$content.off(EVENT_SCROLL, this.toggle).off(EVENT_RESIZE, this.resize); + }, + + isNeedBuild: function() { + var $this = this.$element; + // disable fixer if have multiple tables or in search page or in media library list page + if ( + $('.qor-page__body .qor-js-table').length > 1 || + $('.qor-global-search--container').length > 0 || + $this.hasClass('qor-table--medialibrary') || + $this.is(':hidden') || + $this.find('tbody > tr:visible').length <= 1 || + $this.data("disable-fixer") + ) { + return true; + } + return false; + }, + + build: function() { + let headerWidth = [], + $items = this.$tbody.find('> tr:first').children(); + + $items.each(function() { + let tdWidth = $(this).outerWidth(); + $(this).outerWidth(tdWidth); + headerWidth.push(tdWidth); + }); + + this.$thead + .find('>tr') + .children() + .each(function(i) { + $(this).outerWidth(headerWidth[i]); + }); + }, + + toggle: function() { + if (!this.$content.length) { + return; + } + let $element = this.$element, + $thead = this.$thead, + scrollTop = this.$content.scrollTop(), + offsetTop = this.$subHeader.outerHeight() + this.paddingHeight + this.marginBottomPX, + headerHeight = $('.qor-page__header').outerHeight(), + pageTop = this.$content.offset().top + $(CLASS_HEADER).height(); + + if (scrollTop > offsetTop - headerHeight) { + $thead.css({top: pageTop}); + $element.addClass(CLASS_FIXED_TABLE); + } else { + $element.removeClass(CLASS_FIXED_TABLE); + } + }, + + resize: function() { + this.build(); + this.toggle(); + }, + + destroy: function() { + if (this.buildCheck()) { + return; + } + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorFixer.DEFAULTS = { + header: false, + content: false + }; + + QorFixer.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + $this.data(NAMESPACE, (data = new QorFixer(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.call(data); + } + }); + }; + + $(function() { + var selector = '.qor-js-table'; + var options = { + header: '.mdl-layout__header', + subHeader: '.qor-page__header', + content: '.mdl-layout__content', + paddingHeight: 2 // Fix sub header height bug + }; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorFixer.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorFixer.plugin.call($(selector, e.target), options); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorFixer; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-inline-edit.js b/app/views/qor/assets/javascripts/qor/qor-inline-edit.js new file mode 100644 index 0000000..0dfa19e --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-inline-edit.js @@ -0,0 +1,202 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + const NAMESPACE = 'qor.inlineEdit', + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_MOUSEENTER = 'mouseenter.' + NAMESPACE, + EVENT_MOUSELEAVE = 'mouseleave.' + NAMESPACE, + CLASS_FIELD = '.qor-field', + CLASS_FIELD_SHOW = '.qor-field__show', + CLASS_FIELD_SHOW_INNER = '.qor-field__show-inner', + CLASS_EDIT = '.qor-inlineedit__edit', + CLASS_SAVE = '.qor-inlineedit__save', + CLASS_BUTTONS = '.qor-inlineedit__buttons', + CLASS_CANCEL = '.qor-inlineedit__cancel', + CLASS_CONTAINER = 'qor-inlineedit__field'; + + function QorInlineEdit(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorInlineEdit.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + function getJsonData(names, data) { + let key, + value = data[names[0].slice(1)]; + + if (names.length > 1) { + for (let i = 1; i < names.length; i++) { + key = names[i].slice(1); + value = $.isArray(value) ? value[0][key] : value[key]; + } + } + + return value; + } + + QorInlineEdit.prototype = { + constructor: QorInlineEdit, + + init: function() { + let $element = this.$element, + saveButton = $element.data('button-save'), + cancelButton = $element.data('button-cancel'); + + this.TEMPLATE_SAVE = `
          + + +
          `; + this.bind(); + }, + + bind: function() { + this.$element + .on(EVENT_MOUSEENTER, CLASS_FIELD_SHOW, this.showEditButton) + .on(EVENT_MOUSELEAVE, CLASS_FIELD_SHOW, this.hideEditButton) + .on(EVENT_CLICK, CLASS_CANCEL, this.hideEdit) + .on(EVENT_CLICK, CLASS_SAVE, this.saveEdit) + .on(EVENT_CLICK, CLASS_EDIT, this.showEdit.bind(this)); + }, + + unbind: function() { + this.$element + .off(EVENT_MOUSEENTER) + .off(EVENT_MOUSELEAVE) + .off(EVENT_CLICK); + }, + + showEditButton: function(e) { + let $edit = $(QorInlineEdit.TEMPLATE_EDIT), + $field = $(e.target).closest(CLASS_FIELD); + + if ($field.find('input:disabled, textarea:disabled,select:disabled').length) { + return false; + } + + $edit.appendTo($(this)); + }, + + hideEditButton: function() { + $('.qor-inlineedit__edit').remove(); + }, + + showEdit: function(e) { + let $parent = $(e.target) + .closest(CLASS_EDIT) + .hide() + .closest(CLASS_FIELD) + .addClass(CLASS_CONTAINER), + $save = $(this.TEMPLATE_SAVE); + + $save.appendTo($parent); + }, + + hideEdit: function() { + let $parent = $(this) + .closest(CLASS_FIELD) + .removeClass(CLASS_CONTAINER); + $parent.find(CLASS_BUTTONS).remove(); + }, + + saveEdit: function() { + let $btn = $(this), + $parent = $btn.closest(CLASS_FIELD), + $form = $btn.closest('form'), + $hiddenInput = $parent.closest('.qor-fieldset').find('input.qor-hidden__primary_key[type="hidden"]'), + $input = $parent.find('input[name*="QorResource"],textarea[name*="QorResource"],select[name*="QorResource"]'), + names = $input.length && $input.prop('name').match(/\.\w+/g), + inputData = $input.serialize(); + + if ($hiddenInput.length) { + inputData = `${inputData}&${$hiddenInput.serialize()}`; + } + + if (names.length) { + $.ajax($form.prop('action'), { + method: $form.prop('method'), + data: inputData, + dataType: 'json', + beforeSend: function() { + $btn.prop('disabled', true); + }, + success: function(data) { + let newValue = getJsonData(names, data), + $show = $parent.removeClass(CLASS_CONTAINER).find(CLASS_FIELD_SHOW), + $inner = $show.find(CLASS_FIELD_SHOW_INNER); + + if (typeof newValue === 'string' || newValue instanceof String){ + newValue = newValue.escapeSymbol(); + } + + if ($inner.length) { + $inner.html(newValue); + } else { + $show.html(newValue); + } + + $parent.find(CLASS_BUTTONS).remove(); + $btn.prop('disabled', false); + }, + error: function(err) { + window.QOR.handleAjaxError(err); + $btn.prop('disabled', false); + } + }); + } + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorInlineEdit.DEFAULTS = {}; + + QorInlineEdit.TEMPLATE_EDIT = ``; + + QorInlineEdit.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + $this.data(NAMESPACE, (data = new QorInlineEdit(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.call(data); + } + }); + }; + + $(function() { + let selector = '[data-toggle="qor.inlineEdit"]', + options = {}; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorInlineEdit.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorInlineEdit.plugin.call($(selector, e.target), options); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorInlineEdit; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-material.js b/app/views/qor/assets/javascripts/qor/qor-material.js new file mode 100644 index 0000000..cdd7bea --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-material.js @@ -0,0 +1,59 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let componentHandler = window.componentHandler, + NAMESPACE = 'qor.material', + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_UPDATE = 'update.' + NAMESPACE, + SELECTOR_COMPONENT = '[class*="mdl-js"],[class*="mdl-tooltip"]'; + + function enable(target) { + /*jshint undef:false */ + if (componentHandler) { + // Enable all MDL (Material Design Lite) components within the target element + if ($(target).is(SELECTOR_COMPONENT)) { + componentHandler.upgradeElements(target); + } else { + componentHandler.upgradeElements($(SELECTOR_COMPONENT, target).toArray()); + } + } + } + + function disable(target) { + /*jshint undef:false */ + if (componentHandler) { + // Destroy all MDL (Material Design Lite) components within the target element + if ($(target).is(SELECTOR_COMPONENT)) { + componentHandler.downgradeElements(target); + } else { + componentHandler.downgradeElements($(SELECTOR_COMPONENT, target).toArray()); + } + } + } + + $(function() { + $(document) + .on(EVENT_ENABLE, function(e) { + enable(e.target); + }) + .on(EVENT_DISABLE, function(e) { + disable(e.target); + }) + .on(EVENT_UPDATE, function(e) { + disable(e.target); + enable(e.target); + }); + }); +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-modal.js b/app/views/qor/assets/javascripts/qor/qor-modal.js new file mode 100644 index 0000000..35ac03f --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-modal.js @@ -0,0 +1,235 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let $document = $(document), + NAMESPACE = 'qor.modal', + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_KEYUP = 'keyup.' + NAMESPACE, + EVENT_SHOW = 'show.' + NAMESPACE, + EVENT_SHOWN = 'shown.' + NAMESPACE, + EVENT_HIDE = 'hide.' + NAMESPACE, + EVENT_HIDDEN = 'hidden.' + NAMESPACE, + EVENT_TRANSITION_END = 'transitionend', + CLASS_OPEN = 'qor-modal-open', + CLASS_SHOWN = 'shown', + CLASS_FADE = 'fade', + CLASS_IN = 'in', + ARIA_HIDDEN = 'aria-hidden'; + + function QorModal(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorModal.DEFAULTS, $.isPlainObject(options) && options); + this.transitioning = false; + this.fadable = false; + this.init(); + } + + QorModal.prototype = { + constructor: QorModal, + + init: function() { + this.fadable = this.$element.hasClass(CLASS_FADE); + + if (this.options.show) { + this.show(); + } else { + this.toggle(); + } + }, + + bind: function() { + this.$element.on(EVENT_CLICK, $.proxy(this.click, this)); + + if (this.options.keyboard) { + $document.on(EVENT_KEYUP, $.proxy(this.keyup, this)); + } + }, + + unbind: function() { + this.$element.off(EVENT_CLICK, this.click); + + if (this.options.keyboard) { + $document.off(EVENT_KEYUP, this.keyup); + } + }, + + click: function(e) { + var element = this.$element[0]; + var target = e.target; + + if (target === element && this.options.backdrop) { + this.hide(); + return; + } + + while (target !== element) { + if ($(target).data('dismiss') === 'modal') { + this.hide(); + break; + } + + target = target.parentNode; + } + }, + + keyup: function(e) { + if (e.which === 27) { + this.hide(); + } + }, + + show: function(noTransition) { + var $this = this.$element, + showEvent; + + if (this.transitioning || $this.hasClass(CLASS_IN)) { + return; + } + + showEvent = $.Event(EVENT_SHOW); + $this.trigger(showEvent); + + if (showEvent.isDefaultPrevented()) { + return; + } + + $document.find('body').addClass(CLASS_OPEN); + + /*jshint expr:true */ + $this + .addClass(CLASS_SHOWN) + .scrollTop(0) + .get(0).offsetHeight; // reflow for transition + this.transitioning = true; + + if (noTransition || !this.fadable) { + $this.addClass(CLASS_IN); + this.shown(); + return; + } + + $this.one(EVENT_TRANSITION_END, $.proxy(this.shown, this)); + $this.addClass(CLASS_IN); + }, + + shown: function() { + this.transitioning = false; + this.bind(); + this.$element + .attr(ARIA_HIDDEN, false) + .trigger(EVENT_SHOWN) + .focus(); + }, + + hide: function(noTransition) { + var $this = this.$element, + hideEvent; + + if (this.transitioning || !$this.hasClass(CLASS_IN)) { + return; + } + + hideEvent = $.Event(EVENT_HIDE); + $this.trigger(hideEvent); + + if (hideEvent.isDefaultPrevented()) { + return; + } + + $document.find('body').removeClass(CLASS_OPEN); + this.transitioning = true; + + if (noTransition || !this.fadable) { + $this.removeClass(CLASS_IN); + this.hidden(); + return; + } + + $this.one(EVENT_TRANSITION_END, $.proxy(this.hidden, this)); + $this.removeClass(CLASS_IN); + }, + + hidden: function() { + this.transitioning = false; + this.unbind(); + this.$element + .removeClass(CLASS_SHOWN) + .attr(ARIA_HIDDEN, true) + .trigger(EVENT_HIDDEN); + }, + + toggle: function() { + if (this.$element.hasClass(CLASS_IN)) { + this.hide(); + } else { + this.show(); + } + }, + + destroy: function() { + this.$element.removeData(NAMESPACE); + } + }; + + QorModal.DEFAULTS = { + backdrop: false, + keyboard: true, + show: true + }; + + QorModal.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorModal(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $.fn.qorModal = QorModal.plugin; + + $(function() { + var selector = '.qor-modal'; + + $(document) + .on(EVENT_CLICK, '[data-toggle="qor.modal"]', function() { + var $this = $(this); + var data = $this.data(); + var $target = $(data.target || $this.attr('href')); + + QorModal.plugin.call($target, $target.data(NAMESPACE) ? 'toggle' : data); + }) + .on(EVENT_DISABLE, function(e) { + QorModal.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorModal.plugin.call($(selector, e.target)); + }); + }); + + return QorModal; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-radio-tabs.js b/app/views/qor/assets/javascripts/qor/qor-radio-tabs.js new file mode 100644 index 0000000..270f83e --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-radio-tabs.js @@ -0,0 +1,109 @@ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function ($) { + + 'use strict'; + + var NAMESPACE = 'qor.tabbar.radio'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + var EVENT_CLICK = 'click.' + NAMESPACE; + var EVENT_SWITCHED = 'switched.' + NAMESPACE; + var CLASS_TAB = '[data-tab-target]'; + var CLASS_TAB_SOURCE = '[data-tab-source]'; + var CLASS_ACTIVE = 'is-active'; + + function QorTabRadio(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorTabRadio.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorTabRadio.prototype = { + constructor: QorTabRadio, + + init: function () { + this.bind(); + }, + + bind: function () { + this.$element.on(EVENT_CLICK, CLASS_TAB, this.switchTab.bind(this)); + }, + + unbind: function () { + this.$element.off(EVENT_CLICK, CLASS_TAB, this.switchTab); + }, + + + switchTab: function (e) { + var $target = $(e.target), + $element = this.$element, + $tabs = $element.find(CLASS_TAB), + $tabSources = $element.find(CLASS_TAB_SOURCE), + data = $target.data(), + tabTarget = data.tabTarget; + + if ($target.hasClass(CLASS_ACTIVE)){ + return; + } + + $tabs.removeClass(CLASS_ACTIVE); + $target.addClass(CLASS_ACTIVE); + + $tabSources.hide().filter('[data-tab-source="' + tabTarget + '"]').show(); + $element.trigger(EVENT_SWITCHED, [$element, tabTarget]); + + }, + + destroy: function () { + this.unbind(); + } + }; + + QorTabRadio.DEFAULTS = {}; + + QorTabRadio.plugin = function (options) { + return this.each(function () { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorTabRadio(this, options))); + } + + if (typeof options === 'string' && $.isFunction(fn = data[options])) { + fn.apply(data); + } + }); + }; + + $(function () { + var selector = '[data-toggle="qor.tab.radio"]'; + + $(document) + .on(EVENT_DISABLE, function (e) { + QorTabRadio.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function (e) { + QorTabRadio.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorTabRadio; + +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-redactor.js b/app/views/qor/assets/javascripts/qor/qor-redactor.js new file mode 100644 index 0000000..a598181 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-redactor.js @@ -0,0 +1,452 @@ +(function(factory) { + if (typeof define === "function" && define.amd) { + // AMD. Register as anonymous module. + define(["jquery"], factory); + } else if (typeof exports === "object") { + // Node / CommonJS + factory(require("jquery")); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + "use strict"; + + let NAMESPACE = "qor.redactor", + EVENT_ENABLE = "enable." + NAMESPACE, + EVENT_DISABLE = "disable." + NAMESPACE, + EVENT_CLICK = "click." + NAMESPACE, + EVENT_ADD_CROP = "addCrop." + NAMESPACE, + EVENT_REMOVE_CROP = "removeCrop." + NAMESPACE, + EVENT_SHOWN = "shown.qor.modal", + EVENT_HIDDEN = "hidden.qor.modal", + EVENT_SCROLL = "scroll." + NAMESPACE, + CLASS_WRAPPER = ".qor-cropper__wrapper", + CLASS_SAVE = ".qor-cropper__save", + CLASS_CROPPER_TOGGLE = ".qor-cropper__toggle--redactor"; + + function encodeCropData(data) { + var nums = []; + + if ($.isPlainObject(data)) { + $.each(data, function() { + nums.push(arguments[1]); + }); + } + + return nums.join(); + } + + function decodeCropData(data) { + var nums = data && data.split(","); + + data = null; + + if (nums && nums.length === 4) { + data = { + x: Number(nums[0]), + y: Number(nums[1]), + width: Number(nums[2]), + height: Number(nums[3]) + }; + } + + return data; + } + + function capitalize(str) { + if (typeof str === "string") { + str = str.charAt(0).toUpperCase() + str.substr(1); + } + + return str; + } + + function getCapitalizeKeyObject(obj) { + var newObj = {}, + key; + + if ($.isPlainObject(obj)) { + for (key in obj) { + if (obj.hasOwnProperty(key)) { + newObj[capitalize(key)] = obj[key]; + } + } + } + + return newObj; + } + + function replaceText(str, data) { + if (typeof str === "string") { + if (typeof data === "object") { + $.each(data, function(key, val) { + str = str.replace("$[" + String(key).toLowerCase() + "]", val); + }); + } + } + + return str; + } + + function redactorToolbarSrcoll($toolbar, $container, toolbarFixedTopOffset) { + let offsetTop = $container.offset().top, + containerHeight = $container.outerHeight(), + normallCSS = { + position: "relative", + top: "auto", + width: "auto" + }, + fixedCSS = { + position: "fixed", + top: toolbarFixedTopOffset, + width: $container.width(), + boxShadow: "none" + }; + if (offsetTop < toolbarFixedTopOffset) { + if ( + Math.abs(offsetTop) < Math.abs(containerHeight - toolbarFixedTopOffset) + ) { + $toolbar.css(fixedCSS); + $container.css("padding-top", $toolbar.outerHeight()); + } else { + $toolbar.css(normallCSS); + $container.css("padding-top", 0); + } + } else { + $toolbar.css(normallCSS); + $container.css("padding-top", 0); + } + } + + function QorRedactor(element, options) { + this.$element = $(element); + this.options = $.extend( + true, + {}, + QorRedactor.DEFAULTS, + $.isPlainObject(options) && options + ); + this.init(); + } + + QorRedactor.prototype = { + constructor: QorRedactor, + + init: function() { + var options = this.options; + var $this = this.$element; + var $parent = $this.closest(options.parent); + + if (!$parent.length) { + $parent = $this.parent(); + } + + this.$parent = $parent; + this.$button = $(QorRedactor.BUTTON); + this.$modal = $(replaceText(QorRedactor.MODAL, options.text)).appendTo( + "body" + ); + this.bind(); + }, + + bind: function() { + this.$element + .on(EVENT_ADD_CROP, $.proxy(this.addButton, this)) + .on(EVENT_REMOVE_CROP, $.proxy(this.removeButton, this)); + }, + + unbind: function() { + this.$element + .off(EVENT_ADD_CROP) + .off(EVENT_REMOVE_CROP) + .off(EVENT_SCROLL); + }, + + addButton: function(e, image) { + var $image = $(image); + + this.$button + .css("left", $(image).width() / 2) + .prependTo($image.parent()) + .find(CLASS_CROPPER_TOGGLE) + .one(EVENT_CLICK, $.proxy(this.crop, this, $image)); + }, + + removeButton: function() { + this.$button.find(CLASS_CROPPER_TOGGLE).off(EVENT_CLICK); + this.$button.detach(); + }, + + crop: function($image) { + let options = this.options, + url = $image.attr("src"), + originalUrl = url, + $clone, + $modal = this.$modal; + + if ($.isFunction(options.replace)) { + originalUrl = options.replace(originalUrl); + } + + $clone = $(``); + + $modal + .one(EVENT_SHOWN, function() { + $clone.cropper({ + data: decodeCropData($image.attr("data-crop-options")), + background: false, + movable: false, + zoomable: false, + scalable: false, + rotatable: false, + checkImageOrigin: false, + + ready: function() { + $modal.find(CLASS_SAVE).one(EVENT_CLICK, function() { + var cropData = $clone.cropper("getData", true); + + $.ajax(options.remote, { + type: "POST", + contentType: "application/json", + data: JSON.stringify({ + Url: url, + CropOptions: { + original: getCapitalizeKeyObject(cropData) + }, + Crop: true + }), + dataType: "json", + + success: function(response) { + if ($.isPlainObject(response) && response.url) { + $image + .attr("src", response.url) + .attr("data-crop-options", encodeCropData(cropData)) + .removeAttr("style") + .removeAttr("rel"); + + if ($.isFunction(options.complete)) { + options.complete(); + } + $modal.qorModal("hide"); + } + } + }); + }); + } + }); + }) + .one(EVENT_HIDDEN, function() { + $clone.cropper("destroy").remove(); + }) + .qorModal("show") + .find(CLASS_WRAPPER) + .append($clone); + }, + + destroy: function() { + this.unbind(); + this.$modal.qorModal("hide").remove(); + this.$element.removeData(NAMESPACE); + } + }; + + QorRedactor.DEFAULTS = { + remote: false, + parent: false, + toggle: false, + replace: null, + complete: null, + text: { + title: "Crop the image", + ok: "OK", + cancel: "Cancel" + } + }; + + QorRedactor.BUTTON = `
          + Edit + Crop +
          `; + + QorRedactor.MODAL = ``; + + QorRedactor.plugin = function(option) { + return this.each(function() { + let $this = $(this), + data = $this.data(NAMESPACE), + config, + fn; + + if (!data) { + if (!window.$R) { + return; + } + + if (/destroy/.test(option)) { + return; + } + + $this.data(NAMESPACE, (data = {})); + + let editorButtons = [ + "html", + "format", + "bold", + "italic", + "deleted", + "lists", + "image", + "file", + "link" + ]; + + config = { + imageUpload: $this.data("uploadUrl"), + fileUpload: $this.data("uploadUrl"), + buttons: editorButtons, + linkNewTab: true, + linkTitle: false, + autoparsePaste: false, + autoparseLinks: false, + multipleUpload: false, + toolbarFixedTarget: + !$this.closest(".qor-slideout").length && + !$this.closest(".qor-bottomsheets").length + ? $("main.mdl-layout__content").length + ? "main.mdl-layout__content" + : document + : document, + + callbacks: { + started: function() { + let $container = $(this.container.$container.nodes[0]), + $toolbar = $(this.toolbar.$toolbar.nodes[0]), + isInSlideout = $(".qor-slideout").is(":visible"), + toolbarFixedTarget, + toolbarFixedTopOffset = 64; + + if (isInSlideout) { + if ($this.closest(".qor-bottomsheets").length != 0) { + toolbarFixedTarget = $this.closest(".qor-page__body"); + toolbarFixedTopOffset = $this + .closest(".qor-page__body") + .offset().top; + } else { + toolbarFixedTarget = ".qor-slideout__body"; + toolbarFixedTopOffset = $(".qor-slideout__header").height(); + } + } else { + toolbarFixedTarget = ".qor-layout main.qor-page"; + toolbarFixedTopOffset = + toolbarFixedTopOffset + + $(toolbarFixedTarget) + .find(".qor-page__header") + .height(); + } + + $(toolbarFixedTarget).on(EVENT_SCROLL, function() { + redactorToolbarSrcoll( + $toolbar, + $container, + toolbarFixedTopOffset + ); + }); + + if (!$this.data("cropUrl")) { + return; + } + + $this.data( + NAMESPACE, + (data = new QorRedactor($this, { + remote: $this.data("cropUrl"), + text: $this.data("text"), + parent: ".qor-field", + toggle: ".qor-cropper__toggle--redactor", + replace: function(url) { + return url.replace(/\.\w+$/, function(extension) { + return ".original" + extension; + }); + }, + complete: $.proxy(function() { + this.code.sync(); + }, this) + })) + ); + }, + + imageUpload: function(image, json) { + var $image = $(image); + json.filelink && $image.prop("src", json.filelink); + }, + + insertedLink: function(link) { + var $link = $(link), + description = this.link.description; + + $link.prop("title", description ? description : $link.text()); + this.link.description = ""; + this.link.linkUrlText = ""; + this.link.insertedTriggered = true; + }, + + fileUpload: function(link, json) { + $(link) + .prop("href", json.filelink) + .html(json.filename); + } + } + }; + + $.extend(config, $this.data("redactorSettings")); + window.$R.prototype.constructor.services.editor.prototype.focus = function() { + return false; + }; + window.$R(this, config); + } else { + if (/destroy/.test(option)) { + window.$R(this, "destroy"); + } + } + + if (typeof option === "string" && $.isFunction((fn = data[option]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = 'textarea[data-toggle="qor.redactor"]'; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorRedactor.plugin.call($(selector, e.target), "destroy"); + }) + .on(EVENT_ENABLE, function(e) { + QorRedactor.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorRedactor; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-replicator.js b/app/views/qor/assets/javascripts/qor/qor-replicator.js new file mode 100644 index 0000000..7827707 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-replicator.js @@ -0,0 +1,417 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let _ = window._, + QOR = window.QOR, + NAMESPACE = 'qor.replicator', + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_SUBMIT = 'submit.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_SLIDEOUTBEFORESEND = 'slideoutBeforeSend.qor.slideout.replicator', + EVENT_SELECTCOREBEFORESEND = 'selectcoreBeforeSend.qor.selectcore.replicator bottomsheetBeforeSend.qor.bottomsheets.replicator', + EVENT_REPLICATOR_ADDED = 'added.' + NAMESPACE, + EVENT_REPLICATORS_ADDED = 'addedMultiple.' + NAMESPACE, + EVENT_REPLICATORS_ADDED_DONE = 'addedMultipleDone.' + NAMESPACE, + CLASS_CONTAINER = '.qor-fieldset-container'; + + function QorReplicator(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorReplicator.DEFAULTS, $.isPlainObject(options) && options); + this.index = 0; + this.init(); + } + + QorReplicator.prototype = { + constructor: QorReplicator, + + init: function() { + let $element = this.$element, + $template = $element.find('> .qor-field__block > .qor-fieldset--new'), + fieldsetName; + + this.singlePage = !($element.closest('.qor-slideout').length && $element.closest('.qor-bottomsheets').length); + this.maxitems = $element.data('maxItem'); + this.isSortable = $element.hasClass('qor-fieldset-sortable'); + + if (!$template.length || $element.closest('.qor-fieldset--new').length) { + return; + } + + // Should destroy all components here + $template.trigger('disable'); + // remove data-select2-id attribute or select2 will disable all previous instance + $template.find('select[data-toggle]').removeAttr('data-select2-id'); + + // if have isMultiple data value or template length large than 1 + this.isMultipleTemplate = $element.data('isMultiple'); + + if (this.isMultipleTemplate) { + this.fieldsetName = []; + this.template = {}; + this.index = []; + + $template.each((i, ele) => { + fieldsetName = $(ele).data('fieldsetName'); + if (fieldsetName) { + this.template[fieldsetName] = $(ele).prop('outerHTML'); + this.fieldsetName.push(fieldsetName); + } + }); + + this.parseMultiple(); + } else { + this.parse($template.prop('outerHTML')); + } + + $template.hide(); + this.bind(); + this.resetButton(); + this.resetPositionButton(); + }, + + resetPositionButton: function() { + let sortableButton = this.$element.find('> .qor-sortable__button'); + + if (this.isSortable) { + if (this.getCurrentItems() > 1) { + sortableButton.show(); + } else { + sortableButton.hide(); + } + } + }, + + getCurrentItems: function() { + return this.$element.find('> .qor-field__block > .qor-fieldset').not('.qor-fieldset--new,.is-deleted').length; + }, + + toggleButton: function(isHide) { + let $button = this.$element.find('> .qor-field__block > .qor-fieldset__add'); + + if (isHide) { + $button.hide(); + } else { + $button.show(); + } + }, + + resetButton: function() { + if (this.maxitems <= this.getCurrentItems()) { + this.toggleButton(true); + } else { + this.toggleButton(); + } + }, + + parse: function($tmp) { + let template; + + if (!$tmp) { + return; + } + template = this.initTemplate($tmp); + + this.template = template.template; + this.index = template.index; + }, + + parseMultiple: function() { + let template, + name, + fieldsetName = this.fieldsetName; + + for (let i = 0, len = fieldsetName.length; i < len; i++) { + name = fieldsetName[i]; + template = this.initTemplate(this.template[name]); + this.template[name] = template.template; + this.index.push(template.index); + } + + this.multipleIndex = _.max(this.index); + }, + + initTemplate: function(template) { + let i, + deepLevel = this.$element.parents(CLASS_CONTAINER).length; + + template = template.replace(/(\w+)\="(\S*\[\d+\]\S*)"/g, function(attribute, name, value) { + value = value.replace(/^(\S*)\[(\d+)\]([^\[\]]*)$/, function(input, prefix, index) { + if (input === value) { + if (name === 'name' && !i) { + i = index; + } + + if (deepLevel) { + // assume input = QorResource.SerializableMeta.Menus[1].SubMenus[2].Items[3].URL + // if deepLevel = 1, input should be QorResource.SerializableMeta.Menus[1].SubMenus[{{index}}].Items[3].URL + // if deepLevel = 2, input should be QorResource.SerializableMeta.Menus[1].SubMenus[2].Items[{{index}}].URL + + let newInput = '', + splitStr = input.split(/\[\d+\]/), // ["QorResource.SerializableMeta.Menus", ".SubMenus", ".Items", ".URL"] + sortNumbers = input.match(/\[\d+\]/g); // ["[1]", "[2]", "[3]"] + + for (let j = 0; j < splitStr.length; j++) { + let str = ''; + if (j === deepLevel) { + str = '[{{index}}]'; + } else if (j < sortNumbers.length) { + str = sortNumbers[j]; + } + newInput += splitStr[j] + str; + } + + return newInput; + } else { + return input.replace(/\[\d+\]/, '[{{index}}]'); + } + } + }); + + return name + '="' + value + '"'; + }); + + return { + template: template, + index: parseFloat(i) + 5 //make sure the index is different from original. + }; + }, + + bind: function() { + let options = this.options; + + this.$element.on(EVENT_CLICK, options.addClass, $.proxy(this.add, this)).on(EVENT_CLICK, options.delClass, $.proxy(this.del, this)); + + this.singlePage && $(document).on(EVENT_SUBMIT, '.mdl-layout__container form', this.clearFieldData); + $(document) + .on(EVENT_SLIDEOUTBEFORESEND, '.qor-slideout', this.clearFieldDataInSlideout) + .on(EVENT_SELECTCOREBEFORESEND, this.clearFieldDataInBottomsheet); + }, + + unbind: function() { + this.$element.off(EVENT_CLICK); + + this.singlePage && $(document).off(EVENT_SUBMIT, '.mdl-layout__container form', this.clearFieldData); + $(document) + .off(EVENT_SLIDEOUTBEFORESEND, '.qor-slideout', this.clearFieldDataInSlideout) + .off(EVENT_SELECTCOREBEFORESEND, this.clearFieldDataInBottomsheet); + }, + + clearFieldData: function() { + $('.qor-fieldset--new').remove(); + }, + + clearFieldDataInSlideout: function() { + $('.qor-slideout .qor-fieldset--new').remove(); + }, + + clearFieldDataInBottomsheet: function() { + $('.qor-bottomsheets .qor-fieldset--new').remove(); + }, + + add: function(e, data, isAutomatically) { + let options = this.options, + $item, + template, + $target = $(e.target).closest(options.addClass); + + if (this.maxitems <= this.getCurrentItems()) { + return false; + } + + if (this.isMultipleTemplate) { + let templateName = $target.data('template'), + parents = $target.closest(this.$element), + parentsChildren = parents.children(options.childrenClass), + $fieldset = $target.closest(options.childrenClass).children('fieldset'); + + template = this.template[templateName]; + $item = $(template.replace(/\{\{index\}\}/g, this.multipleIndex)); + + // get input kind from add button then add into QorResource.Rules[1].Kind input + for (let dataKey in $target.data()) { + if (dataKey.match(/^sync/)) { + let k = dataKey.replace(/^sync/, ''); + $item.find("input[name*='." + k + "']").val($target.data(dataKey)); + } + } + + if ($fieldset.length) { + $fieldset.last().after($item.show()); + } else { + parentsChildren.prepend($item.show()); + } + $item.data('itemIndex', this.multipleIndex).removeClass('qor-fieldset--new'); + this.multipleIndex++; + } else { + if (!isAutomatically) { + $item = this.addSingle(); + $target.before($item.show()); + this.index++; + } else { + if (data && data.length) { + this.addMultiple(data); + $(document).trigger(EVENT_REPLICATORS_ADDED_DONE); + } + } + } + + if (!isAutomatically) { + $item.trigger('enable'); + $(document).trigger(EVENT_REPLICATOR_ADDED, [$item]); + e.stopPropagation(); + } + + this.resetPositionButton(); + this.resetButton(); + }, + + addMultiple: function(data) { + let $item; + + for (let i = 0, len = data.length; i < len; i++) { + $item = this.addSingle(); + this.index++; + $(document).trigger(EVENT_REPLICATORS_ADDED, [$item, data[i]]); + } + }, + + addSingle: function() { + let $item, + $element = this.$element; + + if (!this.template) { + return; + } + + $item = $(this.template.replace(/\{\{index\}\}/g, this.index)); + // add order property for sortable fieldset + if (this.isSortable) { + let order = $element.find('> .qor-field__block > .qor-sortable__item').not('.qor-fieldset--new').length; + $item + .attr('order-index', order) + .attr('order-item', `item_${order}`) + .css('order', order); + } + + $item.data('itemIndex', this.index).removeClass('qor-fieldset--new'); + + return $item; + }, + + del: function(e) { + let options = this.options, + $item = $(e.target).closest(options.itemClass), + $alert, + that = this, + message = { + confirm: + $(e.target) + .closest(options.delClass) + .data('confirm') || 'Are you sure?' + }; + + QOR.qorConfirm(message, function(confirm) { + if (confirm) { + $item + .addClass('is-deleted') + .children(':visible') + .addClass('hidden') + .hide(); + $alert = $(options.alertTemplate.replace('{{name}}', that.parseName($item))); + $alert.find(options.undoClass).one( + EVENT_CLICK, + function() { + if (that.maxitems <= that.getCurrentItems()) { + window.QOR.qorConfirm(that.$element.data('maxItemHint')); + return false; + } + + $item.find('> .qor-fieldset__alert').remove(); + $item + .removeClass('is-deleted') + .children('.hidden') + .removeClass('hidden') + .show(); + that.resetButton(); + that.resetPositionButton(); + }.bind(this) + ); + that.resetButton(); + that.resetPositionButton(); + $item.append($alert); + } + }); + }, + + parseName: function($item) { + let name = $item.find('input[name]').attr('name') || $item.find('textarea[name]').attr('name'); + + if (name) { + return name.replace(/[^\[\]]+$/, ''); + } + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorReplicator.DEFAULTS = { + itemClass: '.qor-fieldset', + newClass: '.qor-fieldset--new', + addClass: '.qor-fieldset__add', + delClass: '.qor-fieldset__delete', + childrenClass: '.qor-field__block', + undoClass: '.qor-fieldset__undo', + alertTemplate: + '
          ' + + '' + + '' + + '
          ' + }; + + QorReplicator.plugin = function(options) { + return this.each(function() { + let $this = $(this), + data = $this.data(NAMESPACE), + fn; + + if (!data) { + $this.data(NAMESPACE, (data = new QorReplicator(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.call(data); + } + }); + }; + + $(function() { + let selector = CLASS_CONTAINER; + let options = {}; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorReplicator.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorReplicator.plugin.call($(selector, e.target), options); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorReplicator; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-search.js b/app/views/qor/assets/javascripts/qor/qor-search.js new file mode 100644 index 0000000..6d7eb1d --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-search.js @@ -0,0 +1,163 @@ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function ($) { + + 'use strict'; + var location = window.location; + var componentHandler = window.componentHandler; + var history = window.history; + var NAMESPACE = 'qor.globalSearch'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + var EVENT_CLICK = 'click.' + NAMESPACE; + + var SEARCH_RESOURCE = '.qor-global-search--resource'; + var SEARCH_RESULTS = '.qor-global-search--results'; + var QOR_TABLE = '.qor-table'; + var IS_ACTIVE = 'is-active'; + + function QorSearchCenter(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorSearchCenter.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorSearchCenter.prototype = { + constructor: QorSearchCenter, + + init: function () { + this.bind(); + this.initTab(); + }, + + bind: function () { + this.$element.on(EVENT_CLICK, $.proxy(this.click, this)); + }, + + unbind: function () { + this.$element.off(EVENT_CLICK, this.check); + }, + + initTab: function () { + var locationSearch = location.search; + var resourceName; + if (/resource_name/.test(locationSearch)){ + resourceName = locationSearch.match(/resource_name=\w+/g).toString().split('=')[1]; + $(SEARCH_RESOURCE).removeClass(IS_ACTIVE); + $('[data-resource="' + resourceName + '"]').addClass(IS_ACTIVE); + } + }, + + click : function (e) { + var $target = $(e.target); + var data = $target.data(); + + if ($target.is(SEARCH_RESOURCE)){ + var oldUrl = location.href.replace(/#/g, ''); + var newUrl; + var newResourceName = data.resource; + var hasResource = /resource_name/.test(oldUrl); + var hasKeyword = /keyword/.test(oldUrl); + var resourceParam = 'resource_name=' + newResourceName; + var searchSymbol = hasKeyword ? '&' : '?keyword=&'; + + if (newResourceName){ + if (hasResource){ + newUrl = oldUrl.replace(/resource_name=\w+/g, resourceParam); + } else { + newUrl = oldUrl + searchSymbol + resourceParam; + } + } else { + newUrl = oldUrl.replace(/&resource_name=\w+/g, ''); + } + + if (history.pushState){ + this.fetchSearch(newUrl, $target); + } else { + location.href = newUrl; + } + + } + }, + + fetchSearch: function (url,$target) { + var title = document.title; + + $.ajax(url, { + method: 'GET', + dataType: 'html', + beforeSend: function () { + $('.mdl-spinner').remove(); + $(SEARCH_RESULTS).prepend('
          ').find('.qor-section').hide(); + componentHandler.upgradeElement(document.querySelector('.mdl-spinner')); + }, + success: function (html) { + var result = $(html).find(SEARCH_RESULTS).html(); + $(SEARCH_RESOURCE).removeClass(IS_ACTIVE); + $target.addClass(IS_ACTIVE); + // change location URL without refresh page + history.pushState({ Page: url, Title: title }, title, url); + $('.mdl-spinner').remove(); + $(SEARCH_RESULTS).removeClass('loading').html(result); + componentHandler.upgradeElements(document.querySelectorAll(QOR_TABLE)); + }, + error: function (xhr, textStatus, errorThrown) { + $(SEARCH_RESULTS).find('.qor-section').show(); + $('.mdl-spinner').remove(); + window.alert([textStatus, errorThrown].join(': ')); + } + }); + }, + + destroy: function () { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + + }; + + QorSearchCenter.DEFAULTS = { + }; + + QorSearchCenter.plugin = function (options) { + return this.each(function () { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + $this.data(NAMESPACE, (data = new QorSearchCenter(this, options))); + } + + if (typeof options === 'string' && $.isFunction(fn = data[options])) { + fn.call(data); + } + }); + }; + + $(function () { + var selector = '[data-toggle="qor.global.search"]'; + var options = {}; + + $(document). + on(EVENT_DISABLE, function (e) { + QorSearchCenter.plugin.call($(selector, e.target), 'destroy'); + }). + on(EVENT_ENABLE, function (e) { + QorSearchCenter.plugin.call($(selector, e.target), options); + }). + triggerHandler(EVENT_ENABLE); + }); + + return QorSearchCenter; + +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-select-core.js b/app/views/qor/assets/javascripts/qor/qor-select-core.js new file mode 100644 index 0000000..1583380 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-select-core.js @@ -0,0 +1,170 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let FormData = window.FormData, + QOR = window.QOR, + NAMESPACE = 'qor.selectcore', + EVENT_SELECTCORE_BEFORESEND = 'selectcoreBeforeSend.' + NAMESPACE, + EVENT_ONSELECT = 'afterSelected.' + NAMESPACE, + EVENT_ONSUBMIT = 'afterSubmitted.' + NAMESPACE, + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_SUBMIT = 'submit.' + NAMESPACE, + CLASS_TABLE = 'table.qor-js-table tr', + CLASS_FORM = 'form'; + + function QorSelectCore(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorSelectCore.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorSelectCore.prototype = { + constructor: QorSelectCore, + + init: function() { + this.bind(); + }, + + bind: function() { + this.$element.on(EVENT_CLICK, CLASS_TABLE, this.processingData.bind(this)).on(EVENT_SUBMIT, CLASS_FORM, this.submit.bind(this)); + }, + + unbind: function() { + this.$element.off(EVENT_CLICK, CLASS_TABLE).off(EVENT_SUBMIT, CLASS_FORM); + }, + + processingData: function(e) { + let $this = $(e.target).closest('tr'), + $bottomsheets = $this.closest('.qor-bottomsheets'), + data = {}, + url, + options = this.options, + onSelect = options.onSelect, + loading = options.loading; + + data = $.extend({}, data, $this.data()); + data.$clickElement = $this; + + url = data.mediaLibraryUrl || data.url; + + if (loading && $.isFunction(loading)) { + loading($bottomsheets); + } + + if (url) { + + $.getJSON(url, function(json) { + json.MediaOption && (json.MediaOption = JSON.parse(json.MediaOption)); + data = $.extend({}, json, data); + if (onSelect && $.isFunction(onSelect)) { + onSelect(data, e); + $(document).trigger(EVENT_ONSELECT); + } + }).always(function() { + $bottomsheets.find('.qor-media-loading').remove(); + }); + + } else { + if (onSelect && $.isFunction(onSelect)) { + onSelect(data, e); + $(document).trigger(EVENT_ONSELECT); + } + } + return false; + }, + + submit: function(e) { + let form = e.target, + $form = $(form), + _this = this, + $submit = $form.find(':submit'), + data, + $loading = $(QOR.$formLoading), + onSubmit = this.options.onSubmit; + + $(document).trigger(EVENT_SELECTCORE_BEFORESEND); + + $form.find('.qor-fieldset--new').remove(); + + if (FormData) { + e.preventDefault(); + + $.ajax($form.prop('action'), { + method: $form.prop('method'), + data: new FormData(form), + dataType: 'json', + processData: false, + contentType: false, + beforeSend: function() { + $('.qor-submit-loading').remove(); + $loading.appendTo($submit.prop('disabled', true).closest('.qor-form__actions')).trigger('enable.qor.material'); + }, + success: function(json) { + json.MediaOption && (json.MediaOption = JSON.parse(json.MediaOption)); + data = json; + data.primaryKey = data.ID; + + $('.qor-error').remove(); + + if (onSubmit && $.isFunction(onSubmit)) { + onSubmit(data, e); + $(document).trigger(EVENT_ONSUBMIT); + } else { + _this.refresh(); + } + }, + error: function(err) { + QOR.handleAjaxError(err); + }, + complete: function() { + $submit.prop('disabled', false); + } + }); + } + }, + + refresh: function() { + setTimeout(function() { + window.location.reload(); + }, 350); + }, + + destroy: function() { + this.unbind(); + } + }; + + QorSelectCore.plugin = function(options) { + return this.each(function() { + let $this = $(this), + data = $this.data(NAMESPACE), + fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + $this.data(NAMESPACE, (data = new QorSelectCore(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $.fn.qorSelectCore = QorSelectCore.plugin; + + return QorSelectCore; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-select-many.js b/app/views/qor/assets/javascripts/qor/qor-select-many.js new file mode 100644 index 0000000..0d00252 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-select-many.js @@ -0,0 +1,339 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let $body = $('body'), + $document = $(document), + Mustache = window.Mustache, + NAMESPACE = 'qor.selectone', + PARENT_NAMESPACE = 'qor.bottomsheets', + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_RELOAD = 'reload.' + PARENT_NAMESPACE, + CLASS_CLEAR_SELECT = '.qor-selected-many__remove', + CLASS_UNDO_DELETE = '.qor-selected-many__undo', + CLASS_DELETED_ITEM = 'qor-selected-many__deleted', + CLASS_SELECT_FIELD = '.qor-field__selected-many', + CLASS_SELECT_INPUT = '.qor-field__selectmany-input', + CLASS_SELECT_ICON = '.qor-select__select-icon', + CLASS_SELECT_HINT = '.qor-selectmany__hint', + CLASS_SELECT_ALL = '.qor-selectmany__selectall', + CLASS_PARENT = '.qor-field__selectmany', + CLASS_SELECTED = 'is_selected', + CLASS_MANY = 'qor-bottomsheets__select-many'; + + function QorSelectMany(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorSelectMany.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorSelectMany.prototype = { + constructor: QorSelectMany, + + init: function() { + this.bind(); + }, + + bind: function() { + $document.on(EVENT_RELOAD, `.${CLASS_MANY}`, this.reloadData.bind(this)); + + this.$element + .on(EVENT_CLICK, CLASS_CLEAR_SELECT, this.clearSelect.bind(this)) + .on(EVENT_CLICK, '[data-select-modal="many"]', this.openBottomSheets.bind(this)) + .on(EVENT_CLICK, CLASS_UNDO_DELETE, this.undoDelete.bind(this)); + }, + + unbind: function() { + $document.off(EVENT_CLICK, '[data-select-modal="many"]').off(EVENT_RELOAD, `.${CLASS_MANY}`); + this.$element.off(EVENT_CLICK, CLASS_CLEAR_SELECT).off(EVENT_CLICK, CLASS_UNDO_DELETE); + }, + + clearSelect: function(e) { + var $target = $(e.target), + $selectFeild = $target.closest(CLASS_PARENT); + + $target.closest('[data-primary-key]').addClass(CLASS_DELETED_ITEM); + this.updateSelectInputData($selectFeild); + + return false; + }, + + undoDelete: function(e) { + var $target = $(e.target), + $selectFeild = $target.closest(CLASS_PARENT); + + $target.closest('[data-primary-key]').removeClass(CLASS_DELETED_ITEM); + this.updateSelectInputData($selectFeild); + + return false; + }, + + openBottomSheets: function(e) { + let $this = $(e.target), + data = $this.data(); + + this.BottomSheets = $body.data('qor.bottomsheets'); + this.bottomsheetsData = data; + + this.$selector = data.selectId ? $(data.selectId) : $this.closest(CLASS_PARENT).find('select'); + this.$selectFeild = this.$selector.closest(CLASS_PARENT).find(CLASS_SELECT_FIELD); + + // select many templates + this.SELECT_MANY_SELECTED_ICON = $('[name="select-many-selected-icon"]').html(); + this.SELECT_MANY_UNSELECTED_ICON = $('[name="select-many-unselected-icon"]').html(); + this.SELECT_MANY_HINT = $('[name="select-many-hint"]').html(); + this.SELECT_MANY_TEMPLATE = $('[name="select-many-template"]').html(); + + data.url = data.selectListingUrl; + + if (data.selectDefaultCreating) { + data.url = data.selectCreatingUrl; + } + + this.BottomSheets.open(data, this.handleSelectMany.bind(this)); + }, + + reloadData: function() { + this.initItems(); + }, + + renderSelectMany: function(data) { + return Mustache.render(this.SELECT_MANY_TEMPLATE, data); + }, + + renderHint: function(data) { + return Mustache.render(this.SELECT_MANY_HINT, data); + }, + + initItems: function() { + var $tr = this.$bottomsheets.find('tbody tr'), + selectedIconTmpl = this.SELECT_MANY_SELECTED_ICON, + unSelectedIconTmpl = this.SELECT_MANY_UNSELECTED_ICON, + selectedIDs = [], + primaryKey, + $selectedItems = this.$selectFeild.find('[data-primary-key]').not('.' + CLASS_DELETED_ITEM); + + $selectedItems.each(function() { + selectedIDs.push($(this).data().primaryKey); + }); + + $tr.each(function() { + var $this = $(this), + $td = $this.find('td:first'); + + primaryKey = $this.data().primaryKey; + + if (selectedIDs.indexOf(primaryKey) != '-1') { + $this.addClass(CLASS_SELECTED); + $td.append(selectedIconTmpl); + } else { + $td.append(unSelectedIconTmpl); + } + }); + + this.updateHint(this.getSelectedItemData()); + }, + + getSelectedItemData: function() { + var selecedItems = this.$selectFeild.find('[data-primary-key]').not('.' + CLASS_DELETED_ITEM); + return { + selectedNum: selecedItems.length + }; + }, + + updateHint: function(data) { + var template; + + $.extend(data, this.bottomsheetsData); + template = this.renderHint(data); + + this.$bottomsheets.find(CLASS_SELECT_HINT).remove(); + this.$bottomsheets.find('.qor-page__body').before(template); + }, + + updateSelectInputData: function($selectFeild) { + var $selectList = $selectFeild ? $selectFeild : this.$selectFeild, + $selectedItems = $selectList.find('[data-primary-key]').not('.' + CLASS_DELETED_ITEM), + $selector = $selectFeild ? $selectFeild.find(CLASS_SELECT_INPUT) : this.$selector, + $options = $selector.find('option'), + $option, + data, + primaryKey; + + $options.prop('selected', false); + + $selectedItems.each(function() { + primaryKey = $(this).data().primaryKey; + $option = $options.filter('[value="' + primaryKey + '"]'); + + if (!$option.length) { + data = { + primaryKey: primaryKey, + displayName: '' + }; + $option = $(Mustache.render(QorSelectMany.SELECT_MANY_OPTION_TEMPLATE, data)); + $selector.append($option); + } + + $option.prop('selected', true); + }); + }, + + changeIcon: function($ele, template) { + $ele.find(CLASS_SELECT_ICON).remove(); + $ele.find('td:first').prepend(template); + }, + + removeItem: function(data) { + var primaryKey = data.primaryKey; + + this.$selectFeild + .find('[data-primary-key="' + primaryKey + '"]') + .find(CLASS_CLEAR_SELECT) + .click(); + this.changeIcon(data.$clickElement, this.SELECT_MANY_UNSELECTED_ICON); + }, + + addItem: function(data, isNewData) { + var template = this.renderSelectMany(data), + $option, + $list = this.$selectFeild.find('[data-primary-key="' + data.primaryKey + '"]'); + + if ($list.length) { + if ($list.hasClass(CLASS_DELETED_ITEM)) { + $list.removeClass(CLASS_DELETED_ITEM); + this.updateSelectInputData(); + this.changeIcon(data.$clickElement, this.SELECT_MANY_SELECTED_ICON); + return; + } else { + return; + } + } + + this.$selectFeild.append(template); + + if (isNewData) { + $option = $(Mustache.render(QorSelectMany.SELECT_MANY_OPTION_TEMPLATE, data)); + $option.appendTo(this.$selector); + $option.prop('selected', true); + this.$bottomsheets.remove(); + if (!$('.qor-bottomsheets').is(':visible')) { + $('body').removeClass('qor-bottomsheets-open'); + } + return; + } + + this.changeIcon(data.$clickElement, this.SELECT_MANY_SELECTED_ICON); + }, + + handleSelectMany: function($bottomsheets) { + let options = { + onSelect: this.onSelectResults.bind(this), // render selected item after click item lists + onSubmit: this.onSubmitResults.bind(this) // render new items after new item form submitted + }; + + $bottomsheets.qorSelectCore(options).addClass(CLASS_MANY); + $bottomsheets.on(EVENT_CLICK, CLASS_SELECT_ALL, this.handleSelectAll.bind(this)); + this.$bottomsheets = $bottomsheets; + this.initItems(); + }, + + handleSelectAll: function() { + let $trs = this.$bottomsheets.find('.qor-table tbody tr'), + $trsHasUnselected = $trs.not('.is_selected'); + + if ($trsHasUnselected.length) { + $trsHasUnselected.click(); + } else { + $trs.click(); + } + }, + + onSelectResults: function(data) { + this.handleResults(data); + }, + + onSubmitResults: function(data) { + this.handleResults(data, true); + }, + + handleResults: function(data, isNewData) { + data.displayName = data.Text || data.Name || data.Title || data.Code || data[Object.keys(data)[0]]; + + data.displayName = (data.displayName).escapeSymbol(); + + if (isNewData) { + this.addItem(data, true); + return; + } + + var $element = data.$clickElement, + isSelected; + + $element.toggleClass(CLASS_SELECTED); + isSelected = $element.hasClass(CLASS_SELECTED); + + if (isSelected) { + this.addItem(data); + } else { + this.removeItem(data); + } + + this.updateHint(this.getSelectedItemData()); + this.updateSelectInputData(); + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorSelectMany.SELECT_MANY_OPTION_TEMPLATE = ''; + + QorSelectMany.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorSelectMany(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = '[data-toggle="qor.selectmany"]'; + $(document) + .on(EVENT_DISABLE, function(e) { + QorSelectMany.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorSelectMany.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorSelectMany; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-select-one.js b/app/views/qor/assets/javascripts/qor/qor-select-one.js new file mode 100644 index 0000000..ebfb2fb --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-select-one.js @@ -0,0 +1,214 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + let $body = $('body'), + $document = $(document), + Mustache = window.Mustache, + NAMESPACE = 'qor.selectone', + PARENT_NAMESPACE = 'qor.bottomsheets', + EVENT_CLICK = 'click.' + NAMESPACE, + EVENT_ENABLE = 'enable.' + NAMESPACE, + EVENT_DISABLE = 'disable.' + NAMESPACE, + EVENT_RELOAD = 'reload.' + PARENT_NAMESPACE, + CLASS_CLEAR_SELECT = '.qor-selected__remove', + CLASS_CHANGE_SELECT = '.qor-selected__change', + CLASS_SELECT_FIELD = '.qor-field__selected', + CLASS_SELECT_INPUT = '.qor-field__selectone-input', + CLASS_SELECT_TRIGGER = '.qor-field__selectone-trigger', + CLASS_PARENT = '.qor-field__selectone', + CLASS_SELECTED = 'is_selected', + CLASS_ONE = 'qor-bottomsheets__select-one'; + + function QorSelectOne(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorSelectOne.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorSelectOne.prototype = { + constructor: QorSelectOne, + + init: function() { + this.bind(); + }, + + bind: function() { + $document.on(EVENT_RELOAD, `.${CLASS_ONE}`, this.reloadData.bind(this)); + this.$element + .on(EVENT_CLICK, CLASS_CLEAR_SELECT, this.clearSelect.bind(this)) + .on(EVENT_CLICK, '[data-selectone-url]', this.openBottomSheets.bind(this)) + .on(EVENT_CLICK, CLASS_CHANGE_SELECT, this.changeSelect); + }, + + unbind: function() { + $document.off(EVENT_CLICK, '[data-selectone-url]').off(EVENT_RELOAD, `.${CLASS_ONE}`); + this.$element.off(EVENT_CLICK, CLASS_CLEAR_SELECT).off(EVENT_CLICK, CLASS_CHANGE_SELECT); + }, + + clearSelect: function(e) { + var $target = $(e.target), + $parent = $target.closest(CLASS_PARENT); + + $parent.find(CLASS_SELECT_FIELD).remove(); + $parent.find(CLASS_SELECT_INPUT).html(''); + $parent.find(CLASS_SELECT_INPUT)[0].value = ''; + $parent.find(CLASS_SELECT_TRIGGER).show(); + + $parent.trigger('qor.selectone.unselected'); + return false; + }, + + changeSelect: function() { + var $target = $(this), + $parent = $target.closest(CLASS_PARENT); + + $parent.find(CLASS_SELECT_TRIGGER).trigger('click'); + }, + + openBottomSheets: function(e) { + var $this = $(e.target), + data = $this.data(); + + this.BottomSheets = $body.data('qor.bottomsheets'); + this.$parent = $this.closest(CLASS_PARENT); + + data.url = data.selectoneUrl; + + this.SELECT_ONE_SELECTED_ICON = $('[name="select-one-selected-icon"]').html(); + this.BottomSheets.open(data, this.handleSelectOne.bind(this)); + }, + + initItem: function() { + var $selectFeild = this.$parent.find(CLASS_SELECT_FIELD), + selectedID; + + if (!$selectFeild.length) { + return; + } + + selectedID = $selectFeild.data().primaryKey; + + if (selectedID) { + this.$bottomsheets + .find('tr[data-primary-key="' + selectedID + '"]') + .addClass(CLASS_SELECTED) + .find('td:first') + .append(this.SELECT_ONE_SELECTED_ICON); + } + }, + + reloadData: function() { + this.initItem(); + }, + + renderSelectOne: function(data) { + return Mustache.render($('[name="select-one-selected-template"]').html(), data); + }, + + handleSelectOne: function($bottomsheets) { + var options = { + onSelect: this.onSelectResults.bind(this), //render selected item after click item lists + onSubmit: this.onSubmitResults.bind(this) //render new items after new item form submitted + }; + + $bottomsheets.qorSelectCore(options).addClass(CLASS_ONE); + this.$bottomsheets = $bottomsheets; + this.initItem(); + }, + + onSelectResults: function(data) { + this.handleResults(data); + }, + + onSubmitResults: function(data) { + this.handleResults(data, true); + }, + + handleResults: function(data) { + var template, + $parent = this.$parent, + $select = $parent.find('select'), + $selectFeild = $parent.find(CLASS_SELECT_FIELD); + + data.displayName = data.Text || data.Name || data.Title || data.Code || data[Object.keys(data)[0]]; + data.selectoneValue = data.primaryKey || data.ID; + + data.displayName = (data.displayName).escapeSymbol(); + + if (!$select.length) { + return; + } + + template = this.renderSelectOne(data); + + if ($selectFeild.length) { + $selectFeild.remove(); + } + + $parent.prepend(template); + $parent.find(CLASS_SELECT_TRIGGER).hide(); + + $select.html(Mustache.render(QorSelectOne.SELECT_ONE_OPTION_TEMPLATE, data)); + $select[0].value = data.primaryKey || data.ID; + + $parent.trigger('qor.selectone.selected', [data]); + + this.$bottomsheets.qorSelectCore('destroy').remove(); + if (!$('.qor-bottomsheets').is(':visible')) { + $('body').removeClass('qor-bottomsheets-open'); + } + }, + + destroy: function() { + this.unbind(); + this.$element.removeData(NAMESPACE); + } + }; + + QorSelectOne.SELECT_ONE_OPTION_TEMPLATE = ''; + + QorSelectOne.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorSelectOne(this, options))); + } + + if (typeof options === 'string' && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = '[data-toggle="qor.selectone"]'; + $(document) + .on(EVENT_DISABLE, function(e) { + QorSelectOne.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorSelectOne.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorSelectOne; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-selector.js b/app/views/qor/assets/javascripts/qor/qor-selector.js new file mode 100644 index 0000000..64d67d5 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-selector.js @@ -0,0 +1,274 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + var $document = $(document); + var NAMESPACE = 'qor.selector'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + var EVENT_CLICK = 'click.' + NAMESPACE; + var EVENT_SELECTOR_CHANGE = 'selectorChanged.' + NAMESPACE; + var CLASS_OPEN = 'open'; + var CLASS_ACTIVE = 'active'; + var CLASS_HOVER = 'hover'; + var CLASS_SELECTED = 'selected'; + var CLASS_DISABLED = 'disabled'; + var CLASS_CLEARABLE = 'clearable'; + var SELECTOR_SELECTED = '.' + CLASS_SELECTED; + var SELECTOR_TOGGLE = '.qor-selector-toggle'; + var SELECTOR_LABEL = '.qor-selector-label'; + var SELECTOR_CLEAR = '.qor-selector-clear'; + var SELECTOR_MENU = '.qor-selector-menu'; + var CLASS_BOTTOMSHEETS = '.qor-bottomsheets'; + + function QorSelector(element, options) { + this.options = options; + this.$element = $(element); + this.init(); + } + + QorSelector.prototype = { + constructor: QorSelector, + + init: function() { + var $this = this.$element; + + this.placeholder = $this.attr('placeholder') || $this.attr('name') || 'Select'; + this.build(); + }, + + build: function() { + var $this = this.$element; + var $selector = $(QorSelector.TEMPLATE); + var alignedClass = this.options.aligned + '-aligned'; + var data = {}; + var eleData = $this.data(); + var hover = eleData.hover; + var paramName = $this.attr('name'); + + this.isBottom = eleData.position == 'bottom'; + + hover && $selector.addClass(CLASS_HOVER); + + $selector + .addClass(alignedClass) + .find(SELECTOR_MENU) + .html(function() { + var list = []; + + $this.children().each(function() { + var $this = $(this); + var selected = $this.attr('selected'); + var disabled = $this.attr('disabled'); + var value = $this.attr('value'); + var label = $this.text(); + var classNames = []; + + if (selected) { + classNames.push(CLASS_SELECTED); + data.value = value; + data.label = label; + data.paramName = paramName; + } + + if (disabled) { + classNames.push(CLASS_DISABLED); + } + + list.push( + '' + + label + + '' + ); + }); + + return list.join(''); + }); + + this.$selector = $selector; + $this.hide().after($selector); + $selector.find(SELECTOR_TOGGLE).data('paramName', paramName); + this.pick(data, true); + this.bind(); + }, + + unbuild: function() { + this.unbind(); + this.$selector.remove(); + this.$element.show(); + }, + + bind: function() { + this.$selector.on(EVENT_CLICK, $.proxy(this.click, this)); + $document.on(EVENT_CLICK, $.proxy(this.close, this)); + }, + + unbind: function() { + this.$selector.off(EVENT_CLICK, this.click); + }, + + click: function(e) { + var $target = $(e.target); + + e.stopPropagation(); + + if ($target.is(SELECTOR_CLEAR)) { + this.clear(); + } else if ($target.is('li')) { + if (!$target.hasClass(CLASS_SELECTED) && !$target.hasClass(CLASS_DISABLED)) { + this.pick($target.data()); + } + + this.close(); + } else if ($target.closest(SELECTOR_TOGGLE).length) { + this.open(); + } + }, + + pick: function(data, initialized) { + var $selector = this.$selector; + var selected = !!data.value; + var $element = this.$element; + + $selector + .find(SELECTOR_TOGGLE) + .toggleClass(CLASS_ACTIVE, selected) + .toggleClass(CLASS_CLEARABLE, selected && this.options.clearable) + .find(SELECTOR_LABEL) + .text(data.label || this.placeholder); + + if (!initialized) { + $selector + .find(SELECTOR_MENU) + .children('[data-value="' + data.value + '"]') + .addClass(CLASS_SELECTED) + .siblings(SELECTOR_SELECTED) + .removeClass(CLASS_SELECTED); + + $element.val(data.value); + + if ($element.closest(CLASS_BOTTOMSHEETS).length && !$element.closest('[data-toggle="qor.filter"]').length) { + // If action is in bottom sheet, will trigger filterChanged.qor.selector event, add passed data.value parameter to event. + $(CLASS_BOTTOMSHEETS).trigger(EVENT_SELECTOR_CHANGE, [data.value, data.paramName]); + } else { + $element.trigger('change'); + } + } + }, + + clear: function() { + var $element = this.$element; + + this.$selector + .find(SELECTOR_TOGGLE) + .removeClass(CLASS_ACTIVE) + .removeClass(CLASS_CLEARABLE) + .find(SELECTOR_LABEL) + .text(this.placeholder) + .end() + .end() + .find(SELECTOR_MENU) + .children(SELECTOR_SELECTED) + .removeClass(CLASS_SELECTED); + + $element.val('').trigger('change'); + }, + + open: function() { + // Close other opened dropdowns first + $document.triggerHandler(EVENT_CLICK); + $('.qor-filter__dropdown').hide(); + + // Open the current dropdown + this.$selector.addClass(CLASS_OPEN); + if (this.isBottom) { + this.$selector.addClass('bottom'); + } + }, + + close: function() { + this.$selector.removeClass(CLASS_OPEN); + if (this.isBottom) { + this.$selector.removeClass('bottom'); + } + }, + + destroy: function() { + this.unbuild(); + this.$element.removeData(NAMESPACE); + } + }; + + QorSelector.DEFAULTS = { + aligned: 'left', + clearable: false + }; + + QorSelector.TEMPLATE = + ''; + + QorSelector.plugin = function(option) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var options; + var fn; + + if (!data) { + if (/destroy/.test(option)) { + return; + } + + options = $.extend({}, QorSelector.DEFAULTS, $this.data(), typeof option === 'object' && option); + $this.data(NAMESPACE, (data = new QorSelector(this, options))); + } + + if (typeof option === 'string' && $.isFunction((fn = data[option]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = '[data-toggle="qor.selector"]'; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorSelector.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorSelector.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorSelector; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-slideout.js b/app/views/qor/assets/javascripts/qor/qor-slideout.js new file mode 100644 index 0000000..d6c7a14 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-slideout.js @@ -0,0 +1,689 @@ +(function(factory) { + if (typeof define === "function" && define.amd) { + // AMD. Register as anonymous module. + define(["jquery"], factory); + } else if (typeof exports === "object") { + // Node / CommonJS + factory(require("jquery")); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + "use strict"; + + let $document = $(document), + FormData = window.FormData, + QOR_Translations = window.QOR_Translations, + _ = window._, + QOR = window.QOR, + NAMESPACE = "qor.slideout", + EVENT_KEYUP = "keyup." + NAMESPACE, + EVENT_CLICK = "click." + NAMESPACE, + EVENT_SUBMIT = "submit." + NAMESPACE, + EVENT_SHOW = "show." + NAMESPACE, + EVENT_SLIDEOUT_SUBMIT_COMPLEMENT = "slideoutSubmitComplete." + NAMESPACE, + EVENT_SLIDEOUT_CLOSED = "slideoutClosed." + NAMESPACE, + EVENT_SLIDEOUT_LOADED = "slideoutLoaded." + NAMESPACE, + EVENT_SLIDEOUT_BEFORESEND = "slideoutBeforeSend." + NAMESPACE, + EVENT_SHOWN = "shown." + NAMESPACE, + EVENT_HIDE = "hide." + NAMESPACE, + EVENT_HIDDEN = "hidden." + NAMESPACE, + EVENT_TRANSITIONEND = "transitionend", + CLASS_OPEN = "qor-slideout-open", + CLASS_MINI = "qor-slideout-mini", + CLASS_IS_SHOWN = "is-shown", + CLASS_IS_SLIDED = "is-slided", + CLASS_IS_SELECTED = "is-selected", + CLASS_MAIN_CONTENT = ".mdl-layout__content.qor-page", + CLASS_HEADER_LOCALE = ".qor-actions__locale", + CLASS_BODY_LOADING = ".qor-body__loading"; + + function replaceHtml(el, html) { + let oldEl = typeof el === "string" ? document.getElementById(el) : el, + newEl = oldEl.cloneNode(false); + newEl.innerHTML = html; + oldEl.parentNode.replaceChild(newEl, oldEl); + return newEl; + } + + function pushArrary($ele, isScript) { + let array = [], + prop = "href"; + + isScript && (prop = "src"); + $ele.each(function() { + array.push($(this).attr(prop)); + }); + return _.uniq(array); + } + + function execSlideoutEvents(url, response) { + // exec qorSliderAfterShow after script loaded + var qorSliderAfterShow = $.fn.qorSliderAfterShow; + for (var name in qorSliderAfterShow) { + if ( + qorSliderAfterShow.hasOwnProperty(name) && + !qorSliderAfterShow[name]["isLoaded"] + ) { + qorSliderAfterShow[name]["isLoaded"] = true; + qorSliderAfterShow[name].call(this, url, response); + } + } + } + + function loadScripts(srcs, data, callback) { + let scriptsLoaded = 0; + + for (let i = 0, len = srcs.length; i < len; i++) { + let script = document.createElement("script"); + + script.onload = function() { + scriptsLoaded++; + + if (scriptsLoaded === srcs.length) { + if ($.isFunction(callback)) { + callback(); + } + } + + if (data && data.url && data.response) { + execSlideoutEvents(data.url, data.response); + } + }; + + script.src = srcs[i]; + document.body.appendChild(script); + } + } + + function loadStyles(srcs) { + let ss = document.createElement("link"), + src = srcs.shift(); + + ss.type = "text/css"; + ss.rel = "stylesheet"; + ss.onload = function() { + if (srcs.length) { + loadStyles(srcs); + } + }; + ss.href = src; + document.getElementsByTagName("head")[0].appendChild(ss); + } + + function compareScripts($scripts) { + let $currentPageScripts = $("script"), + slideoutScripts = pushArrary($scripts, true), + currentPageScripts = pushArrary($currentPageScripts, true), + scriptDiff = _.difference(slideoutScripts, currentPageScripts); + return scriptDiff; + } + + function compareLinks($links) { + let $currentStyles = $("link"), + slideoutStyles = pushArrary($links), + currentStyles = pushArrary($currentStyles), + styleDiff = _.difference(slideoutStyles, currentStyles); + + return styleDiff; + } + + function QorSlideout(element, options) { + this.$element = $(element); + this.options = $.extend( + {}, + QorSlideout.DEFAULTS, + $.isPlainObject(options) && options + ); + this.slided = false; + this.disabled = false; + this.slideoutType = false; + this.init(); + } + + QorSlideout.prototype = { + constructor: QorSlideout, + + init: function() { + this.build(); + this.bind(); + }, + + build: function() { + var $slideout; + + this.$slideout = $slideout = $(QorSlideout.TEMPLATE).appendTo("body"); + this.$slideoutTemplate = $slideout.html(); + }, + + unbuild: function() { + this.$slideout.remove(); + }, + + bind: function() { + this.$slideout + .on(EVENT_SUBMIT, "form", this.submit.bind(this)) + .on( + EVENT_CLICK, + ".qor-slideout__fullscreen", + this.toggleSlideoutMode.bind(this) + ) + .on(EVENT_CLICK, '[data-dismiss="slideout"]', this.hide.bind(this)); + + $document.on(EVENT_KEYUP, $.proxy(this.keyup, this)); + }, + + unbind: function() { + this.$slideout.off(EVENT_SUBMIT, this.submit).off(EVENT_CLICK); + + $document.off(EVENT_KEYUP, this.keyup); + }, + + keyup: function(e) { + if (e.which === 27) { + if ( + $(".qor-bottomsheets").is(":visible") || + $(".qor-modal").is(":visible") || + $("#redactor-modal-box").length || + $("#dialog").is(":visible") + ) { + return; + } + + this.hide(); + this.removeSelectedClass(); + } + }, + + loadExtraResource: function(data) { + let styleDiff = compareLinks(data.$links), + scriptDiff = compareScripts(data.$scripts); + + if (styleDiff.length) { + loadStyles(styleDiff); + } + + if (scriptDiff.length) { + loadScripts(scriptDiff, data); + } + }, + + removeSelectedClass: function() { + this.$element.find("[data-url]").removeClass(CLASS_IS_SELECTED); + }, + + addLoading: function() { + $(CLASS_BODY_LOADING).remove(); + var $loading = $(QorSlideout.TEMPLATE_LOADING); + $loading.appendTo($("body")).trigger("enable.qor.material"); + }, + + toggleSlideoutMode: function() { + this.$slideout + .toggleClass("qor-slideout__fullscreen") + .find(".qor-slideout__fullscreen i") + .toggle(); + }, + + checkRichedutorHTMLTags: function(source){ + var DOMHolderArray = new Array(); + var tagsArray = new Array(); + var lines = source.value.split('\n'); + for (var x = 0; x < lines.length; x++) { + tagsArray = lines[x].match(/<(\/{1})?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)>/g); + if (tagsArray) { + for (var i = 0; i < tagsArray.length; i++) { + if (tagsArray[i].indexOf('= 0) { + let elementToPop = tagsArray[i].substr(2, tagsArray[i].length - 3); + elementToPop = elementToPop.replace(/ /g, ''); + for (var j = DOMHolderArray.length - 1; j >= 0; j--) { + if (DOMHolderArray[j].element == elementToPop) { + DOMHolderArray.splice(j, 1); + if (elementToPop != 'html') { + break; + } + } + } + } else { + var tag = new Object(); + tag.full = tagsArray[i]; + tag.line = x + 1; + if (tag.full.indexOf(' ') > 0) { + tag.element = tag.full.substr(1, tag.full.indexOf(' ') - 1); + } else { + tag.element = tag.full.substr(1, tag.full.length - 2); + } + var selfClosingTags = new Array('area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'); + var isSelfClosing = false; + for (var y = 0; y < selfClosingTags.length; y++) { + if (selfClosingTags[y].localeCompare(tag.element) == 0) { + isSelfClosing = true; + } + } + if (isSelfClosing == false) { + DOMHolderArray.push(tag); + } + } + + } + } + } + + return DOMHolderArray.length; + + }, + + submit: function(e) { + let $slideout = this.$slideout, + form = e.target, + $form = $(form), + _this = this, + $loading = $(QOR.$formLoading), + $submit = $form.find(":submit"), + hasNotClosedTags = false; + + if ($form.data("normal-submit")) { + return; + } + + $slideout.trigger(EVENT_SLIDEOUT_BEFORESEND); + + if (!FormData) { + return; + } + e.preventDefault(); + + document.querySelectorAll('.qor-redactor-box .redactor-source').forEach(function(item) { + if(_this.checkRichedutorHTMLTags(item)){ + hasNotClosedTags=true; + } + }); + + if(hasNotClosedTags){ + QOR.qorConfirm(QOR_Translations.slideoutCheckHTMLTagsError); + return false; + } + + this.submitXHR = $.ajax($form.prop("action"), { + method: $form.prop("method"), + data: new FormData(form), + dataType: "html", + processData: false, + contentType: false, + beforeSend: function() { + $(".qor-submit-loading").remove(); + $loading + .appendTo( + $submit.prop("disabled", true).closest(".qor-form__actions") + ) + .trigger("enable.qor.material"); + $.fn.qorSlideoutBeforeHide = null; + }, + success: function() { + let returnUrl = $form.data("returnUrl"), + refreshUrl = $form.data("refreshUrl"); + + $slideout.trigger(EVENT_SLIDEOUT_SUBMIT_COMPLEMENT); + + if (refreshUrl) { + window.location.href = refreshUrl; + return; + } + + if (returnUrl == "refresh") { + _this.refresh(); + return; + } + + if (returnUrl && returnUrl != "refresh") { + _this.load(returnUrl); + } else { + _this.refresh(); + } + }, + error: function(err) { + QOR.handleAjaxError(err); + }, + complete: function() { + $submit.prop("disabled", false); + } + }); + }, + + load: function(url, data) { + var options = this.options; + var method; + var dataType; + var load; + var $slideout = this.$slideout; + var $title; + + if (!url) { + return; + } + + data = $.isPlainObject(data) ? data : {}; + + method = data.method ? data.method : "GET"; + dataType = data.datatype ? data.datatype : "html"; + + load = $.proxy(function() { + $.ajax(url, { + method: method, + dataType: dataType, + cache: true, + ifModified: true, + success: $.proxy(function(response) { + let $response, + $content, + $qorFormContainer, + $scripts, + $links, + bodyClass; + + $(CLASS_BODY_LOADING).remove(); + + if (method === "GET") { + $response = $(response); + $content = $response.find(CLASS_MAIN_CONTENT); + $qorFormContainer = $content.find(".qor-form-container"); + this.slideoutType = + $qorFormContainer.length && + $qorFormContainer.data().slideoutType; + + if (!$content.length) { + return; + } + + let bodyHtml = response.match( + /<\s*body.*>[\s\S]*<\s*\/body\s*>/gi + ); + if (bodyHtml) { + bodyHtml = bodyHtml + .join("") + .replace(/<\s*body/gi, " 0) { + errors = $(".qor-error span") + .map(function() { + return $(this).text(); + }) + .get() + .join(", "); + } else { + errors = QOR_Translations.serverError; + } + window.alert(errors); + }, this) + }); + }, this); + + if (this.slided) { + this.hide(true); + this.$slideout.one(EVENT_HIDDEN, load); + } else { + load(); + } + }, + + open: function(options) { + this.addLoading(); + this.load(options.url, options.data); + }, + + reload: function(url) { + this.hide(); + this.load(url); + }, + + show: function() { + var $slideout = this.$slideout; + var showEvent; + + if (this.slided) { + return; + } + + showEvent = $.Event(EVENT_SHOW); + $slideout.trigger(showEvent); + + if (showEvent.isDefaultPrevented()) { + return; + } + + $slideout.removeClass(CLASS_MINI); + this.slideoutType == "mini" && $slideout.addClass(CLASS_MINI); + + $slideout.addClass(CLASS_IS_SHOWN).get(0).offsetWidth; + $slideout + .one(EVENT_TRANSITIONEND, $.proxy(this.shown, this)) + .addClass(CLASS_IS_SLIDED) + .scrollTop(0); + }, + + shown: function() { + this.slided = true; + // Disable to scroll body element + $("body").addClass(CLASS_OPEN); + this.$slideout + .trigger("beforeEnable.qor.slideout") + .trigger(EVENT_SHOWN) + .trigger("afterEnable.qor.slideout"); + }, + + hide: function() { + let message = { + confirm: QOR_Translations.slideoutCloseWarning + }; + + if ($.fn.qorSlideoutBeforeHide) { + QOR.qorConfirm( + message, + function(confirm) { + if (confirm) { + this.hideSlideout(); + } + }.bind(this) + ); + } else { + this.hideSlideout(); + } + + this.removeSelectedClass(); + }, + + hideSlideout: function() { + var $slideout = this.$slideout; + var hideEvent; + var $datePicker = $(".qor-datepicker").not(".hidden"); + + // remove onbeforeunload event + window.onbeforeunload = null; + $.fn.qorSlideoutBeforeHide = null; + + this.submitXHR && this.submitXHR.abort(); + + if ($datePicker.length) { + $datePicker.addClass("hidden"); + } + + if (!this.slided) { + return; + } + + hideEvent = $.Event(EVENT_HIDE); + $slideout.trigger(hideEvent); + + if (hideEvent.isDefaultPrevented()) { + return; + } + + $slideout + .one(EVENT_TRANSITIONEND, $.proxy(this.hidden, this)) + .removeClass(`${CLASS_IS_SLIDED} qor-slideout__fullscreen`); + $slideout.trigger(EVENT_SLIDEOUT_CLOSED); + }, + + hidden: function() { + this.slided = false; + + // Enable to scroll body element + $("body").removeClass(CLASS_OPEN); + + this.$slideout.removeClass(CLASS_IS_SHOWN).trigger(EVENT_HIDDEN); + }, + + refresh: function() { + this.hide(); + + setTimeout(function() { + window.location.reload(); + }, 350); + }, + + destroy: function() { + this.unbind(); + this.unbuild(); + this.$element.removeData(NAMESPACE); + } + }; + + QorSlideout.DEFAULTS = { + title: ".qor-form-title, .mdl-layout-title", + content: false + }; + + QorSlideout.TEMPLATE = `
          + +
          +
          `; + + QorSlideout.TEMPLATE_LOADING = `
          +
          +
          `; + + QorSlideout.plugin = function(options) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorSlideout(this, options))); + } + + if (typeof options === "string" && $.isFunction((fn = data[options]))) { + fn.apply(data); + } + }); + }; + + $.fn.qorSlideout = QorSlideout.plugin; + + return QorSlideout; +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-sorter.js b/app/views/qor/assets/javascripts/qor/qor-sorter.js new file mode 100644 index 0000000..1256b7e --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-sorter.js @@ -0,0 +1,110 @@ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function ($) { + + 'use strict'; + + var location = window.location; + var NAMESPACE = 'qor.sorter'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + var EVENT_CLICK = 'click.' + NAMESPACE; + var CLASS_IS_SORTABLE = 'is-sortable'; + + function QorSorter(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorSorter.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorSorter.prototype = { + constructor: QorSorter, + + init: function () { + this.$element.addClass(CLASS_IS_SORTABLE); + this.bind(); + }, + + bind: function () { + this.$element.on(EVENT_CLICK, '> thead > tr > th', $.proxy(this.sort, this)); + }, + + unbind: function () { + this.$element.off(EVENT_CLICK, this.sort); + }, + + sort: function (e) { + var $target = $(e.currentTarget); + var orderBy = $target.data('orderBy'); + var search = location.search; + var param = 'order_by=' + orderBy; + + // Stop when it is not sortable + if (!orderBy) { + return; + } + + if (/order_by/.test(search)) { + search = search.replace(/order_by(=\w+)?/, function () { + return param; + }); + } else { + search += search.indexOf('?') > -1 ? ('&' + param) : param; + } + + location.search = search; + }, + + destroy: function () { + this.unbind(); + this.$element.removeClass(CLASS_IS_SORTABLE).removeData(NAMESPACE); + } + }; + + QorSorter.DEFAULTS = {}; + + QorSorter.plugin = function (options) { + return this.each(function () { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorSorter(this, options))); + } + + if (typeof options === 'string' && $.isFunction(fn = data[options])) { + fn.apply(data); + } + }); + }; + + $(function () { + var selector = '.qor-js-table'; + + $(document) + .on(EVENT_DISABLE, function (e) { + QorSorter.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function (e) { + QorSorter.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorSorter; + +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-tabs.js b/app/views/qor/assets/javascripts/qor/qor-tabs.js new file mode 100644 index 0000000..d074652 --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-tabs.js @@ -0,0 +1,210 @@ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function ($) { + + 'use strict'; + + var _ = window._; + var $body = $('body'); + var NAMESPACE = 'qor.tabbar'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + var EVENT_CLICK = 'click.' + NAMESPACE; + var CLASS_TAB = '.qor-layout__tab-button'; + var CLASS_TAB_CONTENT = '.qor-layout__tab-content'; + var CLASS_TAB_BAR = '.mdl-layout__tab-bar-container'; + var CLASS_TAB_BAR_RIGHT = '.qor-layout__tab-right'; + var CLASS_TAB_BAR_LEFT = '.qor-layout__tab-left'; + var CLASS_ACTIVE = 'is-active'; + + function QorTab(element, options) { + this.$element = $(element); + this.options = $.extend({}, QorTab.DEFAULTS, $.isPlainObject(options) && options); + this.init(); + } + + QorTab.prototype = { + constructor: QorTab, + + init: function () { + this.initTab(); + this.bind(); + }, + + bind: function () { + this.$element.on(EVENT_CLICK, CLASS_TAB, this.switchTab.bind(this)); + this.$element.on(EVENT_CLICK, CLASS_TAB_BAR_RIGHT, this.scrollTabRight.bind(this)); + this.$element.on(EVENT_CLICK, CLASS_TAB_BAR_LEFT, this.scrollTabLeft.bind(this)); + }, + + unbind: function () { + this.$element.off(EVENT_CLICK, CLASS_TAB, this.switchTab); + this.$element.off(EVENT_CLICK, CLASS_TAB_BAR_RIGHT, this.scrollTabRight); + this.$element.off(EVENT_CLICK, CLASS_TAB_BAR_LEFT, this.scrollTabLeft); + }, + + initTab: function () { + var data = this.$element.data(); + + if (!data.scopeActive) { + $(CLASS_TAB).first().addClass(CLASS_ACTIVE); + $body.data('tabScopeActive',$(CLASS_TAB).first().data('name')); + } else { + $body.data('tabScopeActive',data.scopeActive); + } + + this.tabWidth = 0; + this.slideoutWidth = $(CLASS_TAB_CONTENT).outerWidth(); + + _.each($(CLASS_TAB), function(ele) { + this.tabWidth = this.tabWidth + $(ele).outerWidth(); + }.bind(this)); + + if (this.tabWidth > this.slideoutWidth) { + this.$element.find(CLASS_TAB_BAR).append(QorTab.ARROW_RIGHT); + } + + }, + + scrollTabLeft: function (e) { + e.stopPropagation(); + + var $scrollBar = $(CLASS_TAB_BAR), + scrollLeft = $scrollBar.scrollLeft(), + jumpDistance = scrollLeft - this.slideoutWidth; + + if (scrollLeft > 0){ + $scrollBar.animate({scrollLeft:jumpDistance}, 400, function () { + + $(CLASS_TAB_BAR_RIGHT).show(); + if ($scrollBar.scrollLeft() == 0) { + $(CLASS_TAB_BAR_LEFT).hide(); + } + + }); + } + }, + + scrollTabRight: function (e) { + e.stopPropagation(); + + var $scrollBar = $(CLASS_TAB_BAR), + scrollLeft = $scrollBar.scrollLeft(), + tabWidth = this.tabWidth, + slideoutWidth = this.slideoutWidth, + jumpDistance = scrollLeft + slideoutWidth; + + if (jumpDistance < tabWidth){ + $scrollBar.animate({scrollLeft:jumpDistance}, 400, function () { + + $(CLASS_TAB_BAR_LEFT).show(); + if ($scrollBar.scrollLeft() + slideoutWidth >= tabWidth) { + $(CLASS_TAB_BAR_RIGHT).hide(); + } + + }); + + !$(CLASS_TAB_BAR_LEFT).length && this.$element.find(CLASS_TAB_BAR).prepend(QorTab.ARROW_LEFT); + } + }, + + switchTab: function (e) { + var $target = $(e.target), + $element = this.$element, + data = $target.data(), + tabScopeActive = $body.data().tabScopeActive, + isInSlideout = $('.qor-slideout').is(':visible'); + + if (!isInSlideout) { + return; + } + + if ($target.hasClass(CLASS_ACTIVE)){ + return false; + } + + $element.find(CLASS_TAB).removeClass(CLASS_ACTIVE); + $target.addClass(CLASS_ACTIVE); + + $.ajax(data.tabUrl, { + method: 'GET', + dataType: 'html', + processData: false, + contentType: false, + beforeSend: function () { + $('.qor-layout__tab-spinner').remove(); + var $spinner = '
          '; + $(CLASS_TAB_CONTENT).hide().before($spinner); + window.componentHandler.upgradeElement($('.qor-layout__tab-spinner')[0]); + }, + success: function (html) { + $('.qor-layout__tab-spinner').remove(); + $body.data('tabScopeActive',$target.data('name')); + var $content = $(html).find(CLASS_TAB_CONTENT).html(); + $(CLASS_TAB_CONTENT).show().html($content).trigger('enable'); + + }, + error: function () { + $('.qor-layout__tab-spinner').remove(); + $body.data('tabScopeActive',tabScopeActive); + } + }); + return false; + }, + + destroy: function () { + this.unbind(); + $body.removeData('tabScopeActive'); + } + }; + + QorTab.ARROW_RIGHT = ''; + QorTab.ARROW_LEFT = ''; + + QorTab.DEFAULTS = {}; + + QorTab.plugin = function (options) { + return this.each(function () { + var $this = $(this); + var data = $this.data(NAMESPACE); + var fn; + + if (!data) { + if (/destroy/.test(options)) { + return; + } + + $this.data(NAMESPACE, (data = new QorTab(this, options))); + } + + if (typeof options === 'string' && $.isFunction(fn = data[options])) { + fn.apply(data); + } + }); + }; + + $(function () { + var selector = '[data-toggle="qor.tab"]'; + + $(document) + .on(EVENT_DISABLE, function (e) { + QorTab.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function (e) { + QorTab.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorTab; + +}); diff --git a/app/views/qor/assets/javascripts/qor/qor-timepicker.js b/app/views/qor/assets/javascripts/qor/qor-timepicker.js new file mode 100644 index 0000000..c8b7f2f --- /dev/null +++ b/app/views/qor/assets/javascripts/qor/qor-timepicker.js @@ -0,0 +1,262 @@ +(function(factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node / CommonJS + factory(require('jquery')); + } else { + // Browser globals. + factory(jQuery); + } +})(function($) { + 'use strict'; + + var NAMESPACE = 'qor.timepicker'; + var EVENT_ENABLE = 'enable.' + NAMESPACE; + var EVENT_DISABLE = 'disable.' + NAMESPACE; + var EVENT_CLICK = 'click.' + NAMESPACE; + var EVENT_FOCUS = 'focus.' + NAMESPACE; + var EVENT_KEYDOWN = 'keydown.' + NAMESPACE; + var EVENT_BLUR = 'blur.' + NAMESPACE; + var EVENT_CHANGE_TIME = 'selectTime.' + NAMESPACE; + + var CLASS_PARENT = '[data-picker-type]'; + var CLASS_TIME_SELECTED = '.ui-timepicker-selected'; + + function QorTimepicker(element, options) { + this.$element = $(element); + this.options = $.extend(true, {}, QorTimepicker.DEFAULTS, $.isPlainObject(options) && options); + this.formatDate = null; + this.pickerData = this.$element.data(); + this.parent = this.$element.closest(CLASS_PARENT); + this.isDateTimePicker = this.parent.data('picker-type') == 'datetime'; + this.$targetInput = this.parent.find(this.pickerData.targetInput || (this.isDateTimePicker ? '.qor-datetimepicker__input' : '.qor-datepicker__input')); + this.init(); + } + + QorTimepicker.prototype = { + init: function() { + if (this.$targetInput.is(':disabled')) { + this.$element.remove(); + return; + } + this.bind(); + this.oldValue = this.$targetInput.val(); + + var dateNow = new Date(); + var month = dateNow.getMonth() + 1; + var date = dateNow.getDate(); + + month = month < 8 ? '0' + month : month; + date = date < 10 ? '0' + date : date; + + this.dateValueNow = dateNow.getFullYear() + '-' + month + '-' + date; + }, + + bind: function() { + var pickerOptions = { + timeFormat: 'H:i', + showOn: null, + wrapHours: false, + scrollDefault: 'now' + }; + + if (this.isDateTimePicker) { + this.$targetInput + .qorTimepicker(pickerOptions) + .on(EVENT_CHANGE_TIME, $.proxy(this.changeTime, this)) + .on(EVENT_BLUR, $.proxy(this.blur, this)) + .on(EVENT_FOCUS, $.proxy(this.focus, this)) + .on(EVENT_KEYDOWN, $.proxy(this.keydown, this)); + } + + this.$element.on(EVENT_CLICK, $.proxy(this.show, this)); + }, + + unbind: function() { + this.$element.off(EVENT_CLICK, this.show); + + if (this.isDateTimePicker) { + this.$targetInput + .off(EVENT_CHANGE_TIME, this.changeTime) + .off(EVENT_BLUR, this.blur) + .off(EVENT_FOCUS, this.focus) + .off(EVENT_KEYDOWN, this.keydown); + } + }, + + focus: function() {}, + + blur: function() { + var inputValue = this.$targetInput.val(); + var inputArr = inputValue.split(' '); + var inputArrLen = inputArr.length; + + var tempValue; + var newDateValue; + var newTimeValue; + var isDate; + var isTime; + var splitSym; + + var timeReg = /\d{1,2}:\d{1,2}/; + var dateReg = /^\d{4}-\d{1,2}-\d{1,2}/; + + if (!inputValue) { + return; + } + + if (inputArrLen == 1) { + if (dateReg.test(inputArr[0])) { + newDateValue = inputArr[0]; + newTimeValue = '00:00'; + } + + if (timeReg.test(inputArr[0])) { + newDateValue = this.dateValueNow; + newTimeValue = inputArr[0]; + } + } else { + for (var i = 0; i < inputArrLen; i++) { + // check for date && time + isDate = dateReg.test(inputArr[i]); + isTime = timeReg.test(inputArr[i]); + + if (isDate) { + newDateValue = inputArr[i]; + splitSym = '-'; + } + + if (isTime) { + newTimeValue = inputArr[i]; + splitSym = ':'; + } + + tempValue = inputArr[i].split(splitSym); + + for (var j = 0; j < tempValue.length; j++) { + if (tempValue[j].length < 2) { + tempValue[j] = '0' + tempValue[j]; + } + } + + if (isDate) { + newDateValue = tempValue.join(splitSym); + } + + if (isTime) { + newTimeValue = tempValue.join(splitSym); + } + } + } + + if (this.checkDate(newDateValue) && this.checkTime(newTimeValue)) { + this.$targetInput.val(newDateValue + ' ' + newTimeValue); + this.oldValue = this.$targetInput.val(); + } else { + this.$targetInput.val(this.oldValue); + } + }, + + keydown: function(e) { + var keycode = e.keyCode; + var keys = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 8, 37, 38, 39, 40, 27, 32, 20, 189, 16, 186, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105]; + if (keys.indexOf(keycode) == -1) { + e.preventDefault(); + } + }, + + checkDate: function(value) { + var regCheckDate = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{1,2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/; + return regCheckDate.test(value); + }, + + checkTime: function(value) { + var regCheckTime = /^([01]\d|2[0-3]):?([0-5]\d)$/; + return regCheckTime.test(value); + }, + + changeTime: function() { + var $targetInput = this.$targetInput; + + var oldValue = this.oldValue; + var timeReg = /\d{1,2}:\d{1,2}/; + var hasTime = timeReg.test(oldValue); + var selectedTime = $targetInput + .data() + .timepickerObj.list.find(CLASS_TIME_SELECTED) + .html(); + var newValue; + + if (!oldValue) { + newValue = this.dateValueNow + ' ' + selectedTime; + } else if (hasTime) { + newValue = oldValue.replace(timeReg, selectedTime); + } else { + newValue = oldValue + ' ' + selectedTime; + } + + $targetInput.val(newValue); + $targetInput.trigger('change'); + }, + + show: function() { + if (!this.isDateTimePicker) { + return; + } + + this.$targetInput.qorTimepicker('show'); + this.oldValue = this.$targetInput.val(); + }, + + destroy: function() { + this.unbind(); + this.$targetInput.qorTimepicker('remove'); + this.$element.removeData(NAMESPACE); + } + }; + + QorTimepicker.DEFAULTS = {}; + + QorTimepicker.plugin = function(option) { + return this.each(function() { + var $this = $(this); + var data = $this.data(NAMESPACE); + var options; + var fn; + + if (!data) { + if (!$.fn.qorDatepicker) { + return; + } + + if (/destroy/.test(option)) { + return; + } + + options = $.extend(true, {}, $this.data(), typeof option === 'object' && option); + $this.data(NAMESPACE, (data = new QorTimepicker(this, options))); + } + + if (typeof option === 'string' && $.isFunction((fn = data[option]))) { + fn.apply(data); + } + }); + }; + + $(function() { + var selector = '[data-toggle="qor.timepicker"]'; + + $(document) + .on(EVENT_DISABLE, function(e) { + QorTimepicker.plugin.call($(selector, e.target), 'destroy'); + }) + .on(EVENT_ENABLE, function(e) { + QorTimepicker.plugin.call($(selector, e.target)); + }) + .triggerHandler(EVENT_ENABLE); + }); + + return QorTimepicker; +}); diff --git a/app/views/qor/assets/javascripts/qor_admin_default.js b/app/views/qor/assets/javascripts/qor_admin_default.js new file mode 100644 index 0000000..c74d4cf --- /dev/null +++ b/app/views/qor/assets/javascripts/qor_admin_default.js @@ -0,0 +1,2 @@ +"use strict";function getSelect2Header(){var t=$("body").data().selectAjaxHeader,e=window.getSelect2HeaderFunction,i={};return t&&e&&$.isFunction(e)?(i[t]=e(),i):{}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}$.fn.qorSliderAfterShow=$.fn.qorSliderAfterShow||{},window.QOR={$formLoading:'
          '},String.prototype.escapeSymbol=function(){var e={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return this.replace(/[&<>"']/g,function(t){return e[t]||t})},window.Mustache&&(window.Mustache.tags=["[[","]]"]),$(document).ajaxComplete(function(t,e,i){"POST"!=i.type&&"PUT"!=i.type||$.fn.qorSlideoutBeforeHide&&($.fn.qorSlideoutBeforeHide=null,window.onbeforeunload=null)}),$.fn.select2.ajaxCommonOptions=function(t){var i=t.remoteDataPrimaryKey;return{dataType:"json",headers:getSelect2Header(t),cache:!0,delay:250,data:function(t){return{keyword:t.term,page:t.page,per_page:20}},processResults:function(t,e){e.page=e.page||1;t=$.map(t,function(t){return t.id=t[i]||t.primaryKey||t.Id||t.ID,t});return{results:t,pagination:{more:20<=t.length}}}}},$.fn.select2.ajaxFormatResult=function(t,e,i){var n="";if(t.loading)return t.text;if(console.log("select2.ajaxFormatResult: Data"),console.log(t),console.log("select2.ajaxFormatResult: has remote image"),console.log(i),i){var o=t.text||t.Name||t.Title||t.Code||t[Object.keys(t)[0]],i=t.Image,n=i?'
          '+o+"
          ":'
          '+o+"
          ";return $(n)}return n=0|<\/.+>)/.test(n)?$(n):n},$(function(){var r=window._,o=window.QOR,s=window.QOR_Translations,t='"),a=$(t).appendTo("body");$(document).on("keyup.qor.confirm",function(t){a.is(":visible")&&(27===t.which&&setTimeout(function(){a.hide(),o.qorConfirmCallback=void 0},100),13===t.which&&setTimeout(function(){$('.dialog-button[data-type="confirm"]').click()},100))}).on("click.qor.confirm",".dialog-button",function(){var t=$(this).data("type"),e=o.qorConfirmCallback;return $.isFunction(e)&&e(t),a.hide(),o.qorConfirmCallback=void 0,!1}),o.qorConfirm=function(t,e){var i=a.find(".dialog-ok"),n=a.find(".dialog-cancel");return r.isString(t)?(a.find(".dialog-message").text(t),i.text(s.okButton),n.text(s.cancelButton)):r.isObject(t)&&(t.confirmOk&&t.confirmCancel?(i.text(t.confirmOk),n.text(t.confirmCancel)):(i.text(s.okButton),n.text(s.cancelButton)),t.icon&&a.find("i.material-icons").addClass(t.icon).html(t.icon),a.find(".dialog-message").text(t.confirm)),a.show(),o.qorConfirmCallback=e,!1};function l(t,e){var i,n,o=e||new FormData;for(n in t)t.hasOwnProperty(n)&&t[n]&&(i=n),t[n]instanceof Date?o.append(i,t[n].toISOString()):"object"!==_typeof(t[n])||t[n]instanceof File?o.append(i,t[n]):l(t[n],o);return o}o.qorAjaxHandleFile=function(t,i,n,e){var o=new XMLHttpRequest;o.responseType="arraybuffer",o.open("POST",t,!0),o.onload=function(){var t,e;200===this.status?(e=new Blob([this.response],{type:i}),t=window.URL.createObjectURL(e),e=document.createElement("a"),document.body.appendChild(e),e.href=t,e.download=n||"download-"+$.now(),e.click()):window.alert(s.serverError)},r.isObject(e)&&("[object FormData]"!=Object.prototype.toString.call(e)&&(e=l(e)),o.send(e))};t=function(){var t=$(".qor-linkify-object"),e=/https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.\-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/gi;t.length&&t.each(function(){var t=$(this).data("video-link");t.match(e)&&$(this).html(''))})};($.fn.qorSliderAfterShow.converVideoLinks=t)(),o.handleAjaxError=function(t){var e=$("body"),i=t.responseJSON,n=t.responseText,o=$('
          ');if(e.find(".qor-alert").remove(),422===t.status)if(i){var r=i.errors,s="";if($.isArray(r))for(var a=0;a\n error\n '.concat(r[a],"\n ");else s='
        • \n error\n '.concat(r,"\n
        • ");o.append(s)}else o=$(n).find(".qor-error");else o.append('
        • \n error\n '.concat(t.statusText,"\n
        • "));o.prependTo(e),setTimeout(function(){o.addClass("qor-alert__active")},50),setTimeout(function(){$('.qor-alert[data-dismissible="true"]').removeClass("qor-alert__active"),$("#qor-submit-loading").remove()},6e3)}}),function(t){"function"==typeof define&&define.amd?define("datepicker",["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(C){var t=C(window),o=window.document,h=C(o),r=window.Number,a="datepicker",i="click."+a,n="keyup."+a,s="focus."+a,e="resize."+a,l="show."+a,d="hide."+a,c="pick."+a,u=/(y|m|d)+/g,f=/\d+/g,p=/^\d{2,4}$/,m=a+"-top-left",y=a+"-bottom-left",g=[m,a+"-top-right",y,a+"-bottom-right"].join(" "),b=a+"-hide",v=Math.min,_=Object.prototype.toString;function q(t){return"string"==typeof t}function w(t){return"number"==typeof t&&!isNaN(t)}function S(t){return void 0===t}function $(t){return"date"===(t=t,_.call(t).slice(8,-1).toLowerCase())}function k(t,e){var i=[];return Array.from?Array.from(t).slice(e||0):(w(e)&&i.push(e),i.slice.apply(t,i))}function x(t,e){var i=k(arguments,2);return function(){return t.apply(e,i.concat(k(arguments)))}}function T(t,e){return[31,(t=t)%4==0&&t%100!=0||t%400==0?29:28,31,30,31,30,31,31,30,31,30,31][e]}function D(t,e){(e=C.isPlainObject(e)?e:{}).language&&(e=C.extend({},D.LANGUAGES[e.language],e)),this.$element=C(t),this.options=C.extend({},D.DEFAULTS,e),this.isBuilt=!1,this.isShown=!1,this.isInput=!1,this.isInline=!1,this.initialValue="",this.initialDate=null,this.startDate=null,this.endDate=null,this.init()}D.prototype={constructor:D,init:function(){var t=this.options,e=this.$element,i=t.startDate,n=t.endDate,o=t.date;this.$trigger=C(t.trigger||e),this.isInput=e.is("input")||e.is("textarea"),this.isInline=t.inline&&(t.container||!this.isInput),this.format=function(t){var e,i,n=String(t).toLowerCase(),o=n.match(u);if(!o||0===o.length)throw new Error("Invalid date format.");for(t={source:n,parts:o},e=o.length,i=0;in.getTime()&&(o=new Date(n)),this.endDate=n),this.date=o,this.viewDate=new Date(o),this.initialDate=new Date(this.date),this.bind(),(t.autoshow||this.isInline)&&this.show(),t.autopick&&this.pick()},build:function(){var t,e=this.options,i=this.$element;this.isBuilt||(this.isBuilt=!0,this.$picker=t=C(e.template),this.$week=t.find('[data-view="week"]'),this.$yearsPicker=t.find('[data-view="years picker"]'),this.$yearsPrev=t.find('[data-view="years prev"]'),this.$yearsNext=t.find('[data-view="years next"]'),this.$yearsCurrent=t.find('[data-view="years current"]'),this.$years=t.find('[data-view="years"]'),this.$monthsPicker=t.find('[data-view="months picker"]'),this.$yearPrev=t.find('[data-view="year prev"]'),this.$yearNext=t.find('[data-view="year next"]'),this.$yearCurrent=t.find('[data-view="year current"]'),this.$months=t.find('[data-view="months"]'),this.$daysPicker=t.find('[data-view="days picker"]'),this.$monthPrev=t.find('[data-view="month prev"]'),this.$monthNext=t.find('[data-view="month next"]'),this.$monthCurrent=t.find('[data-view="month current"]'),this.$days=t.find('[data-view="days"]'),this.isInline?C(e.container||i).append(t.addClass("datepicker-inline")):(C(o.body).append(t.addClass("datepicker-dropdown")),t.addClass(b)),this.fillWeek())},unbuild:function(){this.isBuilt&&(this.isBuilt=!1,this.$picker.remove())},bind:function(){var t=this.options,e=this.$element;C.isFunction(t.show)&&e.on(l,t.show),C.isFunction(t.hide)&&e.on(d,t.hide),C.isFunction(t.pick)&&e.on(c,t.pick),this.isInput&&(e.on(n,C.proxy(this.keyup,this)),t.trigger||e.on(s,C.proxy(this.show,this))),this.$trigger.on(i,C.proxy(this.show,this))},unbind:function(){var t=this.options,e=this.$element;C.isFunction(t.show)&&e.off(l,t.show),C.isFunction(t.hide)&&e.off(d,t.hide),C.isFunction(t.pick)&&e.off(c,t.pick),this.isInput&&(e.off(n,this.keyup),t.trigger||e.off(s,this.show)),this.$trigger.off(i,this.show)},showView:function(t){var e=this.$yearsPicker,i=this.$monthsPicker,n=this.$daysPicker,o=this.format;if(o.hasYear||o.hasMonth||o.hasDay)switch(r(t)){case 2:case"years":i.addClass(b),n.addClass(b),o.hasYear?(this.fillYears(),e.removeClass(b)):this.showView(0);break;case 1:case"months":e.addClass(b),n.addClass(b),o.hasMonth?(this.fillMonths(),i.removeClass(b)):this.showView(2);break;default:e.addClass(b),i.addClass(b),o.hasDay?(this.fillDays(),n.removeClass(b)):this.showView(1)}},hideView:function(){this.options.autohide&&this.hide()},place:function(){var t=this.options,e=this.$element,i=this.$picker,n=h.outerWidth(),o=h.outerHeight(),r=e.outerWidth(),s=e.outerHeight(),a=i.width(),l=i.height(),d=e.offset(),c=d.left,u=d.top,e=parseFloat(t.offset)||10,d=m;l"+n.text+""},fillAll:function(){this.fillYears(),this.fillMonths(),this.fillDays()},fillWeek:function(){for(var t=this.options,e=parseInt(t.weekStart,10)%7,i=t.daysMin,n="",i=C.merge(i.slice(e),i.slice(0,e)),o=0;o<=6;o++)n+=this.createItem({text:i[o]});this.$week.html(n)},fillYears:function(){for(var t,e,i=this.options,n=i.disabledClass||"",o=i.yearSuffix||"",r=C.isFunction(i.filter)&&i.filter,s=this.startDate,a=this.endDate,i=this.viewDate,l=i.getFullYear(),d=i.getMonth(),c=i.getDate(),u=this.date,h=u.getFullYear(),f=!1,p=!1,m=!1,y="",g=-5;g<=6;g++)u=new Date(l+g,d,c),e=-5===g||6===g,t=l+g===h,m=!1,s&&(m=u.getFullYear()a.getFullYear(),6===g&&(p=m)),!m&&r&&(m=!1===r.call(this.$element,u)),y+=this.createItem({text:l+g,view:m?"year disabled":t?"year picked":"year",muted:e,picked:t,disabled:m});this.$yearsPrev.toggleClass(n,f),this.$yearsNext.toggleClass(n,p),this.$yearsCurrent.toggleClass(n,!0).html(l+-5+o+" - "+(l+6)+o),this.$years.html(y)},fillMonths:function(){for(var t,e=this.options,i=e.disabledClass||"",n=e.monthsShort,o=C.isFunction(e.filter)&&e.filter,r=this.startDate,s=this.endDate,a=this.viewDate,l=a.getFullYear(),d=a.getDate(),c=this.date,u=c.getFullYear(),h=c.getMonth(),f=!1,p=!1,m=!1,y="",g=0;g<=11;g++)c=new Date(l,g,d),t=l===u&&g===h,m=!1,r&&(m=(f=c.getFullYear()===r.getFullYear())&&c.getMonth()s.getMonth()),!m&&o&&(m=!1===o.call(this.$element,c)),y+=this.createItem({index:g,text:n[g],view:m?"month disabled":t?"month picked":"month",picked:t,disabled:m});this.$yearPrev.toggleClass(i,f),this.$yearNext.toggleClass(i,p),this.$yearCurrent.toggleClass(i,f&&p).html(l+e.yearSuffix||""),this.$months.html(y)},fillDays:function(){var t,e,i,n,o=this.options,r=o.disabledClass||"",s=o.yearSuffix||"",a=o.monthsShort,l=parseInt(o.weekStart,10)%7,d=C.isFunction(o.filter)&&o.filter,c=this.startDate,u=this.endDate,h=this.viewDate,f=h.getFullYear(),p=h.getMonth(),m=f,y=p,g=f,b=p,v=this.date,_=v.getFullYear(),q=v.getMonth(),w=v.getDate(),S=!1,h=!1,$=!1,k=[],x=[],D=[];for(0===p?(--m,y=11):--y,e=T(m,y),(n=(v=new Date(f,p,1)).getDay()-l)<=0&&(n+=7),c&&(S=v.getTime()<=c.getTime()),i=e-(n-1);i<=e;i++)v=new Date(m,y,i),$=!1,c&&($=v.getTime()=u.getTime()),i=1;i<=n;i++)v=new Date(g,b,i),$=!1,u&&($=v.getTime()>u.getTime()),!$&&d&&($=!1===d.call(this.$element,v)),x.push(this.createItem({text:i,view:"day next",muted:!0,disabled:$}));for(i=1;i<=e;i++)v=new Date(f,p,i),t=f===_&&p===q&&i===w,$=!1,c&&($=v.getTime()u.getTime()),!$&&d&&($=!1===d.call(this.$element,v)),D.push(this.createItem({text:i,view:$?"day disabled":t?"day picked":"day",picked:t,disabled:$}));this.$monthPrev.toggleClass(r,S),this.$monthNext.toggleClass(r,h),this.$monthCurrent.toggleClass(r,S&&h).html(o.yearFirst?f+s+" "+a[p]:a[p]+" "+f+s),this.$days.html(k.join("")+D.join(" ")+x.join(""))},click:function(t){var e,i,n,o,r,s,a=C(t.target),l=this.viewDate;if(t.stopPropagation(),t.preventDefault(),!a.hasClass("disabled"))switch(e=l.getFullYear(),i=l.getMonth(),n=l.getDate(),s=a.data("view")){case"years prev":case"years next":e="years prev"===s?e-10:e+10,r=a.text(),(o=p.test(r))&&(e=parseInt(r,10),this.date=new Date(e,i,v(n,28))),this.viewDate=new Date(e,i,v(n,28)),this.fillYears(),o&&(this.showView(1),this.pick("year"));break;case"year prev":case"year next":e="year prev"===s?e-1:e+1,this.viewDate=new Date(e,i,v(n,28)),this.fillMonths();break;case"year current":this.format.hasYear&&this.showView(2);break;case"year picked":this.format.hasMonth?this.showView(1):this.hideView();break;case"year":e=parseInt(a.text(),10),this.date=new Date(e,i,v(n,28)),this.viewDate=new Date(e,i,v(n,28)),this.format.hasMonth?this.showView(1):this.hideView(),this.pick("year");break;case"month prev":case"month next":i="month prev"===s?i-1:"month next"===s?i+1:i,this.viewDate=new Date(e,i,v(n,28)),this.fillDays();break;case"month current":this.format.hasMonth&&this.showView(1);break;case"month picked":this.format.hasDay?this.showView(0):this.hideView();break;case"month":i=C.inArray(a.text(),this.options.monthsShort),this.date=new Date(e,i,v(n,28)),this.viewDate=new Date(e,i,v(n,28)),this.format.hasDay?this.showView(0):this.hideView(),this.pick("month");break;case"day prev":case"day next":case"day":i="day prev"===s?i-1:"day next"===s?i+1:i,n=parseInt(a.text(),10),this.date=new Date(e,i,n),this.viewDate=new Date(e,i,n),this.fillDays(),"day"===s&&this.hideView(),this.pick("day");break;case"day picked":this.hideView(),this.pick("day")}},clickDoc:function(t){for(var e,i=t.target,n=this.$trigger[0];i!==o;){if(i===n){e=!0;break}i=i.parentNode}e||this.hide()},keyup:function(){this.update()},getValue:function(){var t=this.$element,e="";return this.isInput?e=t.val():this.isInline&&!this.options.container||(e=t.text()),e},setValue:function(t){var e=this.$element;t=q(t)?t:"",this.isInput?e.val(t):this.isInline&&!this.options.container||e.text(t)},show:function(){this.isBuilt||this.build(),this.isShown||this.trigger(l).isDefaultPrevented()||(this.isShown=!0,this.$picker.removeClass(b).on(i,C.proxy(this.click,this)),this.showView(this.options.startView),this.isInline||(t.on(e,this._place=x(this.place,this)),h.on(i,this._clickDoc=x(this.clickDoc,this)),this.place()))},hide:function(){this.isShown&&(this.trigger(d).isDefaultPrevented()||(this.isShown=!1,this.$picker.addClass(b).off(i,this.click),this.isInline||(t.off(e,this._place),h.off(i,this._clickDoc))))},update:function(){this.setDate(this.getValue(),!0)},pick:function(t){var e=this.$element,i=this.date;this.trigger(c,{view:t||"",date:i}).isDefaultPrevented()||(this.setValue(this.formatDate(this.date)),this.isInput&&e.trigger("change"))},reset:function(){this.setDate(this.initialDate,!0),this.setValue(this.initialValue),this.isShown&&this.showView(this.options.startView)},getMonthName:function(t,e){var i=this.options,n=i.months;return C.isNumeric(t)?t=r(t):S(e)&&(e=t),!0===e&&(n=i.monthsShort),n[w(t)?t:this.date.getMonth()]},getDayName:function(t,e,i){var n=this.options,o=n.days;return C.isNumeric(t)?t=r(t):(S(i)&&(i=e),S(e)&&(e=t)),(o=!0===i?n.daysMin:!0===e?n.daysShort:o)[w(t)?t:this.date.getDay()]},getDate:function(t){var e=this.date;return t?this.formatDate(e):new Date(e)},setDate:function(t,e){var i=this.options.filter;($(t)||q(t))&&(t=this.parseDate(t),C.isFunction(i)&&!1===i.call(this.$element,t)||(this.date=t,this.viewDate=new Date(t),e||this.pick(),this.isBuilt&&this.fillAll()))},setStartDate:function(t){($(t)||q(t))&&(this.startDate=this.parseDate(t),this.isBuilt&&this.fillAll())},setEndDate:function(t){($(t)||q(t))&&(this.endDate=this.parseDate(t),this.isBuilt&&this.fillAll())},parseDate:function(t){var e,i,n,o,r,s,a=this.format,l=[];if($(t))return new Date(t.getFullYear(),t.getMonth(),t.getDate());if(q(t)&&(l=t.match(f)||[]),i=(t=new Date).getFullYear(),n=t.getDate(),o=t.getMonth(),e=a.parts.length,l.length===e)for(s=0;s
                  ',offset:10,zIndex:1e3,filter:null,show:null,hide:null,pick:null},D.setDefaults=function(t){C.extend(D.DEFAULTS,C.isPlainObject(t)&&t)},D.other=C.fn.qorDatepicker,C.fn.qorDatepicker=function(o){var r,s=k(arguments,1);return this.each(function(){var t,e,i=C(this),n=i.data(a);if(!n){if(/destroy/.test(o))return;t=C.extend({},i.data(),C.isPlainObject(o)&&o),i.data(a,n=new D(this,t))}q(o)&&C.isFunction(e=n[o])&&(r=e.apply(n,s))}),S(r)?this:r},C.fn.qorDatepicker.Constructor=D,C.fn.qorDatepicker.languages=D.LANGUAGES,C.fn.qorDatepicker.setDefaults=D.setDefaults,C.fn.qorDatepicker.noConflict=function(){return C.fn.qorDatepicker=D.other,this}}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(h){var i=window.Mustache,f=window.QOR,o="qor.action",t="enable."+o,n="click."+o,r='[data-ajax-form="true"][data-method]',e=".qor-action-bulk-buttons",s=".qor-page .qor-table-container",a=".qor-table--bulking",l=".qor-table--bulking tbody tr",p="is_undo",d="mdl-data-table--selectable",c="primary_values[]",m=".qor-body__loading";function u(t,e){this.$element=h(t),this.options=h.extend({},u.DEFAULTS,h.isPlainObject(e)&&e),this.ajaxForm={},this.init()}return u.prototype={constructor:u,init:function(){this.bind(),this.initActions()},bind:function(){this.$element.on(n,".qor-action--bulk",this.renderBulkTable.bind(this)).on(n,".qor-action--exit-bulk",this.removeBulkTable.bind(this)),h(document).on(n,l,this.handleBulkTableClick.bind(this)).on(n,r,this.clickAjaxButton.bind(this))},unbind:function(){this.$element.off(n),h(document).off(n,l,this.handleBulkTableClick).off(n,r,this.clickAjaxButton)},initActions:function(){h(s).find("table").length||(h(e).hide(),h(".qor-page__header a.qor-action--button").hide())},collectFormData:function(){var e,t=h(a).find(".mdl-checkbox__input:checked"),i=[],n=[];return t.length&&t.each(function(){var t=h(this).closest("tr").data("primary-key");e={},t&&(i.push({name:c,value:t.toString()}),e[c]=t.toString(),n.push(e))}),this.ajaxForm.formData=i,this.ajaxForm.normalFormData=n,this.ajaxForm},actionSubmit:function(t){return this.submit(t),!1},handleBulkTableClick:function(t){var e=h(t.target).closest("tr"),i=e.find("td").first(),t=i.find(".mdl-js-checkbox");return t.toggleClass("is-checked"),e.toggleClass("is-selected"),i.find("input").prop("checked",t.hasClass("is-checked")),!1},adjustPageBodyStyle:function(t){var e=h(".qor-page > .qor-page__header"),i=h(".qor-page > .qor-page__body"),n=e.find(".qor-page-subnav__header").length?96:48;t?e.height()>n&&i.css("padding-top",e.height()):parseInt(i.css("padding-top"))>n&&i.css("padding-top","")},renderBulkTable:function(){var t=h("body");t.hasClass("qor-slideout-open")&&t.data("qor.slideout").hide(),h(".qor-table__inner-list").remove(),this.toggleBulkButtons(),this.enableTableMDL(),this.adjustPageBodyStyle(!0)},removeBulkTable:function(){this.toggleBulkButtons(),this.disableTableMDL(),this.adjustPageBodyStyle()},enableTableMDL:function(){h(s).find("table").removeAttr("data-upgraded").addClass(d).trigger("enable")},disableTableMDL:function(){h(s).find("table").removeClass(d).find("tr").removeClass("is-selected").find("td:first,th:first").remove()},toggleBulkButtons:function(){this.$element.find(".qor-action-forms").toggle(),h(e).find("button").toggleClass("hidden"),h(s).toggleClass("qor-table--bulking").find(".qor-table__actions").toggle(),h(".qor-page__header .qor-actions, .qor-page__header .qor-search-container").toggle()},clickAjaxButton:function(t){t=h(t.target);return this.collectFormData(),this.ajaxForm.properties=t.data(),this.submit(t),!1},renderFlashMessage:function(t){var e=u.FLASHMESSAGETMPL;return i.parse(e),i.render(e,t)},addLoading:function(){h(m).remove(),h(u.TEMPLATE_LOADING).appendTo(h("body")).trigger("enable.qor.material")},submit:function(e){var i=this,n=this.ajaxForm||{},t=n.properties||e.data();if(e.hasClass("qor-action-disabled"))return!1;!t.fromIndex||n.formData&&n.formData.length?t.confirm?f.qorConfirm(t,function(t){t&&i.handleAjaxSubmit(n,e)}):this.handleAjaxSubmit(n,e):f.qorConfirm(n.properties.errorNoItem)},handleAjaxSubmit:function(o,r){var s=this,a=this.$element,l=r.closest(".qor-action-forms"),d=o.properties||r.data(),c=d.url,u=d.undoUrl,e=r.hasClass(p),t=r.closest(".qor-slideout").length,i=a.length&&!t;e&&(c=u),this.addLoading(),(l.length?l.find('[data-ajax-form="true"][data-method]'):r).addClass("qor-action-disabled"),h.ajax(c,{method:d.method,data:o.formData,dataType:d.datatype||"json",beforeSend:function(){u?r.prop("disabled",!0):i&&s.switchButtons(a,1)},success:function(t){if(u)return a.trigger("undo.qor.action",[r,e,t]),e?r.removeClass(p):r.addClass(p),void r.prop("disabled",!1);window.location.reload()},error:function(t){200!=t.status&&(u?r.prop("disabled",!1):i&&s.switchButtons(a),f.handleAjaxError(t))},complete:function(t){var e,i=t.getResponseHeader("content-type"),n=t.getResponseHeader("Content-Disposition");h(m).remove(),r.prop("disabled",!1),(l.length?l.find('[data-ajax-form="true"][data-method]'):r).removeClass("qor-action-disabled"),n&&-1!==n.indexOf("attachment")&&(e={},t="",null!=(n=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(n))&&n[1]&&(t=n[1].replace(/['"]/g,"")),d.method&&(e=h.extend({},o.normalFormData,{_method:d.method})),f.qorAjaxHandleFile(c,i,t,e),u?r.prop("disabled",!1):s.switchButtons(a))}})},switchButtons:function(t,e){e=!!e;t.find(".qor-action-button").prop("disabled",e)},destroy:function(){this.unbind(),this.$element.removeData(o)}},u.DEFAULTS={},u.TEMPLATE_LOADING='
                  \n
                  \n
                  \n
                  ',h.fn.qorSliderAfterShow.qorInsertActionData=function(t,e){var i=h(e).find('[data-toggle="qor-action-slideout"]'),n=i.find("form"),e=h(a).find(".mdl-checkbox__input:checked");i.length&&e.length&&e.each(function(){var t=h(this).closest("tr").data("primary-key");t&&n.prepend('')})},u.plugin=function(n){return this.each(function(){var t,e=h(this),i=e.data(o);i||e.data(o,i=new u(this,n)),"string"==typeof n&&h.isFunction(t=i[n])&&t.call(i)})},h(function(){var e={},i='[data-toggle="qor.action.bulk"]';h(i).length||h(document).on(n,r,function(t){return(new u).actionSubmit(h(t.target)),!1}),h(document).on("disable.qor.action",function(t){u.plugin.call(h(i,t.target),"destroy")}).on(t,function(t){u.plugin.call(h(i,t.target),e)}).triggerHandler(t)}),u}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(a){var l=window.location,r=window.QOR,o="qor.advancedsearch",t="enable."+o,e="click."+o;function s(t,e){this.$element=a(t),this.options=a.extend({},s.DEFAULTS,a.isPlainObject(e)&&e),this.init()}return s.prototype={constructor:s,init:function(){this.$form=this.$element.find("form"),this.$modal=a(s.MODAL).appendTo("body"),this.bind()},bind:function(){this.$element.on("submit.qor.advancedsearch","form",this.submit.bind(this)).on(e,".qor-advanced-filter__save",this.showSaveFilter.bind(this)).on(e,".qor-advanced-filter__toggle",this.toggleFilterContent).on(e,".qor-advanced-filter__close",this.closeFilter).on(e,".qor-advanced-filter__delete",this.deleteSavedFilter),this.$modal.on("shown.qor.modal",this.start.bind(this))},closeFilter:function(){a(".qor-advanced-filter__dropdown").hide()},toggleFilterContent:function(t){a(t.target).closest(".qor-advanced-filter__toggle").parent().find(">[advanced-search-toggle]").toggle()},showSaveFilter:function(){this.$modal.qorModal("show")},deleteSavedFilter:function(t){var e=a(t.target).closest(".qor-advanced-filter__delete"),i=e.closest(".qor-advanced-filter__savedfilter"),n=e.data("filter-name"),o=l.pathname;return r.qorConfirm({confirm:"Are you sure you want to delete this saved filter?"},function(t){t&&a.get(o,a.param({delete_saved_filter:n})).done(function(){e.closest("li").remove(),0===i.find("li").length&&i.remove()}).fail(function(){r.qorConfirm("Server error, please try again!")})}),!1},start:function(){this.$modal.trigger("enable.qor.material").on(e,".qor-advanced-filter__savefilter",this.saveFilter.bind(this))},saveFilter:function(){var t=this.$modal.find("#qor-advanced-filter__savename").val();t&&this.$form.prepend('')).submit()},submit:function(){var t,e=this.$form,i=e.find("input[name],select[name]"),n=[],o=e.closest(".qor-bottomsheets"),r=e.serialize();if(i.each(function(){n.push(a(this).attr("name"))}),t=function(t){var e,i,n=decodeURIComponent(l.search.substr(1)).split("&"),o={};if(1==n.length&&""==n[0])return!1;for(i in n)""!==n[i]&&(e=n[i].split("="),o[e[0]]=e[1]);return t.forEach(function(t){delete o[t]}),o}(n),!a.isEmptyObject(t))for(var s in t)t.hasOwnProperty(s)&&e.prepend('\n
                  \n
                  \n

                  Save advanced filter

                  \n
                  \n
                  \n \n
                  \n \n \n
                  \n\n
                  \n \n
                  \n \n
                  \n
                  \n ',s.plugin=function(n){return this.each(function(){var t,e=a(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new s(this,n))}"string"==typeof n&&a.isFunction(t=i[n])&&t.apply(i)})},a(function(){var e='[data-toggle="qor.advancedsearch"]';a(document).on("disable.qor.advancedsearch",function(t){s.plugin.call(a(e,t.target),"destroy")}).on(t,function(t){s.plugin.call(a(e,t.target),void 0)}).triggerHandler(t)}),s}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(o){var r="qor.autoheight",t="enable."+r;function s(t,e){this.$element=o(t),this.options=o.extend({},s.DEFAULTS,o.isPlainObject(e)&&e),this.init()}return s.prototype={constructor:s,init:function(){var t=this.$element;this.paddingTop=parseInt(t.css("padding-top"),10),this.paddingBottom=parseInt(t.css("padding-bottom"),10),this.resize(),this.bind()},bind:function(){this.$element.on("input",o.proxy(this.resize,this))},unbind:function(){this.$element.off("input",this.resize)},resize:function(){var t=this.$element,e=t.prop("scrollHeight");e?t.height("auto").height(e-this.paddingTop-this.paddingBottom):t.height("40px")},destroy:function(){this.unbind(),this.$element.removeData(r)}},s.DEFAULTS={},s.plugin=function(n){return this.each(function(){var t,e=o(this),i=e.data(r);if(!i){if(/destroy/.test(n))return;e.data(r,i=new s(this,n))}"string"==typeof n&&o.isFunction(t=i[n])&&t.apply(i)})},o(function(){var e="textarea.qor-js-autoheight";o(document).on("disable.qor.autoheight",function(t){s.plugin.call(o(e,t.target),"destroy")}).on(t,function(t){s.plugin.call(o(e,t.target))}).triggerHandler(t)}),s}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(b){var o=window._,n=window.FormData,i=window.QOR_Translations,r="qor.bottomsheets",t="click."+r,e="submit."+r,v="qor-bottomsheets-open",_=".mdl-layout__content.qor-page",s=".qor-page__body",q=".qor-page__header",a=".qor-bottomsheets__search-input";function l(t,e){var i=[],n=e?"src":"href";return t.each(function(){i.push(b(this).attr(n))}),o.uniq(i)}function d(t,e,i){for(var n=0,o=0,r=t.length;o')},filterChanged:function(t,e,i){i=this.constructloadURL(e,i);return i&&this.reload(i),!1},selectorChanged:function(t,e,i){i=this.constructloadURL(e,i);return i&&this.reload(i),!1},keyup:function(t){var e=this.$bottomsheets.find(a);13===t.which&&e.length&&e.is(":focus")&&this.search()},search:function(){var t=this.$bottomsheets,e=t.data().url,i=b.trim(t.find(a).val()),t=e+"?keyword="+i;/\?/g.test(e)&&(t=e+"&keyword="+i),this.reload(t)},pagination:function(t){t=b(t.target).closest("a").prop("href");return t&&this.reload(t),!1},reload:function(t){var e=this.$bottomsheets.find(s);this.addLoading(e),this.fetchPage(t)},reloadFromUrl:function(t,e){this.reload(e)},fetchPage:function(i){var n=this.$bottomsheets,o=this;b.get(i,function(t){var e=b(t).find(_),t=e.find(q),e=e.find(s);e.length?(n.find(s).html(e.html()),t.length&&(o.$body.find(q).html(t.html()).trigger("enable"),o.addHeaderClass()),n.trigger("reload.qor.bottomsheets")):o.reload(i)}).fail(function(){window.alert("server error, please try again later!")})},constructloadURL:function(t,e){var i,n,o=this.filterURL,r=this.$bottomsheets.data().url;if(!o){if(!r)return;o=r}return i=new URL("http://www.getqor.com/"+t),n=e,r=i.search,n=n.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),t=null===(r=new RegExp("[\\?&]"+n+"=([^&#]*)").exec(decodeURIComponent(r)))?"":r[1].replace(/\+/g," "),o=this.filterURL=(i=e,n=t,r=o,e=String(i).replace(/[\\^$*+?.()|[\]{}]/g,"\\$&"),t=new RegExp("([?&])"+e+"=.*?(&|$)","i"),e=-1!==r.indexOf("?")?"&":"?",r.match(t)?n?r.replace(t,"$1"+i+"="+n+"$2"):"?"===RegExp.$1||RegExp.$1===RegExp.$2?r.replace(t,"$1"):r.replace(t,""):n?r+e+i+"="+n:void 0)},addHeaderClass:function(){this.$body.find(q).hide(),this.$bottomsheets.find(q).children(".qor-bottomsheet__filter").length&&this.$body.addClass("has-header").find(q).show()},addLoading:function(t){t.html(""),b(w.TEMPLATE_LOADING).appendTo(t).trigger("enable.qor.material")},loadExtraResource:function(t){var e,i,n=(e=t.$links,i=b("link"),e=l(e),i=l(i),o.difference(e,i)),i=(e=t.$scripts,i=b("script"),e=l(e,!0),i=l(i,!0),o.difference(e,i));n.length&&function t(e){var i=document.createElement("link"),n=e.shift();i.type="text/css",i.rel="stylesheet",i.onload=function(){e.length&&t(e)},i.href=n,document.getElementsByTagName("head")[0].appendChild(i)}(n),i.length&&d(i,t)},loadMedialibraryJS:function(t){var e,t=t.filter("script"),i=/theme=media_library/g,n=this;t.each(function(){var t;e=b(this).prop("src"),i.test(e)&&((t=document.createElement("script")).src=e,document.body.appendChild(t),n.mediaScriptAdded=!0)})},submit:function(t){var r,e=t.target,s=b(e),a=this,l=s.prop("action"),d=s.closest(".qor-bottomsheets"),c=d.data(),i=c.ajaxType,u=s.find(":submit");c.ingoreSubmit||s.data().normalSubmit||(b(document).trigger("bottomsheetBeforeSend.qor.bottomsheets"),t.preventDefault(),r=new n(e),b.ajax(l,{method:s.prop("method"),data:r,dataType:i||"html",processData:!1,contentType:!1,beforeSend:function(){u.prop("disabled",!0)},success:function(t,e,i){if(c.ajaxMute)d.remove();else if(c.ajaxTakeover)c.$target.parent().trigger("ajaxSuccessed.qor.bottomsheets",[t,d]);else{t=i.getResponseHeader("Content-Disposition");if(t&&-1!==t.indexOf("attachment")){var t=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(t),n=i.getResponseHeader("Content-Type"),o="";return null!=t&&t[1]&&(o=t[1].replace(/['"]/g,"")),window.QOR.qorAjaxHandleFile(l,n,o,r),void u.prop("disabled",!1)}b(".qor-error").remove();n=s.data("returnUrl"),o=s.data("refreshUrl");o?window.location.href=o:"refresh"!=n?(n&&"refresh"!=n?a.load(n):a.refresh(),b(document).trigger("bottomsheetSubmitComplete.qor.bottomsheets")):a.refresh()}},error:function(t){window.QOR.handleAjaxError(t)},complete:function(){u.prop("disabled",!1)}}))},load:function(s,a,l){var d,t,e,c=this.options,u=a.actionData,h=this.resourseData,f=h.selectModal,p=h.ingoreSubmit,m=this.$bottomsheets,y=this.$header,g=this.$body;s&&(this.show(),this.addLoading(g),this.filterURL=s,g.removeClass("has-header has-hint"),a=b.isPlainObject(a)?a:{},d=a.method||"GET",t=a.datatype||"html",e=b.proxy(function(){b.ajax(s,{method:d,dataType:t,success:b.proxy(function(t){var e,i,n,o,r;"GET"===d?(i={$scripts:(e=b(t)).filter("script"),$links:e.filter("link"),url:s,response:t},n=f&&e.find(".qor-search-container").length,o=t.match(/<\s*body.*>[\s\S]*<\s*\/body\s*>/gi),r=e.find(_),o&&(o=o.join("").replace(/<\s*body/gi,"').concat(a.selectBacktolistTitle,"")),f&&(g.find(".qor-button--new").data("ingoreSubmit",!0).data("selectId",h.selectId).data("loadInline",!0),"one"==f||a.selectNohint||void 0!==h.maxItem&&"1"==h.maxItem||g.addClass("has-hint"),"mediabox"!=f||this.mediaScriptAdded||this.loadMedialibraryJS(e)),y.find(".qor-button--new").remove(),this.$title.after(g.find(".qor-button--new")),n&&(m.addClass("has-search"),y.find(".qor-bottomsheets__search").remove(),y.prepend(w.TEMPLATE_SEARCH)),u&&u.length&&this.bindActionData(u),h.bottomsheetClassname&&m.addClass(h.bottomsheetClassname),m.trigger("enable"),m.one("hidden.qor.bottomsheets",function(){b(this).trigger("disable")}),this.addHeaderClass(),m.data(a),l&&b.isFunction(l)&&l(this.$bottomsheets),m.trigger("bottomsheetLoaded.qor.bottomsheets",[s,t]))):a.returnUrl?this.load(a.returnUrl):this.refresh()},this),error:b.proxy(function(){var t;this.$bottomsheets.remove(),b(".qor-bottomsheets").is(":visible")||b("body").removeClass(v),t=0=u&&c&&v.isFunction(c)&&c()}).attr("src",t).data("originalUrl",t),p.show()},start:function(){var o=this.options,r=this.$modal,t=this.$target,e=t.data(),s=e.sizeName||"original",i=e.sizeResolution,n=e&&e.originalUrl&&t.attr("data-original-url")?/\.original\./.test(e.originalUrl)?e.originalUrl:/\.original\./.test(t.attr("data-original-url"))?t.attr("data-original-url"):t.attr("data-original-url").replace(/file\./,"file.original."):t.attr("src"),a=v("")),l=this.data||{},d=this,t=NaN,n=e.sizeResolutionWidth,e=e.sizeResolutionHeight;i&&(n||e||(n=q(i,"width"),e=q(i,"height")),t=n/e),l[o.key]||(l[o.key]={}),r.trigger("enable.qor.material").find(u).html(a),(e=this.getList(t))&&r.find(h).show().append(e),a.cropper({aspectRatio:t,data:function(t){var e,i={};if(v.isPlainObject(t))for(e in t)t.hasOwnProperty(e)&&(i[String(e).toLowerCase()]=t[e]);return i}(l[o.key][s]),background:!1,movable:!1,zoomable:!1,scalable:!1,rotatable:!1,autoCropArea:1,ready:function(){r.find(".qor-cropper__options-toggle").on(c,function(){r.find(".qor-cropper__options-input").prop("checked",v(this).prop("checked"))}).prop("checked",!0),r.find(".qor-cropper__save").one(c,function(){var t,e=a.cropper("getData",!0),i=a.cropper("getCroppedCanvas"),n=[];if(l.Crop=!0,l[o.key][s]=e,d.imageData=a.cropper("getImageData"),d.cropData=e,i)try{t=i.toDataURL()}catch(t){console.log(t),console.log("Please check image Cross-origin setting")}r.find(h+" input").each(function(){var t=v(this);t.prop("checked")&&n.push(t.attr("name"))}),d.output(t,n),r.qorModal("hide")})}})},stop:function(){this.$modal.trigger("disable.qor.material").find(u+" > img").cropper("destroy").remove().end().find(h).hide().find("ul").remove()},getList:function(o){var r=[];return this.$list.find("img").not(this.$target).each(function(){var t=v(this).data(),e=t.sizeResolution,i=t.sizeName,n=t.sizeResolutionWidth,t=t.sizeResolutionHeight;e&&(n||t||(n=q(e,"width"),t=q(e,"height")),n/t===o&&r.push('"))}),r.length?"
                  • "+r.join("
                  • ")+"
                  ":""},output:function(t,e){var i=this.$target;t?this.center(i.attr("src",t),!0):this.preview(i),v.isArray(e)&&e.length&&this.autoCrop(t,e),this.$output.val(JSON.stringify(this.data)).trigger(o),this.$formCropInput.val(JSON.stringify(this.data))},preview:function(t,e,i){var n=t.parent().parent(),o=n.width(),r=n.height(),s=e||this.imageData,n=v.extend({},i||this.cropData),e=n.width/n.height,i=o;0!=i&&0!=s.naturalWidth&&0!=s.naturalHeight&&(r*e<=o&&(i=r*e),i=n.width/i,t.css({maxWidth:s.naturalWidth/i,maxHeight:s.naturalHeight/i}),this.center(t))},center:function(t,o){t.each(function(){var t=v(this),i=t.parent(),n=i.parent();function e(){var t=n.height(),e=i.height(),e=eclear'))},show:function(){this.$element.find(l).toggle()},close:function(t){var e=s(t.target),i=s(l),n=i.is(":visible"),o=e.closest(l).length,r=e.closest(".qor-filter-toggle").length,t=e.closest(".qor-modal").length,e=e.closest(".ui-timepicker-wrapper").length;n&&(o||r||t||e)||i.hide()},setFilterTime:function(t){var e,i,n=s(t.target),o=n.data(),t=o.filterRange;if(!t)return!1;if(s(this.options.label).removeClass(d),n.addClass(d),"events"==t)return this.$timeStart.val(o.scheduleStartAt||""),this.$timeEnd.val(o.scheduleEndAt||""),this.$searchButton.click(),!1;switch(t){case"today":e=i=new Date;break;case"week":e=this.startWeekDate,i=this.endWeekDate;break;case"month":e=this.startMonthDate,i=this.endMonthDate}if(!e||!i)return!1;o=this.getTime(e)+" 00:00",t=this.getTime(i)+" 23:59",this.$timeStart.val(o),this.$timeEnd.val(t),this.$searchButton.click()},getTime:function(t){var e=(e=t.getMonth()+1)<10?"0"+e:e,i=(i=t.getDate())<10?"0"+i:i;return t.getFullYear()+"-"+e+"-"+i},clear:function(){var t=s(this.options.trigger),e=t.find(".qor-selector-label");return t.removeClass("active clearable"),e.html(e.data("label")),this.$timeStart.val(""),this.$timeEnd.val(""),this.$searchButton.click(),!1},getUrlParameter:function(t){var e=decodeURIComponent(a.search),t=t.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),e=new RegExp("[\\?&]"+t+"=([^&#]*)").exec(e);return null===e?"":e[1].replace(/\+/g," ")},updateQueryStringParameter:function(t,e,i){var n=i||a.href,o=n.match(/#\S*$/)||"",r=String(t).replace(/[\\^$*+?.()|[\]{}]/g,"\\$&"),i=new RegExp("([?&])"+r+"=.*?(&|$)","i"),r=-1!==n.indexOf("?")?"&":"?";return o&&(o=o[0],n=n.replace(o,"")),n.match(i)?n=e?n.replace(i,"$1"+t+"="+e+"$2"):"?"===RegExp.$1||RegExp.$1===RegExp.$2?n.replace(i,"$1"):n.replace(i,""):e&&(n=n+r+t+"="+e),n+o},search:function(){var t=this.$searchParam,i=a.href,n=this;t.length&&(t.each(function(){var t=s(this),e=t.data().searchParam,t=t.val();i=n.updateQueryStringParameter(e,t,i)}),this.$element.closest(r).length?s(r).trigger("filterChanged.qor.filter",[i,"qor.filter.time"]):a.href=i)},destroy:function(){this.unbind(),this.$element.removeData(o)}},c.DEFAULTS={label:!1,trigger:!1,button:!1,clear:!1},c.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new c(this,n))}"string"==typeof n&&s.isFunction(t=i[n])&&t.apply(i)})},s(function(){var e='[data-toggle="qor.filter.time"]',i={label:".qor-filter__block-buttons button",trigger:"a.qor-filter-toggle",button:".qor-filter__button-search",clear:".qor-selector-clear"};s(document).on("disable.qor.filter",function(t){c.plugin.call(s(e,t.target),"destroy")}).on(t,function(t){c.plugin.call(s(e,t.target),i)}).triggerHandler(t)}),c}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(d){var c=window.location,o="qor.filter",t="enable."+o,e="click."+o,i="change."+o,u=".qor-bottomsheets";function h(t,i){var n,e=decodeURI(c.search),o=c.search.match(/per_page=\d+/),e=e.replace(/per_page=\d+/g,"").replace(/page=\d+/,"page=1");return o&&o.length&&(e=e+"&"+o[0]),d.isArray(t)&&(n=f(e),d.each(t,function(t,e){-1===(t=d.inArray(e,n))?n.push(e):i&&n.splice(t,1)}),e="?"+n.join("&")),e}function f(t){var e=[];return t&&-1 thead"),this.$tbody=e.find("> tbody"),this.$header=s(t.header),this.$subHeader=s(t.subHeader),this.$content=s(t.content),this.marginBottomPX=parseInt(this.$subHeader.css("marginBottom")),this.paddingHeight=t.paddingHeight,this.resize(),this.bind())},bind:function(){this.$content.on(i,this.toggle.bind(this)),t.on(e,this.resize.bind(this))},unbind:function(){this.$content.off(i,this.toggle).off(e,this.resize)},isNeedBuild:function(){var t=this.$element;return!!(1 tr:visible").length<=1||t.data("disable-fixer"))},build:function(){var e=[];this.$tbody.find("> tr:first").children().each(function(){var t=s(this).outerWidth();s(this).outerWidth(t),e.push(t)}),this.$thead.find(">tr").children().each(function(t){s(this).outerWidth(e[t])})},toggle:function(){var t,e,i,n,o,r;this.$content.length&&(t=this.$element,e=this.$thead,i=this.$content.scrollTop(),n=this.$subHeader.outerHeight()+this.paddingHeight+this.marginBottomPX,o=s(".qor-page__header").outerHeight(),r=this.$content.offset().top+s(".qor-page__header").height(),n-o\n \n \n "),this.bind()},bind:function(){this.$element.on(i,l,this.showEditButton).on(n,l,this.hideEditButton).on(e,".qor-inlineedit__cancel",this.hideEdit).on(e,".qor-inlineedit__save",this.saveEdit).on(e,r,this.showEdit.bind(this))},unbind:function(){this.$element.off(i).off(n).off(e)},showEditButton:function(t){var e=s(u.TEMPLATE_EDIT);if(s(t.target).closest(a).find("input:disabled, textarea:disabled,select:disabled").length)return!1;e.appendTo(s(this))},hideEditButton:function(){s(".qor-inlineedit__edit").remove()},showEdit:function(t){t=s(t.target).closest(r).hide().closest(a).addClass(c);s(this.TEMPLATE_SAVE).appendTo(t)},hideEdit:function(){s(this).closest(a).removeClass(c).find(d).remove()},saveEdit:function(){var n=s(this),o=n.closest(a),t=n.closest("form"),e=o.closest(".qor-fieldset").find('input.qor-hidden__primary_key[type="hidden"]'),i=o.find('input[name*="QorResource"],textarea[name*="QorResource"],select[name*="QorResource"]'),r=i.length&&i.prop("name").match(/\.\w+/g),i=i.serialize();e.length&&(i="".concat(i,"&").concat(e.serialize())),r.length&&s.ajax(t.prop("action"),{method:t.prop("method"),data:i,dataType:"json",beforeSend:function(){n.prop("disabled",!0)},success:function(t){var e=function(t,e){var i,n=e[t[0].slice(1)];if(1mode_edit',u.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(o);i||e.data(o,i=new u(this,n)),"string"==typeof n&&s.isFunction(t=i[n])&&t.call(i)})},s(function(){var e='[data-toggle="qor.inlineEdit"]',i={};s(document).on("disable.qor.inlineEdit",function(t){u.plugin.call(s(e,t.target),"destroy")}).on(t,function(t){u.plugin.call(s(e,t.target),i)}).triggerHandler(t)}),u}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(e){var i=window.componentHandler,n='[class*="mdl-js"],[class*="mdl-tooltip"]';function o(t){i&&(e(t).is(n)?i.upgradeElements(t):i.upgradeElements(e(n,t).toArray()))}function r(t){i&&(e(t).is(n)?i.downgradeElements(t):i.downgradeElements(e(n,t).toArray()))}e(function(){e(document).on("enable.qor.material",function(t){o(t.target)}).on("disable.qor.material",function(t){r(t.target)}).on("update.qor.material",function(t){r(t.target),o(t.target)})})}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(o){var n=o(document),r="qor.modal",t="click."+r,e="keyup."+r,s="transitionend",a="qor-modal-open",l="in",i="aria-hidden";function d(t,e){this.$element=o(t),this.options=o.extend({},d.DEFAULTS,o.isPlainObject(e)&&e),this.transitioning=!1,this.fadable=!1,this.init()}return d.prototype={constructor:d,init:function(){this.fadable=this.$element.hasClass("fade"),this.options.show?this.show():this.toggle()},bind:function(){this.$element.on(t,o.proxy(this.click,this)),this.options.keyboard&&n.on(e,o.proxy(this.keyup,this))},unbind:function(){this.$element.off(t,this.click),this.options.keyboard&&n.off(e,this.keyup)},click:function(t){var e=this.$element[0],i=t.target;if(i===e&&this.options.backdrop)this.hide();else for(;i!==e;){if("modal"===o(i).data("dismiss")){this.hide();break}i=i.parentNode}},keyup:function(t){27===t.which&&this.hide()},show:function(t){var e,i=this.$element;if(!this.transitioning&&!i.hasClass(l)&&(e=o.Event("show.qor.modal"),i.trigger(e),!e.isDefaultPrevented())){if(n.find("body").addClass(a),i.addClass("shown").scrollTop(0).get(0).offsetHeight,this.transitioning=!0,t||!this.fadable)return i.addClass(l),void this.shown();i.one(s,o.proxy(this.shown,this)),i.addClass(l)}},shown:function(){this.transitioning=!1,this.bind(),this.$element.attr(i,!1).trigger("shown.qor.modal").focus()},hide:function(t){var e,i=this.$element;if(!this.transitioning&&i.hasClass(l)&&(e=o.Event("hide.qor.modal"),i.trigger(e),!e.isDefaultPrevented())){if(n.find("body").removeClass(a),this.transitioning=!0,t||!this.fadable)return i.removeClass(l),void this.hidden();i.one(s,o.proxy(this.hidden,this)),i.removeClass(l)}},hidden:function(){this.transitioning=!1,this.unbind(),this.$element.removeClass("shown").attr(i,!0).trigger("hidden.qor.modal")},toggle:function(){this.$element.hasClass(l)?this.hide():this.show()},destroy:function(){this.$element.removeData(r)}},d.DEFAULTS={backdrop:!1,keyboard:!0,show:!0},d.plugin=function(n){return this.each(function(){var t,e=o(this),i=e.data(r);if(!i){if(/destroy/.test(n))return;e.data(r,i=new d(this,n))}"string"==typeof n&&o.isFunction(t=i[n])&&t.apply(i)})},o.fn.qorModal=d.plugin,o(function(){var e=".qor-modal";o(document).on(t,'[data-toggle="qor.modal"]',function(){var t=o(this),e=t.data(),t=o(e.target||t.attr("href"));d.plugin.call(t,t.data(r)?"toggle":e)}).on("disable.qor.modal",function(t){d.plugin.call(o(e,t.target),"destroy")}).on("enable.qor.modal",function(t){d.plugin.call(o(e,t.target))})}),d}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(r){var o="qor.tabbar.radio",t="enable."+o,e="click."+o,s="[data-tab-target]",a="is-active";function l(t,e){this.$element=r(t),this.options=r.extend({},l.DEFAULTS,r.isPlainObject(e)&&e),this.init()}return l.prototype={constructor:l,init:function(){this.bind()},bind:function(){this.$element.on(e,s,this.switchTab.bind(this))},unbind:function(){this.$element.off(e,s,this.switchTab)},switchTab:function(t){var e=r(t.target),i=this.$element,n=i.find(s),o=i.find("[data-tab-source]"),t=e.data().tabTarget;e.hasClass(a)||(n.removeClass(a),e.addClass(a),o.hide().filter('[data-tab-source="'+t+'"]').show(),i.trigger("switched.qor.tabbar.radio",[i,t]))},destroy:function(){this.unbind()}},l.DEFAULTS={},l.plugin=function(n){return this.each(function(){var t,e=r(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new l(this,n))}"string"==typeof n&&r.isFunction(t=i[n])&&t.apply(i)})},r(function(){var e='[data-toggle="qor.tab.radio"]';r(document).on("disable.qor.tabbar.radio",function(t){l.plugin.call(r(e,t.target),"destroy")}).on(t,function(t){l.plugin.call(r(e,t.target))}).triggerHandler(t)}),l}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(c){var r="qor.redactor",t="enable."+r,l="click."+r,e="addCrop."+r,i="removeCrop."+r,s="scroll."+r,n=".qor-cropper__toggle--redactor";function u(t,e){this.$element=c(t),this.options=c.extend(!0,{},u.DEFAULTS,c.isPlainObject(e)&&e),this.init()}return u.prototype={constructor:u,init:function(){var i,t=this.options,e=this.$element,n=e.closest(t.parent);n.length||(n=e.parent()),this.$parent=n,this.$button=c(u.BUTTON),this.$modal=c((i=u.MODAL,t=t.text,"string"==typeof i&&"object"===_typeof(t)&&c.each(t,function(t,e){i=i.replace("$["+String(t).toLowerCase()+"]",e)}),i)).appendTo("body"),this.bind()},bind:function(){this.$element.on(e,c.proxy(this.addButton,this)).on(i,c.proxy(this.removeButton,this))},unbind:function(){this.$element.off(e).off(i).off(s)},addButton:function(t,e){var i=c(e);this.$button.css("left",c(e).width()/2).prependTo(i.parent()).find(n).one(l,c.proxy(this.crop,this,i))},removeButton:function(){this.$button.find(n).off(l),this.$button.detach()},crop:function(n){var o,r=this.options,s=n.attr("src"),t=s,a=this.$modal;c.isFunction(r.replace)&&(t=r.replace(t)),o=c("")),a.one("shown.qor.modal",function(){var t,e;o.cropper({data:(t=n.attr("data-crop-options"),e=t&&t.split(","),t=null,e&&4===e.length&&(t={x:Number(e[0]),y:Number(e[1]),width:Number(e[2]),height:Number(e[3])}),t),background:!1,movable:!1,zoomable:!1,scalable:!1,rotatable:!1,checkImageOrigin:!1,ready:function(){a.find(".qor-cropper__save").one(l,function(){var i=o.cropper("getData",!0);c.ajax(r.remote,{type:"POST",contentType:"application/json",data:JSON.stringify({Url:s,CropOptions:{original:function(t){var e,i,n={};if(c.isPlainObject(t))for(e in t)t.hasOwnProperty(e)&&(n["string"==typeof(i=e)&&(i=i.charAt(0).toUpperCase()+i.substr(1)),i]=t[e]);return n}(i)},Crop:!0}),dataType:"json",success:function(t){var e;c.isPlainObject(t)&&t.url&&(n.attr("src",t.url).attr("data-crop-options",(t=i,e=[],c.isPlainObject(t)&&c.each(t,function(){e.push(arguments[1])}),e.join())).removeAttr("style").removeAttr("rel"),c.isFunction(r.complete)&&r.complete(),a.qorModal("hide"))}})})}})}).one("hidden.qor.modal",function(){o.cropper("destroy").remove()}).qorModal("show").find(".qor-cropper__wrapper").append(o)},destroy:function(){this.unbind(),this.$modal.qorModal("hide").remove(),this.$element.removeData(r)}},u.DEFAULTS={remote:!1,parent:!1,toggle:!1,replace:null,complete:null,text:{title:"Crop the image",ok:"OK",cancel:"Cancel"}},u.BUTTON='
                  \n Edit\n Crop\n
                  ',u.MODAL='',u.plugin=function(o){return this.each(function(){var t,i=c(this),n=i.data(r);if(n)/destroy/.test(o)&&window.$R(this,"destroy");else{if(!window.$R)return;if(/destroy/.test(o))return;i.data(r,n={});var e={imageUpload:i.data("uploadUrl"),fileUpload:i.data("uploadUrl"),buttons:["html","format","bold","italic","deleted","lists","image","file","link"],linkNewTab:!0,linkTitle:!1,autoparsePaste:!1,autoparseLinks:!1,multipleUpload:!1,toolbarFixedTarget:!i.closest(".qor-slideout").length&&!i.closest(".qor-bottomsheets").length&&c("main.mdl-layout__content").length?"main.mdl-layout__content":document,callbacks:{started:function(){var t,a=c(this.container.$container.nodes[0]),l=c(this.toolbar.$toolbar.nodes[0]),e=c(".qor-slideout").is(":visible"),d=64;e?d=0!=i.closest(".qor-bottomsheets").length?(t=i.closest(".qor-page__body"),i.closest(".qor-page__body").offset().top):(t=".qor-slideout__body",c(".qor-slideout__header").height()):d+=c(t=".qor-layout main.qor-page").find(".qor-page__header").height(),c(t).on(s,function(){var t,e,i,n,o,r,s;t=l,i=d,n=(e=a).offset().top,o=e.outerHeight(),r={position:"relative",top:"auto",width:"auto"},s={position:"fixed",top:i,width:e.width(),boxShadow:"none"},n .qor-field__block > .qor-fieldset--new");this.singlePage=!(t.closest(".qor-slideout").length&&t.closest(".qor-bottomsheets").length),this.maxitems=t.data("maxItem"),this.isSortable=t.hasClass("qor-fieldset-sortable"),e.length&&!t.closest(".qor-fieldset--new").length&&(e.trigger("disable"),e.find("select[data-toggle]").removeAttr("data-select2-id"),this.isMultipleTemplate=t.data("isMultiple"),this.isMultipleTemplate?(this.fieldsetName=[],this.template={},this.index=[],e.each(function(t,e){(i=c(e).data("fieldsetName"))&&(n.template[i]=c(e).prop("outerHTML"),n.fieldsetName.push(i))}),this.parseMultiple()):this.parse(e.prop("outerHTML")),e.hide(),this.bind(),this.resetButton(),this.resetPositionButton())},resetPositionButton:function(){var t=this.$element.find("> .qor-sortable__button");this.isSortable&&(1 .qor-field__block > .qor-fieldset").not(".qor-fieldset--new,.is-deleted").length},toggleButton:function(t){var e=this.$element.find("> .qor-field__block > .qor-fieldset__add");t?e.hide():e.show()},resetButton:function(){this.maxitems<=this.getCurrentItems()?this.toggleButton(!0):this.toggleButton()},parse:function(t){t&&(t=this.initTemplate(t),this.template=t.template,this.index=t.index)},parseMultiple:function(){for(var t,e,i=this.fieldsetName,n=0,o=i.length;n .qor-field__block > .qor-sortable__item").not(".qor-fieldset--new").length,e.attr("order-index",t).attr("order-item","item_".concat(t)).css("order",t)),e.data("itemIndex",this.index).removeClass("qor-fieldset--new"),e}},del:function(t){var e,i=this.options,n=c(t.target).closest(i.itemClass),o=this,t={confirm:c(t.target).closest(i.delClass).data("confirm")||"Are you sure?"};s.qorConfirm(t,function(t){t&&(n.addClass("is-deleted").children(":visible").addClass("hidden").hide(),(e=c(i.alertTemplate.replace("{{name}}",o.parseName(n)))).find(i.undoClass).one(a,function(){if(o.maxitems<=o.getCurrentItems())return window.QOR.qorConfirm(o.$element.data("maxItemHint")),!1;n.find("> .qor-fieldset__alert").remove(),n.removeClass("is-deleted").children(".hidden").removeClass("hidden").show(),o.resetButton(),o.resetPositionButton()}.bind(this)),o.resetButton(),o.resetPositionButton(),n.append(e))})},parseName:function(t){t=t.find("input[name]").attr("name")||t.find("textarea[name]").attr("name");if(t)return t.replace(/[^\[\]]+$/,"")},destroy:function(){this.unbind(),this.$element.removeData(o)}},d.DEFAULTS={itemClass:".qor-fieldset",newClass:".qor-fieldset--new",addClass:".qor-fieldset__add",delClass:".qor-fieldset__delete",childrenClass:".qor-field__block",undoClass:".qor-fieldset__undo",alertTemplate:'
                  '},d.plugin=function(n){return this.each(function(){var t,e=c(this),i=e.data(o);i||e.data(o,i=new d(this,n)),"string"==typeof n&&c.isFunction(t=i[n])&&t.call(i)})},c(function(){var e=l,i={};c(document).on("disable.qor.replicator",function(t){d.plugin.call(c(e,t.target),"destroy")}).on(t,function(t){d.plugin.call(c(e,t.target),i)}).triggerHandler(t)}),d}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(s){var a=window.location,o=window.componentHandler,l=window.history,r="qor.globalSearch",t="enable."+r,e="click."+r,d=".qor-global-search--resource",c=".qor-global-search--results",u="is-active";function h(t,e){this.$element=s(t),this.options=s.extend({},h.DEFAULTS,s.isPlainObject(e)&&e),this.init()}return h.prototype={constructor:h,init:function(){this.bind(),this.initTab()},bind:function(){this.$element.on(e,s.proxy(this.click,this))},unbind:function(){this.$element.off(e,this.check)},initTab:function(){var t=a.search;/resource_name/.test(t)&&(t=t.match(/resource_name=\w+/g).toString().split("=")[1],s(d).removeClass(u),s('[data-resource="'+t+'"]').addClass(u))},click:function(t){var e,i,n,o=s(t.target),r=o.data();o.is(d)&&(n=a.href.replace(/#/g,""),e=r.resource,i=/resource_name/.test(n),t="resource_name="+e,r=/keyword/.test(n)?"&":"?keyword=&",n=e?i?n.replace(/resource_name=\w+/g,t):n+r+t:n.replace(/&resource_name=\w+/g,""),l.pushState?this.fetchSearch(n,o):a.href=n)},fetchSearch:function(e,i){var n=document.title;s.ajax(e,{method:"GET",dataType:"html",beforeSend:function(){s(".mdl-spinner").remove(),s(c).prepend('
                  ').find(".qor-section").hide(),o.upgradeElement(document.querySelector(".mdl-spinner"))},success:function(t){t=s(t).find(c).html();s(d).removeClass(u),i.addClass(u),l.pushState({Page:e,Title:n},n,e),s(".mdl-spinner").remove(),s(c).removeClass("loading").html(t),o.upgradeElements(document.querySelectorAll(".qor-table"))},error:function(t,e,i){s(c).find(".qor-section").show(),s(".mdl-spinner").remove(),window.alert([e,i].join(": "))}})},destroy:function(){this.unbind(),this.$element.removeData(r)}},h.DEFAULTS={},h.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(r);i||e.data(r,i=new h(this,n)),"string"==typeof n&&s.isFunction(t=i[n])&&t.call(i)})},s(function(){var e='[data-toggle="qor.global.search"]',i={};s(document).on("disable.qor.globalSearch",function(t){h.plugin.call(s(e,t.target),"destroy")}).on(t,function(t){h.plugin.call(s(e,t.target),i)}).triggerHandler(t)}),h}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(l){var d=window.FormData,c=window.QOR,o="qor.selectcore",s="afterSelected."+o,t="click."+o,e="submit."+o,i="table.qor-js-table tr";function r(t,e){this.$element=l(t),this.options=l.extend({},r.DEFAULTS,l.isPlainObject(e)&&e),this.init()}return r.prototype={constructor:r,init:function(){this.bind()},bind:function(){this.$element.on(t,i,this.processingData.bind(this)).on(e,"form",this.submit.bind(this))},unbind:function(){this.$element.off(t,i).off(e,"form")},processingData:function(e){var t=l(e.target).closest("tr"),i=t.closest(".qor-bottomsheets"),n={},o=this.options,r=o.onSelect,o=o.loading;return(n=l.extend({},n,t.data())).$clickElement=t,t=n.mediaLibraryUrl||n.url,o&&l.isFunction(o)&&o(i),t?l.getJSON(t,function(t){t.MediaOption&&(t.MediaOption=JSON.parse(t.MediaOption)),n=l.extend({},t,n),r&&l.isFunction(r)&&(r(n,e),l(document).trigger(s))}).always(function(){i.find(".qor-media-loading").remove()}):r&&l.isFunction(r)&&(r(n,e),l(document).trigger(s)),!1},submit:function(e){var i,t=e.target,n=l(t),o=this,r=n.find(":submit"),s=l(c.$formLoading),a=this.options.onSubmit;l(document).trigger("selectcoreBeforeSend.qor.selectcore"),n.find(".qor-fieldset--new").remove(),d&&(e.preventDefault(),l.ajax(n.prop("action"),{method:n.prop("method"),data:new d(t),dataType:"json",processData:!1,contentType:!1,beforeSend:function(){l(".qor-submit-loading").remove(),s.appendTo(r.prop("disabled",!0).closest(".qor-form__actions")).trigger("enable.qor.material")},success:function(t){t.MediaOption&&(t.MediaOption=JSON.parse(t.MediaOption)),(i=t).primaryKey=i.ID,l(".qor-error").remove(),a&&l.isFunction(a)?(a(i,e),l(document).trigger("afterSubmitted.qor.selectcore")):o.refresh()},error:function(t){c.handleAjaxError(t)},complete:function(){r.prop("disabled",!1)}}))},refresh:function(){setTimeout(function(){window.location.reload()},350)},destroy:function(){this.unbind()}},r.plugin=function(n){return this.each(function(){var t,e=l(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new r(this,n))}"string"==typeof n&&l.isFunction(t=i[n])&&t.apply(i)})},l.fn.qorSelectCore=r.plugin,r}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(s){var i=s("body"),t=s(document),a=window.Mustache,o="qor.selectone",n="click."+o,r="enable."+o,e="reload.qor.bottomsheets",l=".qor-selected-many__remove",d=".qor-selected-many__undo",c="qor-selected-many__deleted",u=".qor-field__selectmany",h="is_selected",f="qor-bottomsheets__select-many";function p(t,e){this.$element=s(t),this.options=s.extend({},p.DEFAULTS,s.isPlainObject(e)&&e),this.init()}return p.prototype={constructor:p,init:function(){this.bind()},bind:function(){t.on(e,".".concat(f),this.reloadData.bind(this)),this.$element.on(n,l,this.clearSelect.bind(this)).on(n,'[data-select-modal="many"]',this.openBottomSheets.bind(this)).on(n,d,this.undoDelete.bind(this))},unbind:function(){t.off(n,'[data-select-modal="many"]').off(e,".".concat(f)),this.$element.off(n,l).off(n,d)},clearSelect:function(t){var e=s(t.target),t=e.closest(u);return e.closest("[data-primary-key]").addClass(c),this.updateSelectInputData(t),!1},undoDelete:function(t){var e=s(t.target),t=e.closest(u);return e.closest("[data-primary-key]").removeClass(c),this.updateSelectInputData(t),!1},openBottomSheets:function(t){var e=s(t.target),t=e.data();this.BottomSheets=i.data("qor.bottomsheets"),this.bottomsheetsData=t,this.$selector=t.selectId?s(t.selectId):e.closest(u).find("select"),this.$selectFeild=this.$selector.closest(u).find(".qor-field__selected-many"),this.SELECT_MANY_SELECTED_ICON=s('[name="select-many-selected-icon"]').html(),this.SELECT_MANY_UNSELECTED_ICON=s('[name="select-many-unselected-icon"]').html(),this.SELECT_MANY_HINT=s('[name="select-many-hint"]').html(),this.SELECT_MANY_TEMPLATE=s('[name="select-many-template"]').html(),t.url=t.selectListingUrl,t.selectDefaultCreating&&(t.url=t.selectCreatingUrl),this.BottomSheets.open(t,this.handleSelectMany.bind(this))},reloadData:function(){this.initItems()},renderSelectMany:function(t){return a.render(this.SELECT_MANY_TEMPLATE,t)},renderHint:function(t){return a.render(this.SELECT_MANY_HINT,t)},initItems:function(){var i,t=this.$bottomsheets.find("tbody tr"),n=this.SELECT_MANY_SELECTED_ICON,o=this.SELECT_MANY_UNSELECTED_ICON,r=[];this.$selectFeild.find("[data-primary-key]").not("."+c).each(function(){r.push(s(this).data().primaryKey)}),t.each(function(){var t=s(this),e=t.find("td:first");i=t.data().primaryKey,"-1"!=r.indexOf(i)?(t.addClass(h),e.append(n)):e.append(o)}),this.updateHint(this.getSelectedItemData())},getSelectedItemData:function(){return{selectedNum:this.$selectFeild.find("[data-primary-key]").not("."+c).length}},updateHint:function(t){s.extend(t,this.bottomsheetsData),t=this.renderHint(t),this.$bottomsheets.find(".qor-selectmany__hint").remove(),this.$bottomsheets.find(".qor-page__body").before(t)},updateSelectInputData:function(t){var e,i,n=(t||this.$selectFeild).find("[data-primary-key]").not("."+c),o=t?t.find(".qor-field__selectmany-input"):this.$selector,r=o.find("option");r.prop("selected",!1),n.each(function(){i=s(this).data().primaryKey,(e=r.filter('[value="'+i+'"]')).length||(i={primaryKey:i,displayName:""},e=s(a.render(p.SELECT_MANY_OPTION_TEMPLATE,i)),o.append(e)),e.prop("selected",!0)})},changeIcon:function(t,e){t.find(".qor-select__select-icon").remove(),t.find("td:first").prepend(e)},removeItem:function(t){var e=t.primaryKey;this.$selectFeild.find('[data-primary-key="'+e+'"]').find(l).click(),this.changeIcon(t.$clickElement,this.SELECT_MANY_UNSELECTED_ICON)},addItem:function(t,e){var i=this.renderSelectMany(t),n=this.$selectFeild.find('[data-primary-key="'+t.primaryKey+'"]');return n.length?n.hasClass(c)?(n.removeClass(c),this.updateSelectInputData(),void this.changeIcon(t.$clickElement,this.SELECT_MANY_SELECTED_ICON)):void 0:(this.$selectFeild.append(i),e?((e=s(a.render(p.SELECT_MANY_OPTION_TEMPLATE,t))).appendTo(this.$selector),e.prop("selected",!0),this.$bottomsheets.remove(),void(s(".qor-bottomsheets").is(":visible")||s("body").removeClass("qor-bottomsheets-open"))):void this.changeIcon(t.$clickElement,this.SELECT_MANY_SELECTED_ICON))},handleSelectMany:function(t){var e={onSelect:this.onSelectResults.bind(this),onSubmit:this.onSubmitResults.bind(this)};t.qorSelectCore(e).addClass(f),t.on(n,".qor-selectmany__selectall",this.handleSelectAll.bind(this)),this.$bottomsheets=t,this.initItems()},handleSelectAll:function(){var t=this.$bottomsheets.find(".qor-table tbody tr"),e=t.not(".is_selected");(e.length?e:t).click()},onSelectResults:function(t){this.handleResults(t)},onSubmitResults:function(t){this.handleResults(t,!0)},handleResults:function(t,e){t.displayName=t.Text||t.Name||t.Title||t.Code||t[Object.keys(t)[0]],t.displayName=t.displayName.escapeSymbol(),e?this.addItem(t,!0):((e=t.$clickElement).toggleClass(h),e.hasClass(h)?this.addItem(t):this.removeItem(t),this.updateHint(this.getSelectedItemData()),this.updateSelectInputData())},destroy:function(){this.unbind(),this.$element.removeData(o)}},p.SELECT_MANY_OPTION_TEMPLATE='',p.plugin=function(n){return this.each(function(){var t,e=s(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new p(this,n))}"string"==typeof n&&s.isFunction(t=i[n])&&t.apply(i)})},s(function(){var e='[data-toggle="qor.selectmany"]';s(document).on("disable.qor.selectone",function(t){p.plugin.call(s(e,t.target),"destroy")}).on(r,function(t){p.plugin.call(s(e,t.target))}).triggerHandler(r)}),p}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(r){var i=r("body"),t=r(document),s=window.Mustache,o="qor.selectone",e="click."+o,n="enable."+o,a="reload.qor.bottomsheets",l=".qor-selected__remove",d=".qor-selected__change",c=".qor-field__selected",u=".qor-field__selectone-input",h=".qor-field__selectone-trigger",f=".qor-field__selectone",p="qor-bottomsheets__select-one";function m(t,e){this.$element=r(t),this.options=r.extend({},m.DEFAULTS,r.isPlainObject(e)&&e),this.init()}return m.prototype={constructor:m,init:function(){this.bind()},bind:function(){t.on(a,".".concat(p),this.reloadData.bind(this)),this.$element.on(e,l,this.clearSelect.bind(this)).on(e,"[data-selectone-url]",this.openBottomSheets.bind(this)).on(e,d,this.changeSelect)},unbind:function(){t.off(e,"[data-selectone-url]").off(a,".".concat(p)),this.$element.off(e,l).off(e,d)},clearSelect:function(t){t=r(t.target).closest(f);return t.find(c).remove(),t.find(u).html(""),t.find(u)[0].value="",t.find(h).show(),t.trigger("qor.selectone.unselected"),!1},changeSelect:function(){r(this).closest(f).find(h).trigger("click")},openBottomSheets:function(t){var e=r(t.target),t=e.data();this.BottomSheets=i.data("qor.bottomsheets"),this.$parent=e.closest(f),t.url=t.selectoneUrl,this.SELECT_ONE_SELECTED_ICON=r('[name="select-one-selected-icon"]').html(),this.BottomSheets.open(t,this.handleSelectOne.bind(this))},initItem:function(){var t,e=this.$parent.find(c);e.length&&(t=e.data().primaryKey)&&this.$bottomsheets.find('tr[data-primary-key="'+t+'"]').addClass("is_selected").find("td:first").append(this.SELECT_ONE_SELECTED_ICON)},reloadData:function(){this.initItem()},renderSelectOne:function(t){return s.render(r('[name="select-one-selected-template"]').html(),t)},handleSelectOne:function(t){var e={onSelect:this.onSelectResults.bind(this),onSubmit:this.onSubmitResults.bind(this)};t.qorSelectCore(e).addClass(p),this.$bottomsheets=t,this.initItem()},onSelectResults:function(t){this.handleResults(t)},onSubmitResults:function(t){this.handleResults(t,!0)},handleResults:function(t){var e,i=this.$parent,n=i.find("select"),o=i.find(c);t.displayName=t.Text||t.Name||t.Title||t.Code||t[Object.keys(t)[0]],t.selectoneValue=t.primaryKey||t.ID,t.displayName=t.displayName.escapeSymbol(),n.length&&(e=this.renderSelectOne(t),o.length&&o.remove(),i.prepend(e),i.find(h).hide(),n.html(s.render(m.SELECT_ONE_OPTION_TEMPLATE,t)),n[0].value=t.primaryKey||t.ID,i.trigger("qor.selectone.selected",[t]),this.$bottomsheets.qorSelectCore("destroy").remove(),r(".qor-bottomsheets").is(":visible")||r("body").removeClass("qor-bottomsheets-open"))},destroy:function(){this.unbind(),this.$element.removeData(o)}},m.SELECT_ONE_OPTION_TEMPLATE='',m.plugin=function(n){return this.each(function(){var t,e=r(this),i=e.data(o);if(!i){if(/destroy/.test(n))return;e.data(o,i=new m(this,n))}"string"==typeof n&&r.isFunction(t=i[n])&&t.apply(i)})},r(function(){var e='[data-toggle="qor.selectone"]';r(document).on("disable.qor.selectone",function(t){m.plugin.call(r(e,t.target),"destroy")}).on(n,function(t){m.plugin.call(r(e,t.target))}).triggerHandler(n)}),m}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(l){var t=l(document),r="qor.selector",i="enable."+r,e="click."+r,d="selected",c="disabled",s="clearable",a="."+d,u=".qor-selector-toggle",h=".qor-selector-label",f=".qor-selector-menu",p=".qor-bottomsheets";function m(t,e){this.options=e,this.$element=l(t),this.init()}return m.prototype={constructor:m,init:function(){var t=this.$element;this.placeholder=t.attr("placeholder")||t.attr("name")||"Select",this.build()},build:function(){var t=this.$element,e=l(m.TEMPLATE),i=this.options.aligned+"-aligned",s={},n=t.data(),o=n.hover,a=t.attr("name");this.isBottom="bottom"==n.position,o&&e.addClass("hover"),e.addClass(i).find(f).html(function(){var r=[];return t.children().each(function(){var t=l(this),e=t.attr("selected"),i=t.attr("disabled"),n=t.attr("value"),o=t.text(),t=[];e&&(t.push(d),s.value=n,s.label=o,s.paramName=a),i&&t.push(c),r.push("'+o+"")}),r.join("")}),this.$selector=e,t.hide().after(e),e.find(u).data("paramName",a),this.pick(s,!0),this.bind()},unbuild:function(){this.unbind(),this.$selector.remove(),this.$element.show()},bind:function(){this.$selector.on(e,l.proxy(this.click,this)),t.on(e,l.proxy(this.close,this))},unbind:function(){this.$selector.off(e,this.click)},click:function(t){var e=l(t.target);t.stopPropagation(),e.is(".qor-selector-clear")?this.clear():e.is("li")?(e.hasClass(d)||e.hasClass(c)||this.pick(e.data()),this.close()):e.closest(u).length&&this.open()},pick:function(t,e){var i=this.$selector,n=!!t.value,o=this.$element;i.find(u).toggleClass("active",n).toggleClass(s,n&&this.options.clearable).find(h).text(t.label||this.placeholder),e||(i.find(f).children('[data-value="'+t.value+'"]').addClass(d).siblings(a).removeClass(d),o.val(t.value),o.closest(p).length&&!o.closest('[data-toggle="qor.filter"]').length?l(p).trigger("selectorChanged.qor.selector",[t.value,t.paramName]):o.trigger("change"))},clear:function(){var t=this.$element;this.$selector.find(u).removeClass("active").removeClass(s).find(h).text(this.placeholder).end().end().find(f).children(a).removeClass(d),t.val("").trigger("change")},open:function(){t.triggerHandler(e),l(".qor-filter__dropdown").hide(),this.$selector.addClass("open"),this.isBottom&&this.$selector.addClass("bottom")},close:function(){this.$selector.removeClass("open"),this.isBottom&&this.$selector.removeClass("bottom")},destroy:function(){this.unbuild(),this.$element.removeData(r)}},m.DEFAULTS={aligned:"left",clearable:!1},m.TEMPLATE='',m.plugin=function(o){return this.each(function(){var t,e,i=l(this),n=i.data(r);if(!n){if(/destroy/.test(o))return;t=l.extend({},m.DEFAULTS,i.data(),"object"===_typeof(o)&&o),i.data(r,n=new m(this,t))}"string"==typeof o&&l.isFunction(e=n[o])&&e.apply(n)})},l(function(){var e='[data-toggle="qor.selector"]';l(document).on("disable.qor.selector",function(t){m.plugin.call(l(e,t.target),"destroy")}).on(i,function(t){m.plugin.call(l(e,t.target))}).triggerHandler(i)}),m}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(p){var t=p(document),l=window.FormData,m=window.QOR_Translations,o=window._,d=window.QOR,r="qor.slideout",e="keyup."+r,i="click."+r,n="submit."+r,y="shown."+r,g="hidden."+r,s="transitionend",a="qor-slideout-open",c="qor-slideout-mini",u="is-shown",h="is-slided",b=".qor-body__loading";function f(t,e){var i=[],n=e?"src":"href";return t.each(function(){i.push(p(this).attr(n))}),o.uniq(i)}function v(t,e,i){for(var n=0,o=0,r=t.length;o\s]+))?)+\s*|\s*)>/g))for(var r=0;r[\s\S]*<\s*\/body\s*>/gi);r&&(r=r.join("").replace(/<\s*body/gi," thead > tr > th",o.proxy(this.sort,this))},unbind:function(){this.$element.off(e,this.sort)},sort:function(t){var e=o(t.currentTarget).data("orderBy"),t=n.search,i="order_by="+e;e&&(/order_by/.test(t)?t=t.replace(/order_by(=\w+)?/,function(){return i}):t+=-1this.slideoutWidth&&this.$element.find(d).append(f.ARROW_RIGHT)},scrollTabLeft:function(t){t.stopPropagation();var e=o(d),i=e.scrollLeft(),t=i-this.slideoutWidth;0=i&&o(c).hide()}),o(u).length||this.$element.find(d).prepend(f.ARROW_LEFT))},switchTab:function(t){var e=o(t.target),i=this.$element,t=e.data(),n=r.data().tabScopeActive;if(o(".qor-slideout").is(":visible"))return e.hasClass(h)||(i.find(a).removeClass(h),e.addClass(h),o.ajax(t.tabUrl,{method:"GET",dataType:"html",processData:!1,contentType:!1,beforeSend:function(){o(".qor-layout__tab-spinner").remove();o(l).hide().before('
                  '),window.componentHandler.upgradeElement(o(".qor-layout__tab-spinner")[0])},success:function(t){o(".qor-layout__tab-spinner").remove(),r.data("tabScopeActive",e.data("name"));t=o(t).find(l).html();o(l).show().html(t).trigger("enable")},error:function(){o(".qor-layout__tab-spinner").remove(),r.data("tabScopeActive",n)}})),!1},destroy:function(){this.unbind(),r.removeData("tabScopeActive")}},f.ARROW_RIGHT='',f.ARROW_LEFT='',f.DEFAULTS={},f.plugin=function(n){return this.each(function(){var t,e=o(this),i=e.data(s);if(!i){if(/destroy/.test(n))return;e.data(s,i=new f(this,n))}"string"==typeof n&&o.isFunction(t=i[n])&&t.apply(i)})},o(function(){var e='[data-toggle="qor.tab"]';o(document).on("disable.qor.tabbar",function(t){f.plugin.call(o(e,t.target),"destroy")}).on(t,function(t){f.plugin.call(o(e,t.target))}).triggerHandler(t)}),f}),function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery")):t(jQuery)}(function(r){var s="qor.timepicker",t="enable."+s,e="click."+s,i="focus."+s,n="keydown."+s,o="blur."+s,a="selectTime."+s,l="[data-picker-type]";function d(t,e){this.$element=r(t),this.options=r.extend(!0,{},d.DEFAULTS,r.isPlainObject(e)&&e),this.formatDate=null,this.pickerData=this.$element.data(),this.parent=this.$element.closest(l),this.isDateTimePicker="datetime"==this.parent.data("picker-type"),this.$targetInput=this.parent.find(this.pickerData.targetInput||(this.isDateTimePicker?".qor-datetimepicker__input":".qor-datepicker__input")),this.init()}return d.prototype={init:function(){var t,e,i;this.$targetInput.is(":disabled")?this.$element.remove():(this.bind(),this.oldValue=this.$targetInput.val(),e=(e=(t=new Date).getMonth()+1)<8?"0"+e:e,i=(i=t.getDate())<10?"0"+i:i,this.dateValueNow=t.getFullYear()+"-"+e+"-"+i)},bind:function(){this.isDateTimePicker&&this.$targetInput.qorTimepicker({timeFormat:"H:i",showOn:null,wrapHours:!1,scrollDefault:"now"}).on(a,r.proxy(this.changeTime,this)).on(o,r.proxy(this.blur,this)).on(i,r.proxy(this.focus,this)).on(n,r.proxy(this.keydown,this)),this.$element.on(e,r.proxy(this.show,this))},unbind:function(){this.$element.off(e,this.show),this.isDateTimePicker&&this.$targetInput.off(a,this.changeTime).off(o,this.blur).off(i,this.focus).off(n,this.keydown)},focus:function(){},blur:function(){var t,e,i,n,o,r,s=this.$targetInput.val(),a=s.split(" "),l=a.length,d=/\d{1,2}:\d{1,2}/,c=/^\d{4}-\d{1,2}-\d{1,2}/;if(s){if(1==l)c.test(a[0])&&(e=a[0],i="00:00"),d.test(a[0])&&(e=this.dateValueNow,i=a[0]);else for(var u=0;u