-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add note type for activities #1103
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -540,3 +540,110 @@ function posterHandlers() { | |
$(this).find('button[type="submit"].wait').addClass("disabled"); | ||
}); | ||
} | ||
|
||
$(document).on("click", "#add-notes-option", function () { | ||
var optionIndex = $("#notes-options .col-md-6").length; | ||
var optionHtml = | ||
'<div class="col-md-6">' + | ||
'<div class="input-group mb-3">' + | ||
'<input class="form-control" type="text" name="activity[notes_options][]">' + | ||
'<div class="input-group-append">' + | ||
'<button class="btn btn-sm btn-danger delete-option" type="button">' + | ||
'<i class="fa fa-fw fa-minus"></i>' + | ||
"</button>" + | ||
"</div>" + | ||
"</div>" + | ||
"</div>"; | ||
$("#notes-options").append(optionHtml); | ||
}); | ||
|
||
$(document).on("click", ".delete-option", function () { | ||
$(this).closest(".col-md-6").remove(); | ||
}); | ||
|
||
$(document).on("change", "#activity_notes_input_type", function () { | ||
var notesInputType = $(this).val(); | ||
var notesContainer = $("#notes-container"); | ||
|
||
if (notesInputType === "text") { | ||
var notesValue = $("#notes-options input") | ||
.map(function () { | ||
return $(this).val(); | ||
}) | ||
.get() | ||
.join("\n"); | ||
notesContainer.html( | ||
'<textarea class="form-control" id="activity_notes" name="activity[notes]">' + | ||
notesValue + | ||
"</textarea>", | ||
); | ||
} else { | ||
var optionsHtml = ""; | ||
var notesValue = $("#activity_notes").val(); | ||
var optionsArray = []; | ||
|
||
if (notesValue && notesValue.trim() !== "") { | ||
optionsArray = notesValue.split("\n"); | ||
} | ||
|
||
if (optionsArray.length > 0) { | ||
var titleValue = optionsArray[0]; | ||
optionsHtml += | ||
'<div class="col-md-12">' + | ||
'<div class="input-group mb-3">' + | ||
'<span class="input-group-text">Title</span>' + | ||
'<input class="form-control" type="text" name="activity[notes_options][]" value="' + | ||
titleValue + | ||
'">' + | ||
"</div>" + | ||
"</div>"; | ||
|
||
optionsArray.slice(1).forEach(function (optionValue) { | ||
optionsHtml += | ||
'<div class="col-md-6">' + | ||
'<div class="input-group mb-3">' + | ||
'<input class="form-control" type="text" name="activity[notes_options][]" value="' + | ||
optionValue + | ||
'">' + | ||
'<div class="input-group-append">' + | ||
'<button class="btn btn-sm btn-danger delete-option" type="button">' + | ||
'<i class="fa fa-fw fa-minus"></i>' + | ||
"</button>" + | ||
"</div>" + | ||
"</div>" + | ||
"</div>"; | ||
}); | ||
} else { | ||
optionsHtml += | ||
'<div class="col-md-12">' + | ||
'<div class="input-group mb-3">' + | ||
'<span class="input-group-text">Title</span>' + | ||
'<input class="form-control" type="text" name="activity[notes_options][]">' + | ||
"</div>" + | ||
"</div>" + | ||
'<div class="col-md-6">' + | ||
'<div class="input-group mb-3">' + | ||
'<input class="form-control" type="text" name="activity[notes_options][]">' + | ||
'<div class="input-group-append">' + | ||
'<button class="btn btn-sm btn-danger delete-option" type="button">' + | ||
'<i class="fa fa-fw fa-minus"></i>' + | ||
"</button>" + | ||
"</div>" + | ||
"</div>" + | ||
"</div>"; | ||
Comment on lines
+618
to
+633
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add some indentation here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be preferable, however, an even better approach would be to eliminate the need for generating HTML within the JavaScript code altogether. Make a HAML partial file as a template for the option menu. this is not required, but would prevent coding twice when changing the UI |
||
} | ||
|
||
notesContainer.html( | ||
'<div class="row" id="notes-options">' + | ||
optionsHtml + | ||
"</div>" + | ||
'<div class="row">' + | ||
'<div class="col-md-12">' + | ||
'<button class="btn btn-primary" id="add-notes-option" type="button">' + | ||
'<i class="fa fa-fw fa-plus"></i> Add Option' + | ||
"</button>" + | ||
"</div>" + | ||
"</div>", | ||
); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,19 @@ export class Activity { | |
has_notes() { | ||
return this.notes.length !== 0; | ||
} | ||
|
||
has_notes_checkboxes() { | ||
return find_in_object(this.notes, function (note) { | ||
return note.type === "checkbox"; | ||
}); | ||
} | ||
|
||
has_notes_radio_buttons() { | ||
return find_in_object(this.notes, function (note) { | ||
return note.type === "radio"; | ||
}); | ||
} | ||
|
||
are_notes_filled() { | ||
return $.trim(this.notes.val()).length > 0; | ||
} | ||
|
@@ -184,12 +197,29 @@ Object.defineProperties(Activity.prototype, { | |
*/ | ||
value: function (method) { | ||
var activity = this; | ||
var par_notes; | ||
var notes = []; | ||
console.log(activity.has_notes_checkboxes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the console log be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
if (activity.has_notes_checkboxes()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also know little JS, however, does it not have switch cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way to define the enum in 1 place like in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think so, atleast not trivally |
||
console.log(this.notes.find(":checked")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove log or cache |
||
this.notes.each(function () { | ||
if (this.checked) { | ||
notes.push(this.value); | ||
} | ||
}); | ||
par_notes = notes.join(", "); | ||
} else if (activity.has_notes_radio_buttons()) { | ||
par_notes = this.notes.find(":checked").val(); | ||
} else { | ||
par_notes = this.notes.val(); | ||
} | ||
|
||
var request = $.ajax({ | ||
url: "/activities/" + activity.id + "/participants", | ||
type: method, | ||
data: { | ||
authenticity_token: this.token, | ||
par_notes: this.notes.val(), | ||
par_notes: par_notes, | ||
}, | ||
}) | ||
.done(function (response) { | ||
|
@@ -374,7 +404,7 @@ Object.defineProperties( | |
}, | ||
|
||
notes: function () { | ||
return this.panel.find(".notes"); | ||
return this.panel.find(".notes"); // .find function returns a jQuery object with the found elements | ||
}, | ||
|
||
notes_mandatory: function () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did the linter add a double space? Linters 🤷