mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Can create a new choice for the survey
This commit is contained in:
parent
5086f45cc1
commit
e0d69ab504
@ -34,7 +34,18 @@ class SurveyHelper {
|
|||||||
.isOK;
|
.isOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new choice in a survey
|
||||||
|
///
|
||||||
|
/// Throws in case of failure
|
||||||
|
static Future<void> createNewChoice(int postID, String newChoice) async =>
|
||||||
|
await APIRequest.withLogin("surveys/create_new_choice")
|
||||||
|
.addInt("postID", postID)
|
||||||
|
.addString("choice", newChoice)
|
||||||
|
.execWithThrow();
|
||||||
|
|
||||||
/// Prevent new choices from being created on a survey
|
/// Prevent new choices from being created on a survey
|
||||||
|
///
|
||||||
|
/// Throws in case of failure
|
||||||
static Future<void> blockNewChoicesCreation(int postID) async =>
|
static Future<void> blockNewChoicesCreation(int postID) async =>
|
||||||
await APIRequest.withLogin("surveys/block_new_choices_creation")
|
await APIRequest.withLogin("surveys/block_new_choices_creation")
|
||||||
.addInt("postID", postID)
|
.addInt("postID", postID)
|
||||||
|
@ -44,6 +44,9 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
|
|||||||
),
|
),
|
||||||
_buildUserResponse(),
|
_buildUserResponse(),
|
||||||
|
|
||||||
|
// Offer the user to create a new choice on the survey, if possible
|
||||||
|
survey.allowNewChoicesCreation ? _buildNewChoiceLink() : Container(),
|
||||||
|
|
||||||
// Offer to block the creation of new responses, if possible
|
// Offer to block the creation of new responses, if possible
|
||||||
survey.canBlockNewChoicesCreation
|
survey.canBlockNewChoicesCreation
|
||||||
? _buildBlockNewResponsesLink()
|
? _buildBlockNewResponsesLink()
|
||||||
@ -116,9 +119,20 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildBlockNewResponsesLink() => InkWell(
|
Widget _buildNewChoiceLink() => Padding(
|
||||||
onTap: _blockNewChoices,
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(tr("Block the creation of new responses")),
|
child: InkWell(
|
||||||
|
onTap: _createNewChoices,
|
||||||
|
child: Text(tr("Create a new choice")),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _buildBlockNewResponsesLink() => Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: _blockNewChoices,
|
||||||
|
child: Text(tr("Block the creation of new responses")),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _buildChart() {
|
Widget _buildChart() {
|
||||||
@ -146,6 +160,30 @@ class _SurveyWidgetState extends SafeState<SurveyWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new choice
|
||||||
|
void _createNewChoices() async {
|
||||||
|
try {
|
||||||
|
final newChoice = await askUserString(
|
||||||
|
context: context,
|
||||||
|
title: tr("New choice"),
|
||||||
|
message: tr("Please specify the new choice for the survey"),
|
||||||
|
defaultValue: "",
|
||||||
|
hint: tr("New choice..."),
|
||||||
|
maxLength: 50,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newChoice == null || newChoice.isEmpty) return;
|
||||||
|
|
||||||
|
await SurveyHelper.createNewChoice(survey.postID, newChoice);
|
||||||
|
|
||||||
|
// TODO : reload survey
|
||||||
|
} catch (e, s) {
|
||||||
|
print("Could not create new survey choice! $e\n$s");
|
||||||
|
showSimpleSnack(
|
||||||
|
context, tr("Could not create a new choice for this survey!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Block the creation of new choices on this survey
|
/// Block the creation of new choices on this survey
|
||||||
void _blockNewChoices() async {
|
void _blockNewChoices() async {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user