Skip to content

Commit

Permalink
Modal added
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow243 committed Oct 7, 2024
1 parent 586285d commit c252dd8
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
71 changes: 70 additions & 1 deletion modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,76 @@ class Hm_Output_content_section_end extends Hm_Output_Module {
* Closes the main tag opened in Hm_Output_content_section_start
*/
protected function output() {
return '</div></main>';
$share_folder_modal = '<div class="modal fade" id="shareFolderModal" tabindex="-1" aria-labelledby="shareFolderModalLabel" aria-hidden="true">';
$share_folder_modal .= '<div class="modal-dialog">';
$share_folder_modal .= '<div class="modal-content">';
$share_folder_modal .= '<div class="modal-header">';
$share_folder_modal .= '<h5 class="modal-title" id="shareFolderModalLabel">Edit Permissions</h5>';
$share_folder_modal .= '<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>';
$share_folder_modal .= '</div>';

$share_folder_modal .= '<div class="modal-body">';
$share_folder_modal .= '<form id="shareForm" action="" method="POST">';

$share_folder_modal .= '<input type="hidden" name="server_id" id="server_id" value="">';
$share_folder_modal .= '<input type="hidden" name="folder_uid" id="folder_uid" value="">';

$share_folder_modal .= '<div class="mb-3 row">';
$share_folder_modal .= '<div class="col-lg-4 col-md-4 col-sm-12">';
$share_folder_modal .= '<label class="form-label">Identifier</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '<div class="col-lg-8 col-md-8 col-sm-12">';
$share_folder_modal .= '<div>';
$share_folder_modal .= '<input type="radio" name="identifier" value="user" id="identifierUser" checked>';
$share_folder_modal .= '<label for="identifierUser">User:</label>';
$share_folder_modal .= '<input type="text" class="form-control d-inline-block" id="email" name="email" required placeholder="Enter email">';
$share_folder_modal .= '</div>';
$share_folder_modal .= '<div>';
$share_folder_modal .= '<input type="radio" name="identifier" value="all" id="identifierAll">';
$share_folder_modal .= '<label for="identifierAll">All users (anyone)</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '<div>';
$share_folder_modal .= '<input type="radio" name="identifier" value="guests" id="identifierGuests">';
$share_folder_modal .= '<label for="identifierGuests">Guests (anonymous)</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '</div>';

$share_folder_modal .= '<div class="mb-3 row">';
$share_folder_modal .= '<div class="col-lg-4 col-md-4 col-sm-12">';
$share_folder_modal .= '<label class="form-label">Access Rights</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '<div class="col-lg-8 col-md-8 col-sm-12">';
$share_folder_modal .= '<div>';
$share_folder_modal .= '<input type="checkbox" name="access_read" id="accessRead" checked>';
$share_folder_modal .= '<label for="accessRead">Read</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '<div>';
$share_folder_modal .= '<input type="checkbox" name="access_write" id="accessWrite">';
$share_folder_modal .= '<label for="accessWrite">Write</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '<div>';
$share_folder_modal .= '<input type="checkbox" name="access_delete" id="accessDelete">';
$share_folder_modal .= '<label for="accessDelete">Delete</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '<div>';
$share_folder_modal .= '<input type="checkbox" name="access_other" id="accessOther">';
$share_folder_modal .= '<label for="accessOther">Other</label>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '</div>';

$share_folder_modal .= '<div class="modal-footer">';
$share_folder_modal .= '<button type="submit" class="btn btn-primary">Save</button>';
$share_folder_modal .= '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>';
$share_folder_modal .= '</div>';

$share_folder_modal .= '</form>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '</div>';
$share_folder_modal .= '</div>';
return '</div></main>'.$share_folder_modal;
}
}

Expand Down
12 changes: 12 additions & 0 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ $.fn.fadeOutAndRemove = function(timeout = 600) {
return this;
};

$.fn.modal = function(action) {
const modalElement = this[0];
if (modalElement) {
const modal = new bootstrap.Modal(modalElement);
if (action === 'show') {
modal.show();
} else if (action === 'hide') {
modal.hide();
}
}
};

/* swipe event handler */
var swipe_event = function(el, callback, direction) {
var start_x, start_y, dist_x, dist_y, threshold = 150, restraint = 100,
Expand Down
2 changes: 1 addition & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function format_imap_folder_section($folders, $id, $output_mod, $with_input = fa
}
$results .= '<span class="unread_count unread_imap_'.$id.'_'.$output_mod->html_safe($folder_name).'"></span>';
if($can_share_folders) {
$results .= '<div class="dropdown"><a href="#" class="action-link" data-bs-toggle="dropdown" aria-expanded="false"><i class="icon bi bi-three-dots-vertical"></i></a><ul class="dropdown-menu dropdown-menu"><li><a href="#" class="dropdown-item"><i class="icon bi bi-share"></i> Share</a></ul></div>';
$results .= '<div class="dropdown"><a href="#" class="action-link" data-bs-toggle="dropdown" aria-expanded="false"><i class="icon bi bi-three-dots-vertical"></i></a><ul class="dropdown-menu dropdown-menu"><li data-id="'.$id.'" data-folder="'.$output_mod->html_safe($folder_name).'"><a href="#" class="dropdown-item share"><i class="icon bi bi-share"></i> Share</a></ul></div>';
}
$results .= '</li>';
}
Expand Down
21 changes: 21 additions & 0 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1424,3 +1424,24 @@ $('.screen-email-like').on("click", function() {
});
add_email_in_contact_trusted(list_email); return false;
});

$(document).on('click', '[data-bs-dismiss="modal"]', function() {
$('#shareFolderModal').modal('hide');
});

$(document).on('click', 'a.dropdown-item.share', function(e) {
e.preventDefault();
console.log("Event", e)
const listItem = e.target.closest('li');
if(listItem) {
listItem.getAttribute('data-id');
const uid = listItem.getAttribute('data-id');
const folder = listItem.getAttribute('data-folder');
//must send a request to get the data using imap_getacl function

//then populate the modal with the data
$('#server_id').val(uid);
$('#folder_uid').val(folder);
$('#shareFolderModal').modal('show');
}
});
2 changes: 1 addition & 1 deletion tests/phpunit/modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ public function test_content_section_start() {
public function test_content_section_end() {
$test = new Output_Test('content_section_end', 'core');
$res = $test->run();
$this->assertEquals(array('</div></main>'), $res->output_response);
$this->assertEquals(array('</div></main><div class="modal fade" id="shareFolderModal" tabindex="-1" aria-labelledby="shareFolderModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="shareFolderModalLabel">Edit Permissions</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><form id="shareForm" action="" method="POST"><input type="hidden" name="server_id" id="server_id" value=""><input type="hidden" name="folder_uid" id="folder_uid" value=""><div class="mb-3 row"><div class="col-lg-4 col-md-4 col-sm-12"><label class="form-label">Identifier</label></div><div class="col-lg-8 col-md-8 col-sm-12"><div><input type="radio" name="identifier" value="user" id="identifierUser" checked><label for="identifierUser">User:</label><input type="text" class="form-control d-inline-block" id="email" name="email" required placeholder="Enter email"></div><div><input type="radio" name="identifier" value="all" id="identifierAll"><label for="identifierAll">All users (anyone)</label></div><div><input type="radio" name="identifier" value="guests" id="identifierGuests"><label for="identifierGuests">Guests (anonymous)</label></div></div></div><div class="mb-3 row"><div class="col-lg-4 col-md-4 col-sm-12"><label class="form-label">Access Rights</label></div><div class="col-lg-8 col-md-8 col-sm-12"><div><input type="checkbox" name="access_read" id="accessRead" checked><label for="accessRead">Read</label></div><div><input type="checkbox" name="access_write" id="accessWrite"><label for="accessWrite">Write</label></div><div><input type="checkbox" name="access_delete" id="accessDelete"><label for="accessDelete">Delete</label></div><div><input type="checkbox" name="access_other" id="accessOther"><label for="accessOther">Other</label></div></div></div><div class="modal-footer"><button type="submit" class="btn btn-primary">Save</button><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button></div></form></div></div></div></div>'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand Down

0 comments on commit c252dd8

Please sign in to comment.