Skip to content

Commit

Permalink
RocketChat#156 Prefill request creation form (RocketChat#157)
Browse files Browse the repository at this point in the history
* fixes RocketChat#156

- Pass topic as URL param (URL encoded) as `topic` or `expertise` (same effect)
- Title is focused if expertise is passed

* Allow pre-filling of title and question as well.

This way, fixes mrsimpson#20 : The consumer (e. g. the wiki page) can create a simple form an pass the content as parameter

* - Use the copied current() instead of the internal value
```
FlowRouter.current
ƒ () {                                                                               // 248
  // We can't trust outside, that's why we clone this                                                        …
```
- refactor query-selectors => reuse

* use FlowRouter API properly
  • Loading branch information
mrsimpson authored and ruKurz committed Dec 1, 2017
1 parent 29dd0a6 commit 6b71ca6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,39 @@ Template.AssistifyCreateRequest.events({

Template.AssistifyCreateRequest.onRendered(function() {
const instance = this;
this.find('input[name="expertise"]').focus();
this.ac.element = this.find('input[name="expertise"]');
this.ac.$element = $(this.ac.element);
this.ac.$element.on('autocompleteselect', function(e, {item}) {
const expertiseElement = this.find('input[name="expertise"]');
const titleElement = this.find('input[name="request_title"]');
const questionElement = this.find('input[name="first_question"]');

instance.ac.element = expertiseElement;
instance.ac.$element = $(instance.ac.element);
instance.ac.$element.on('autocompleteselect', function(e, {item}) {
instance.expertise.set(item.name);
$('input[name="expertise"]').val(item.name);
instance.debounceValidateExpertise(item.name);

return instance.find('.js-save-request').focus();
});

if (instance.requestTitle.get()) {
titleElement.value = instance.requestTitle.get();
}

if (instance.openingQuestion.get()) {
questionElement.value = instance.openingQuestion.get();
}

// strategy for setting the focus (yac!)
if (!expertiseElement.value) {
expertiseElement.focus();
} else if (!questionElement.value) {
questionElement.focus();
} else if (!titleElement.value) {
titleElement.focus();
} else {
questionElement.focus();
}

});

Template.AssistifyCreateRequest.onCreated(function() {
Expand Down Expand Up @@ -212,12 +235,6 @@ Template.AssistifyCreateRequest.onCreated(function() {
}
}, 500);

// instance.clearForm = function() {
// instance.requestRoomName.set('');
// instance.expertise.set('');
// instance.find('#expertise-search').value = '';
// };

this.ac = new AutoComplete({
selector: {
item: '.rc-popup-list__item',
Expand All @@ -242,4 +259,23 @@ Template.AssistifyCreateRequest.onCreated(function() {

});
this.ac.tmplInst = this;

//prefill form based on query parameters if passed
if (FlowRouter.current().queryParams) {
const expertise = FlowRouter.getQueryParam('topic') || FlowRouter.getQueryParam('expertise');
if (expertise) {
instance.expertise.set(expertise);
instance.debounceValidateExpertise(expertise);
}

const title = FlowRouter.getQueryParam('title');
if (title) {
instance.requestTitle.set(title);
}

const question = FlowRouter.getQueryParam('question');
if (question) {
instance.openingQuestion.set(question);
}
}
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ New_request_for_expertise: Wählen Sie das Thema Ihrer Frage aus
New_request: Neue Anfrage
New_request_created: Die neue Anfrage wurde erstellt
New_request_first_question: Was möchten Sie fragen?
New_request_title: Ein Name hilft, die Anfrage wieder zu finden
New_request_title: Ein Titel hilft, die Anfrage wieder zu finden
No_expertise_yet: Keinem Thema zugeordnet
No_requests_yet: Keine Anfragen bisher
release: Version
Expand Down

0 comments on commit 6b71ca6

Please sign in to comment.