+
+
diff --git a/src/core/courses/pages/search/search.module.ts b/src/core/courses/pages/search/search.module.ts
new file mode 100644
index 000000000..c74212c21
--- /dev/null
+++ b/src/core/courses/pages/search/search.module.ts
@@ -0,0 +1,33 @@
+// (C) Copyright 2015 Martin Dougiamas
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import { NgModule } from '@angular/core';
+import { IonicPageModule } from 'ionic-angular';
+import { TranslateModule } from '@ngx-translate/core';
+import { CoreCoursesSearchPage } from './search';
+import { CoreComponentsModule } from '../../../../components/components.module';
+import { CoreCoursesComponentsModule } from '../../components/components.module';
+
+@NgModule({
+ declarations: [
+ CoreCoursesSearchPage,
+ ],
+ imports: [
+ CoreComponentsModule,
+ CoreCoursesComponentsModule,
+ IonicPageModule.forChild(CoreCoursesSearchPage),
+ TranslateModule.forChild()
+ ],
+})
+export class CoreCoursesSearchPageModule {}
diff --git a/src/core/courses/pages/search/search.scss b/src/core/courses/pages/search/search.scss
new file mode 100644
index 000000000..1bf3fe798
--- /dev/null
+++ b/src/core/courses/pages/search/search.scss
@@ -0,0 +1,3 @@
+page-core-courses-search {
+
+}
diff --git a/src/core/courses/pages/search/search.ts b/src/core/courses/pages/search/search.ts
new file mode 100644
index 000000000..654b36cb5
--- /dev/null
+++ b/src/core/courses/pages/search/search.ts
@@ -0,0 +1,82 @@
+// (C) Copyright 2015 Martin Dougiamas
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import { Component } from '@angular/core';
+import { IonicPage } from 'ionic-angular';
+import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
+import { CoreCoursesProvider } from '../../providers/courses';
+
+/**
+ * Page that allows searching for courses.
+ */
+@IonicPage()
+@Component({
+ selector: 'page-core-courses-search',
+ templateUrl: 'search.html',
+})
+export class CoreCoursesSearchPage {
+ total = 0;
+ courses: any[];
+ canLoadMore: boolean;
+
+ protected page = 0;
+ protected currentSearch = '';
+
+ constructor(private domUtils: CoreDomUtilsProvider, private coursesProvider: CoreCoursesProvider) {}
+
+ /**
+ * Search a new text.
+ *
+ * @param {string} text The text to search.
+ */
+ search(text: string) {
+ this.currentSearch = text;
+ this.courses = undefined;
+ this.page = 0;
+
+ let modal = this.domUtils.showModalLoading('core.searching', true);
+ this.searchCourses().finally(() => {
+ modal.dismiss();
+ });
+ }
+
+ /**
+ * Load more results.
+ */
+ loadMoreResults(infiniteScroll) {
+ this.searchCourses().finally(() => {
+ infiniteScroll.complete();
+ });
+ }
+
+ /**
+ * Search courses or load the next page of current search.
+ */
+ protected searchCourses() {
+ return this.coursesProvider.search(this.currentSearch, this.page).then((response) => {
+ if (this.page === 0) {
+ this.courses = response.courses;
+ } else {
+ this.courses = this.courses.concat(response.courses);
+ }
+ this.total = response.total;
+
+ this.page++;
+ this.canLoadMore = this.courses.length < this.total;
+ }).catch((error) => {
+ this.canLoadMore = false;
+ this.domUtils.showErrorModalDefault(error, 'core.courses.errorsearching', true);
+ });
+ }
+}
diff --git a/src/core/login/pages/site/site.html b/src/core/login/pages/site/site.html
index d8f15beac..dc5c1dda1 100644
--- a/src/core/login/pages/site/site.html
+++ b/src/core/login/pages/site/site.html
@@ -19,7 +19,7 @@
{{ 'core.login.newsitedescription' | translate }}
-
+
diff --git a/src/directives/auto-focus.ts b/src/directives/auto-focus.ts
index 5cded27fa..9b41e7a3c 100644
--- a/src/directives/auto-focus.ts
+++ b/src/directives/auto-focus.ts
@@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Directive, Input, AfterViewInit, ElementRef } from '@angular/core';
+import { Directive, Input, OnInit, ElementRef } from '@angular/core';
+import { NavController } from 'ionic-angular';
import { CoreDomUtilsProvider } from '../providers/utils/dom';
import { CoreUtilsProvider } from '../providers/utils/utils';
@@ -24,19 +25,35 @@ import { CoreUtilsProvider } from '../providers/utils/utils';
@Directive({
selector: '[core-auto-focus]'
})
-export class CoreAutoFocusDirective implements AfterViewInit {
+export class CoreAutoFocusDirective implements OnInit {
@Input('core-auto-focus') coreAutoFocus: boolean|string = true;
protected element: HTMLElement;
- constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider, private utils: CoreUtilsProvider) {
+ constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider, private utils: CoreUtilsProvider,
+ private navCtrl: NavController) {
this.element = element.nativeElement || element;
}
+ /**
+ * Component being initialized.
+ */
+ ngOnInit() {
+ if (this.navCtrl.isTransitioning()) {
+ // Navigating to a new page. Wait for the transition to be over.
+ let subscription = this.navCtrl.viewDidEnter.subscribe(() => {
+ this.autoFocus();
+ subscription.unsubscribe();
+ });
+ } else {
+ this.autoFocus();
+ }
+ }
+
/**
* Function after the view is initialized.
*/
- ngAfterViewInit() {
+ protected autoFocus() {
const autoFocus = this.utils.isTrueOrOne(this.coreAutoFocus);
if (autoFocus) {
// If it's a ion-input or ion-textarea, search the right input to use.