]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/event_edit.js
Merge pull request #10116 from mexon/mat/addon-console-command
[friendica.git] / view / theme / frio / js / event_edit.js
1 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
2 $(document).ready(function () {
3         // Go to the permissions tab if the checkbox is checked.
4         $("body")
5                 .on("click", "#id_share", function () {
6                         if ($("#id_share").is(":checked") && !$("#id_share").attr("disabled")) {
7                                 $("#acl-wrapper").show();
8                                 $("a#event-perms-lnk").parent("li").show();
9                                 toggleEventNav("a#event-perms-lnk");
10                                 eventAclActive();
11                         } else {
12                                 $("#acl-wrapper").hide();
13                                 $("a#event-perms-lnk").parent("li").hide();
14                         }
15                 })
16                 .trigger("change");
17
18         // Disable the finish time input if the user disable it.
19         $("body")
20                 .on("change", "#id_nofinish", function () {
21                         enableDisableFinishDate();
22                 })
23                 .trigger("change");
24
25         // JS for the permission section.
26         $("#contact_allow, #contact_deny, #group_allow, #group_deny")
27                 .change(function () {
28                         var selstr;
29                         $(
30                                 "#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected",
31                         ).each(function () {
32                                 selstr = $(this).html();
33                                 $("#jot-public").hide();
34                         });
35                         if (selstr == null) {
36                                 $("#jot-public").show();
37                         }
38                 })
39                 .trigger("change");
40
41         // Change the event nav menu.tabs on click.
42         $("body").on("click", "#event-nav > li > a", function (e) {
43                 e.preventDefault();
44                 toggleEventNav(this);
45         });
46
47         // This is experimental. We maybe can make use of it to inject
48         // some js code while the event modal opens.
49         //$('body').on('show.bs.modal', function () {
50         //      enableDisableFinishDate();
51         //});
52
53         // Clear some elements (e.g. the event-preview container) when
54         // selecting a event nav link so it don't appear more than once.
55         $("body").on("click", "#event-nav a", function (e) {
56                 $("#event-preview").empty();
57                 e.preventDefault();
58         });
59 });
60
61 // Load the html of the actual event and incect the output to the
62 // event-edit section.
63 function doEventPreview() {
64         $("#event-edit-preview").val(1);
65         $.post("events", $("#event-edit-form").serialize(), function (data) {
66                 $("#event-preview").append(data);
67         });
68         $("#event-edit-preview").val(0);
69 }
70
71 // The following functions show/hide the specific event-edit content
72 // in dependence of the selected nav.
73 function eventAclActive() {
74         $("#event-edit-wrapper, #event-preview, #event-desc-wrapper").hide();
75         $("#event-acl-wrapper").show();
76 }
77
78 function eventPreviewActive() {
79         $("#event-acl-wrapper, #event-edit-wrapper, #event-desc-wrapper").hide();
80         $("#event-preview").show();
81         doEventPreview();
82 }
83
84 function eventEditActive() {
85         $("#event-acl-wrapper, #event-preview, #event-desc-wrapper").hide();
86         $("#event-edit-wrapper").show();
87
88         // Make sure jot text does have really the active class (we do this because there are some
89         // other events which trigger jot text.
90         toggleEventNav($("#event-edit-lnk"));
91 }
92
93 function eventDescActive() {
94         $("#event-edit-wrapper, #event-preview, #event-acl-wrapper").hide();
95         $("#event-desc-wrapper").show();
96 }
97
98 // Give the active "event-nav" list element the class "active".
99 function toggleEventNav(elm) {
100         // Select all li of #event-nav and remove the active class.
101         $(elm).closest("#event-nav").children("li").removeClass("active");
102         // Add the active class to the parent of the link which was selected.
103         $(elm).parent("li").addClass("active");
104 }
105
106 // Disable the input for the finish date if it is not available.
107 function enableDisableFinishDate() {
108         if ($("#id_nofinish").is(":checked")) $("#id_finish_text").prop("disabled", true);
109         else $("#id_finish_text").prop("disabled", false);
110 }
111 // @license-end