Skip to content

Commit

Permalink
Get the day adding/removing working
Browse files Browse the repository at this point in the history
  • Loading branch information
V13Axel committed Oct 8, 2024
1 parent 7d41444 commit 87c6c20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 40 deletions.
8 changes: 5 additions & 3 deletions resources/js/calendar/calendar_global_week.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { do_error_check } from "./calendar_inputs_edit";
import { do_error_check, populate_first_day_select } from "./calendar_inputs_edit";
import { set_up_view_values } from "./calendar_inputs_view";

export default () => ({
Expand All @@ -12,7 +12,7 @@ export default () => ({
this.customWeekWarningCheck(static_data);
},
refreshWeekdays(static_data) {
this.weekdays = static_data.year_data.global_week;
this.weekdays = [...static_data.year_data.global_week];
this.deleting = -1;
},
customWeekWarningCheck(static_data) {
Expand All @@ -21,17 +21,19 @@ export default () => ({
},
addNewDay() {
window.static_data.year_data.global_week.push(this.new_weekday_name);
this.refreshWeekdays(window.static_data);

this.new_weekday_name = '';

set_up_view_values();
populate_first_day_select(window.static_data.year_data.first_day);
do_error_check();
},
removeWeekday(index) {
console.log("Removing " + index);

window.static_data.year_data.global_week.splice(index, 1);
this.weekdays.splice(index, 1);
this.refreshWeekdays(window.static_data);

this.deleting = -1;
do_error_check();
Expand Down
36 changes: 1 addition & 35 deletions resources/js/calendar/calendar_inputs_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export function set_up_edit_inputs() {
input_container = $('#input_container');
timespan_sortable = $('#timespan_sortable');
first_day = $('#first_day');
global_week_sortable = $('#global_week_sortable');
leap_day_list = $('#leap_day_list');
moon_list = $('#moon_list');
periodic_seasons_checkbox = $('#periodic_seasons_checkbox');
Expand Down Expand Up @@ -395,12 +394,6 @@ export function set_up_edit_inputs() {

/* ------------------- Layout callbacks ------------------- */

$('.add_inputs').keyup(function(e) {
if (e.keyCode == 13) {
$(this).find('.add').click();
}
});

$(document).on('change', '.week_day_name', function() {
populate_first_day_select(window.static_data.year_data.first_day);
});
Expand Down Expand Up @@ -2850,33 +2843,6 @@ function update_data(e) {
window.dispatchEvent(new CustomEvent('calendar-structure-changed'));
}

function add_weekday_to_sortable(parent, key, name) {
var element = [];

element.push("<div class='sortable-container list-group-item week_day'>");
element.push("<div class='main-container'>");
element.push("<div class='handle fa fa-bars'></div>");
element.push("<div class='name-container'>");
element.push(`<input type='text' class='form-control name-input small-input dynamic_input week_day_name' data='year_data.global_week' fc-index='${key}' tabindex='${(key + 1)}'/>`);
element.push("</div>");
element.push("<div class='remove-spacer'></div>");
element.push("</div>");
element.push("<div class='remove-container'>");
element.push("<div class='remove-container-text'>Are you sure you want to remove this?</div>");
element.push("<div class='btn_remove btn btn-danger fa fa-trash'></div>");
element.push("<div class='btn_cancel btn btn-danger fa fa-xmark'></div>");
element.push("<div class='btn_accept btn btn-success fa fa-check'></div>");
element.push("</div>");

element.push("</div>");

element = $(element.join(""))

element.find('.name-input').val(name);

parent.append(element);
}

function add_timespan_to_sortable(parent, key, data) {
if (key == 0) $('.timespan_sortable_header').removeClass('hidden');

Expand Down Expand Up @@ -4487,7 +4453,7 @@ function evaluate_remove_buttons() {
});
}

function populate_first_day_select(val) {
export function populate_first_day_select(val) {
var custom_week = false;
timespan_sortable.children().each(function() {
if ($(this).find('.unique-week-input').is(':checked')) {
Expand Down
5 changes: 3 additions & 2 deletions resources/views/components/weekdays-collapsible.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ class="wiki protip">

<div class='row no-gutters add_inputs global_week'>
<div class='col input-group'>
<input type='text' class='form-control' placeholder='Weekday name' x-model="new_weekday_name">
<input type='text' class='form-control' placeholder='Weekday name' x-model="new_weekday_name" @keyup.enter="addNewDay">

<div class="input-group-append">
<button type='button' class='btn btn-primary add'><i class="fa fa-plus"></i></button>
<button type='button' class='btn btn-primary' @click="addNewDay"><i class="fa fa-plus"></i></button>
</div>
</div>
</div>
Expand Down

0 comments on commit 87c6c20

Please sign in to comment.