Created
September 1, 2014 05:36
-
-
Save MioGreen/d419faecd4f04b8cc4cb to your computer and use it in GitHub Desktop.
Всплывающий выбор городов.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="modal" ng-controller="CitySearchCtrl"> | |
<ion-header-bar class="bar bar-header bar-assertive"> | |
<h1 class="title">Выбор города</h1> | |
<button class="button button-clear button-primary" ng-click="modal.hide()">Отмена</button> | |
</ion-header-bar> | |
<ion-header-bar class="bar-subheader item-input-inset"> | |
<label class="item-input-wrapper"> | |
<i class="icon ion-ios7-search placeholder-icon"></i> | |
<input type="search" placeholder="Поиск города" ng-change="search()" ng-model="data.search"> | |
</label> | |
<button class="button ion-checkmark" ng-click="choose(data.search)"> | |
</button> | |
<!--<button class="button ion-close" ng-click="data.search = ''">--> | |
<!--</button>--> | |
</ion-header-bar> | |
<ion-content> | |
<div class="list"> | |
<li class="item" ng-repeat="city in data.cities" ng-click="choose(city)">{{city}}</li> | |
</div> | |
</ion-content> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function capitaliseFirstLetter(string) | |
{ | |
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); | |
} | |
angular.module('pocketParty.services') | |
.service('CityDataService', function($q, $timeout) { | |
var cityData = [ | |
'Москва' | |
,'Апрелевка' | |
,'Балашиха' | |
,'Бронницы' | |
,'Верея' | |
,'Видное' | |
,'Волоколамск' | |
,'Воскресенск' | |
,'Высоковск' | |
,'Голицыно' | |
,'Дзержинский' | |
,'Дмитров' | |
,'Долгопрудный' | |
,'Домодедово' | |
,'Дрезна' | |
,'Дубна' | |
,'Егорьевск' | |
,'Железнодорожный' | |
,'Жуковский' | |
,'Зарайск' | |
,'Звенигород' | |
,'Зеленоград' | |
,'Ивантеевка' | |
,'Истра' | |
,'Кашира' | |
,'Климовск' | |
,'Клин' | |
,'Коломна' | |
,'Королев' | |
,'Котельники' | |
,'Красмоармейск' | |
,'Красногорск' | |
,'Краснозаводск' | |
,'Краснознаменск' | |
,'Кубинка' | |
,'Куровское' | |
,'Ликино-Дулево' | |
,'Лобня' | |
,'Лосино-Петровский' | |
,'Луховицы' | |
,'Лыткарино' | |
,'Люберцы' | |
,'Можайск' | |
,'Мытищи' | |
,'Наро-Фоминск' | |
,'Ногинск' | |
,'Одинцово' | |
,'Ожерелье' | |
,'Озеры' | |
,'Орехово-Зуево' | |
,'Павловский Посад' | |
,'Подольск' | |
,'Протвино' | |
,'Пушкино' | |
,'Пущино' | |
,'Раменское' | |
,'Реутов' | |
,'Рошаль' | |
,'Руза' | |
,'Сергиев Посад' | |
,'Серпухов' | |
,'Солнечногорск' | |
,'Стремилово' | |
,'Ступино' | |
,'Сходня' | |
,'Талдом' | |
,'Троицк' | |
,'Фрязино' | |
,'Химки' | |
,'Хотьково' | |
,'Черноголовка' | |
,'Чехов' | |
,'Шатура' | |
,'Щелково' | |
,'Щербинка' | |
,'Электрогорск' | |
,'Электросталь' | |
,'Электроугли' | |
,'Юбилейный' | |
,'Яхрома' | |
]; | |
this.all = function(){ | |
return cityData; | |
} | |
this.search = function(search){ | |
var search = capitaliseFirstLetter(search), | |
deferred = $q.defer(); | |
$timeout(function() { | |
var cities = []; | |
if(!!search) | |
cities = _.filter(cityData, | |
function (name) { | |
return name.indexOf(search) >= 0 | |
}); | |
deferred.resolve(cities); | |
}); | |
return deferred.promise; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('pocketParty.controllers') | |
.controller('CitySearchCtrl', function ($scope, CityDataService, messanger) { | |
$scope.data = { "cities" : CityDataService.all(), "search" : '' }; | |
$scope.search = function() { | |
CityDataService | |
.search($scope.data.search) | |
.then( | |
function(matches) { | |
$scope.data.cities = matches; | |
} | |
) | |
} | |
messanger.on('modal.field.editing', function(event, value) { | |
$scope.data.search = value; | |
$scope.search(); | |
}); | |
function hide() { | |
$scope.data.search = ''; | |
$scope.modal.hide(); | |
} | |
$scope.close = function () { | |
hide(); | |
}; | |
$scope.choose = function (city) { | |
messanger.send('modal.field.edited', city); | |
hide(); | |
}; | |
}) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('pocketParty.controllers') | |
.factory('FieldEditor', function(messanger, $ionicModal) { | |
return { | |
create: function(template){ | |
var cb = null, | |
m = null; | |
$ionicModal.fromTemplateUrl(template || 'templates/field-edit.html', function (modal) { | |
m = modal; | |
}, { | |
animation: 'slide-in-up', | |
focusFirstInput: true | |
}); | |
// Execute action on hide modal | |
messanger.on('modal.field.edited', function(event, value) { | |
if(!cb) { return; } | |
cb(value); | |
cb = null; | |
}); | |
return { | |
editField: function(fn, current) { | |
cb = fn; | |
messanger.send('ga.page', 'fieldedit.pocketparty.ru'); | |
m.show(); | |
if(current) { | |
messanger.send('modal.field.editing', current); } | |
} | |
}; | |
} | |
} | |
} | |
) | |
.controller('EditFieldCtrl', function ($scope, messanger) { | |
$scope.data = { | |
item: '' | |
}; | |
messanger.on('modal.field.editing', function(event, value) { | |
$scope.data.item = value; | |
}); | |
function hide() { | |
$scope.data.item = ''; | |
$scope.modal.hide(); | |
} | |
$scope.close = function () { | |
hide(); | |
}; | |
$scope.save = function () { | |
messanger.send('ga.event', 'Button', 'Click', 'EditField Save ' + $stateParams.step, 1); | |
var item = $scope.data.item; | |
if (!item) return; | |
messanger.send('modal.field.edited', $scope.data.item); | |
hide(); | |
}; | |
}) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rootScope.fieldEditor = FieldEditor.create(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.cityEditor = FieldEditor.create('templates/city-search.html'); | |
$scope.updateCityField = function(){ | |
$scope.cityEditor.editField( | |
function(value){ | |
$scope.request.city = value;}, | |
$scope.request.city); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment