Skip to content

Commit

Permalink
Search in persons
Browse files Browse the repository at this point in the history
  • Loading branch information
autowp committed Sep 13, 2017
1 parent b910db4 commit fde1a1e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
51 changes: 45 additions & 6 deletions assets/controllers/moder/pictures/item/move/index.js
Expand Up @@ -36,8 +36,8 @@ angular.module(Module)
}
])
.controller(CONTROLLER_NAME, [
'$scope', '$http', '$state', PICTURE_ITEM_SERVICE,
function($scope, $http, $state, PictureItemService) {
'$scope', '$http', '$state', '$q', PICTURE_ITEM_SERVICE,
function($scope, $http, $state, $q, PictureItemService) {

var ctrl = this;

Expand Down Expand Up @@ -117,16 +117,27 @@ angular.module(Module)
});
}

if ($scope.show_persons) {
var personsCanceler;
function loadPersons() {

if (personsCanceler) {
personsCanceler.resolve();
personsCanceler = null;
}

personsCanceler = $q.defer();

$http({
method: 'GET',
url: '/api/item',
params: {
type_id: 8,
fields: 'name_html',
limit: 50,
name: ctrl.search ? '%' + ctrl.search + '%' : null,
page: $scope.page
}
},
timeout: personsCanceler.promise
}).then(function(response) {
$scope.persons = response.data.items;
$scope.persons_paginator = response.data.paginator;
Expand All @@ -135,16 +146,35 @@ angular.module(Module)
});
}

if ($scope.show_authors) {
if ($scope.show_persons) {
ctrl.doSearch = function() {
loadPersons();
};

loadPersons();
}

var authorsCanceler;
function loadAuthors() {

if (authorsCanceler) {
authorsCanceler.resolve();
authorsCanceler = null;
}

authorsCanceler = $q.defer();

$http({
method: 'GET',
url: '/api/item',
params: {
type_id: 8,
fields: 'name_html',
limit: 50,
name: ctrl.search ? '%' + ctrl.search + '%' : null,
page: $scope.page
}
},
timeout: authorsCanceler.promise
}).then(function(response) {
$scope.authors = response.data.items;
$scope.authors_paginator = response.data.paginator;
Expand All @@ -153,6 +183,15 @@ angular.module(Module)
});
}

if ($scope.show_authors) {

ctrl.doSearch = function() {
loadAuthors();
};

loadAuthors();
}

function loadBrands() {
$http({
method: 'GET',
Expand Down
10 changes: 9 additions & 1 deletion assets/controllers/moder/pictures/item/move/template.html
Expand Up @@ -38,6 +38,9 @@
<div ng-if="show_persons && !src_item && (!src_type || src_type == 1)">

<div class="well">
<div style="margin-bottom:20px">
<input type="text" ng-model="ctrl.search" ng-change="ctrl.doSearch()" class="form-control" placeholder="Type to search ..." auto-focus />
</div>
<a href="#" ng-repeat-start="item in persons" ng-click="selectItem(item.id, null, 1)" ng-bind-html="item.name_html"></a>
<br ng-repeat-end />
</div>
Expand All @@ -48,6 +51,9 @@
<div ng-if="show_authors && !src_item && (!src_type || src_type == 2)">

<div class="well">
<div style="margin-bottom:20px">
<input type="text" ng-model="ctrl.search" ng-change="ctrl.doSearch()" class="form-control" placeholder="Type to search ..." auto-focus />
</div>
<a href="#" ng-repeat-start="item in authors" ng-click="selectItem(item.id, null, 2)" ng-bind-html="item.name_html"></a>
<br ng-repeat-end />
</div>
Expand All @@ -60,7 +66,9 @@
<div ng-if="!brand_id">

<div class="well">
<input type="text" ng-model="ctrl.search" ng-change="ctrl.doSearch()" class="form-control" placeholder="Type to search ..." auto-focus />
<div style="margin-bottom:20px">
<input type="text" ng-model="ctrl.search" ng-change="ctrl.doSearch()" class="form-control" placeholder="Type to search ..." auto-focus />
</div>
<div class="row">
<div ng-repeat="chunk in brands" class="col-xs-2">
<a ng-repeat-start="item in chunk" ui-sref=".({page: null, brand_id: item.id})" ng-bind-html="item.name_html"></a>
Expand Down

0 comments on commit fde1a1e

Please sign in to comment.