123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- angular.module('starter.controllers', [])
- .controller('DashCtrl', function($scope) {})
- .controller('ChatsCtrl', function($scope, Chats) {
- // With the new view caching in Ionic, Controllers are only called
- // when they are recreated or on app start, instead of every page change.
- // To listen for when this page is active (for example, to refresh data),
- // listen for the $ionicView.enter event:
- //
- //$scope.$on('$ionicView.enter', function(e) {
- //});
- $scope.chats = Chats.all();
- $scope.remove = function(chat) {
- Chats.remove(chat);
- };
- })
- .controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
- $scope.chat = Chats.get($stateParams.chatId);
- })
- .controller('AccountCtrl', function($scope, $state, $resource, Task) {
- // $scope.settings = {
- // enableFriends: true
- // };
- $scope.time = new Date();
- var task = $resource('http://192.168.1.6:8000/task/:id/');
- task.get(function (res) {
- $scope.taskList = res;
- }, function (err) {
- alert(JSON.stringify(err));
- $scope.taskList = [{
- id:1,title:'任务',description:'123456',created:new Date(),is_completed:false
- }]
- })
- $scope.toAdd = function () {
- $state.go('tab.task-detail',{
- id:0
- })
- }
- $scope.toDetail = function (item) {
- Task.detail = _.clone(item);
- $state.go('tab.task-detail',{
- id:item.id
- })
- }
- $scope.doRefresh = function () {
- getData();
- }
- function getData() {
- Task.getTask.get(function (res) {
- $scope.taskList = res;
- }, function (err) {
- alert(JSON.stringify(err));
- }).$promise.finally(function () {
- $scope.$broadcast('scroll.refreshComplete');
- });
- }
- })
- .controller('TaskDetailCtrl', function ($scope, $state, $stateParams, $resource, $ionicHistory, Task) {
- var id = $stateParams.id;//$state.params['id']
- var isNew = id == 0 ? true : false;
- $scope.data = isNew ? {
- title:null,
- description:null,
- is_completed:null
- } : _.clone(Task.detail);
- var task = $resource('http://192.168.1.6:8000/task/:id/');
- $scope.addTask = function () {
- console.log($scope.data);
- if (isNew) {
- task.save($scope.data,function () {
- $ionicHistory.goBack();
- });
- } else {
- Task.getTask.put($scope.data,function () {
- $ionicHistory.goBack();
- });
- }
- }
- $scope.deleteTask = function (id) {
- Task.getTask.delete({id:id}, function () {
- $ionicHistory.goBack();
- })
- }
- $scope.completed = function () {
- if (!$scope.data.is_completed) $scope.data.is_completed = !$scope.data.is_completed;
- }
- });
|