HTML5技术

【Ionic+AngularJS 开发】之『个人日常管理』App(二) - Glife(5)

字号+ 作者:H5之家 来源:H5之家 2017-02-10 11:01 我要评论( )

日常 nbsp; nbsp; 事务 学习 健康 运动 其他 View Code JavaScript部分 1 angular.module('pdm' ) 2 .controller('Ctrl_DailyActivity' , 3 ['$scope', '$ionicModal', '$db', '$cordovaToast', '$alertPopup' 4 ,

日常nbsp; nbsp; 事务 学习 健康 运动 其他

View Code

JavaScript部分

1 angular.module('pdm') 2 .controller('Ctrl_DailyActivity', 3 ['$scope', '$ionicModal', '$db', '$cordovaToast', '$alertPopup' 4 , function ($scope, $ionicModal, $db, $cordovaToast, $alertPopup) { $scope.getDA = function (callback, cndt) { 8 var sql = "SELECT * FROM Life_DailyActivity WHERE 1=1 "; 9 if (cndt != undefined && cndt != '')sql += (' AND ' + cndt); 10 sql += ' ORDER BY Date'; 11 $db._exec(sql, [], function (rst) { 12 var data = []; 13 for (var i = 0; i < rst.rows.length; i++) data.push(rst.rows.item(i)); 14 callback(data); 15 }); 16 }; 17 $scope.addDA = function (Date, Business, Study, Health, Sport, Others, Remark, callback) { 18 var tbl = 'Life_DailyActivity'; 19 var fields = 'account,Date,Business,Study,Health,Sport,Others,Remark'; 20 var valueArr = [g_user, Date, Business, Study, Health, Sport, Others, Remark]; 21 var _param = ''; 22 for (var i = 0; i < fields.split(',').length; i++)_param += ',?'; 23 _param = _param.substr(1); 24 var sql = 'INSERT INTO ' + tbl + '(' + fields + ') values(' + _param + ')'; 25 $db._exec(sql, valueArr, 26 function (rst) { 27 if (callback != undefined && callback != null) callback(rst); 28 else $cordovaToast.showShortCenter('add to ' + tbl + ' success'); 29 }); 30 }; 31 $scope.updateDA = function (Date, Business, Study, Health, Sport, Others, Remark) { 32 $db.update('Life_DailyActivity' 33 , 'Business,Study,Health,Sport,Others,Remark' 34 , [Business, Study, Health, Sport, Others, Remark] 35 , "Date='" + Date + "'" 36 , true); 37 } $scope.editing = false; 41 $scope.act = { 42 id: 0, 43 tDate: dateFormat(new Date(), 'ymd'), 44 Business: '', 45 Study: '', 46 Health: '', 47 Sport: '', 48 Others: '', 49 Remark: '' 50 }; 51 var _lastDate = $scope.act.tDate; 52 53 $scope.loadData = function () { 54 $scope.getDA(function (data) { 55 $scope.act.Business = ''; 56 $scope.act.Study = ''; 57 $scope.act.Health = ''; 58 $scope.act.Sport = ''; 59 $scope.act.Others = ''; 60 $scope.act.Remark = ''; (data.length > 0) { 63 var item = data[0]; 64 $scope.act.id = item.id; 65 $scope.act.Business = item.Business; 66 $scope.act.Study = item.Study; 67 $scope.act.Health = item.Health; 68 $scope.act.Sport = item.Sport; 69 $scope.act.Others = item.Others; 70 $scope.act.Remark = item.Remark; ($scope.act.id > 0) { 73 $db._exec("delete from Life_DailyActivity where Date='" + $scope.act.tDate + "' and id!=" + $scope.act.id); 74 } 75 } else { 76 $scope.addDA($scope.act.tDate 77 , $scope.act.Business 78 , $scope.act.Study 79 , $scope.act.Health 80 , $scope.act.Sport 81 , $scope.act.Others 82 , $scope.act.Remark 83 , function (rst) { 84 $scope.act.id = rst.insertId; 85 } 86 ); 87 } 88 }, 89 "Date='" + $scope.act.tDate + "'"); 90 } 91 92 $scope.save = function () { 93 $scope.updateDA($scope.act.tDate 94 , $scope.act.Business 95 , $scope.act.Study 96 , $scope.act.Health 97 , $scope.act.Sport 98 , $scope.act.Others 99 , $scope.act.Remark 100 ); 101 } $scope.$watch('act.Business', function (newValue, oldValue, scope) { 105 if ($scope.editing && newValue != oldValue)$scope.save(); 106 }); 107 $scope.$watch('act.Study', function (newValue, oldValue, scope) { 108 if ($scope.editing && newValue != oldValue)$scope.save(); 109 }); 110 $scope.$watch('act.Health', function (newValue, oldValue, scope) { 111 if ($scope.editing && newValue != oldValue)$scope.save(); 112 }); 113 $scope.$watch('act.Sport', function (newValue, oldValue, scope) { 114 if ($scope.editing && newValue != oldValue)$scope.save(); 115 }); 116 $scope.$watch('act.Others', function (newValue, oldValue, scope) { 117 if ($scope.editing && newValue != oldValue)$scope.save(); 118 }); $scope.initData = function () { 122 var events_data = []; $scope.getDA(function (data) { 126 var op = []; 127 op['Business'] = '#387EF5'; 128 op['Study'] = '#FFC900'; 129 op['Health'] = '#EF473A'; 130 op['Sport'] = '#33CD5F'; 131 op['Others'] = '#B2B2B2'; (var i = 0; i < data.length; i++) { 134 var dd = data[i]; 135 for (var k in op) { 136 if (dd[k.toString()] != undefined && dd[k.toString()] != '') { 137 var item = []; 138 item['color'] = op[k]; 139 item['title'] = dd[k.toString()].replace('\n','|').substring(0, 10); 140 item['start'] = new Date(dd['Date']); 141 events_data.push(item); 142 } 143 } 144 } 145 146 $('#calendar').fullCalendar('destroy'); 147 $('#calendar').fullCalendar({ 148 header: { 149 left: 'prev,next today', 150 center: 'title', }, 153 firstDay: 1, 154 events: events_data, dayClick: function (date, allDay, jsEvent, view) { $scope.act.tDate = selDate; 159 160 $scope.loadData(); 161 $scope.openModal(); 162 }, eventClick: function (calEvent, jsEvent, view) { 165 $scope.act.tDate = dateFormat(calEvent.start,'ymd'); 166 167 $scope.loadData(); 168 $scope.openModal(); 169 } 170 }); 171 }); 172 } $ionicModal.fromTemplateUrl('detail.html', { 177 scope: $scope, 178 animation: 'slide-in-up' 179 }).then(function (modal) { 180 $scope.modal = modal; 181 }); 182 $scope.openModal = function () { 183 $scope.modal.show(); 184 185 $scope.editing = true; 186 }; 187 $scope.closeDetail = function () { 188 $scope.initData(); 189 $scope.editing = false; 190 191 $scope.modal.hide(); 192 } 193 $scope.$on('$destroy', function () { 194 $scope.modal.remove(); 195 }); $scope.initData(); 199 200 }]) 201 ;

View Code

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 【福利大放送】不止是Android,Github超高影响力开源大放送,学习开发必备教科书 - 南尘

    【福利大放送】不止是Android,Github超高影响力开源大放送,学习开

    2017-02-09 12:04

  • 高性能移动端开发 - beidan

    高性能移动端开发 - beidan

    2017-02-09 12:00

  • 【Ionic+AngularJS 开发】之『个人日常管理』App(一) - Glife

    【Ionic+AngularJS 开发】之『个人日常管理』App(一) - Glife

    2017-02-08 14:00

  • 我的编程经历与我所热爱的游戏服务端开发 - 千年风雅丶

    我的编程经历与我所热爱的游戏服务端开发 - 千年风雅丶

    2017-02-04 16:00

网友点评
p