Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 KB | None | 0 0
  1. $scope.AddPost = function(files) {
  2. var url = "https://hotelboard.firebaseio.com/Articles/";
  3. var category = $scope.Category;
  4.  
  5. //var fb = new Firebase("https://hotelboard.firebaseio.com/Articles/");
  6.  
  7. var fb = new Firebase(url).child(category);
  8.  
  9. var title = $scope.article.title;
  10. var post = $scope.article.post;
  11. var user = CommonProp.getUser();
  12.  
  13. if (files == undefined){
  14.  
  15. var push = fb.push({
  16. title: title,
  17. post: post,
  18. emailId: user,
  19. images : null,
  20. '.priority': user
  21.  
  22. },function(error) {
  23. if (error) {
  24. console.log("Error:",error);
  25. } else {
  26. console.log("Post set successfully!");
  27. $location.path('/home');
  28. console.log(push.key());
  29. $scope.$apply();
  30. }
  31. });
  32.  
  33. } else {
  34.  
  35. Upload.base64DataUrl(files).then(function(base64Urls){
  36.  
  37. fb.push({
  38. title: title,
  39. post: post,
  40. emailId: user,
  41. images : base64Urls,
  42. '.priority': user
  43.  
  44. },function(error) {
  45. if (error) {
  46. console.log("Error:",error);
  47. } else {
  48. console.log("Post set successfully!");
  49. $location.path('/home');
  50. $scope.$apply();
  51.  
  52. }
  53.  
  54. });
  55.  
  56. });
  57. }
  58. }
  59. $scope.remove = function(array, index){
  60. array.splice(index, 1);
  61.  
  62.  
  63. }
  64.  
  65. }]);
  66.  
  67. <div class="list-group" ng-repeat="article in articles">
  68.  
  69. <h1>{{article.$id}}</h1>
  70.  
  71. <div class="list-group" ng-repeat="(key,art) in article">
  72. <span class="list-group-item active">
  73.  
  74. <h4 class="list-group-item-heading">{{art.title}}</h4>
  75. <p class="list-group-item-text">{{art.post}}</p>
  76. <div class="row">
  77. <div class="col-sm-2" ng-repeat="image in art.images">
  78. <img ng-show="art.images" ng-src={{image}} width="50px" height="50px" >
  79. </div>
  80. </div>
  81. <span class="pull-right" >
  82. <button class="btn btn-xs btn-info" ng-click="editPost(article.$id)" data-target="#editModal">EDIT</button>
  83. <button class="btn btn-xs btn-warning" ng-click="confirmDelete(article.$id)" data-target="#deleteModal">DELETE</button>
  84. </span>
  85. </span>
  86. </div>
  87. </div>
  88.  
  89. <!-- Edit Modal popup -->
  90. <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
  91. <div class="modal-dialog">
  92. <div class="modal-content">
  93. <div class="modal-header">
  94. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
  95. </button>
  96. <h4 class="modal-title" id="editModalLabel">Update Post</h4>
  97. </div>
  98.  
  99. <div class="modal-body">
  100. <form role="form">
  101. <div class="form-group">
  102. <label for="recipient-name" class="control-label">Title:</label>
  103. <input type="text" class="form-control" ng-model="postToUpdate.title" id="recipient-name">
  104. </div>
  105. <div class="form-group">
  106. <label for="message-text" class="control-label">Post:</label>
  107. <textarea class="form-control" ng-model="postToUpdate.post" id="message-text"></textarea>
  108. </div>
  109. <div class="form-group" ng-show="postToUpdate.images">
  110. <label for="picturs" class="control-label">Pictures:</label>
  111. <div ng-repeat="image in postToUpdate.images"><img ng-src={{image}} width="50px" height="50px"><span class="glyphicon glyphicon-remove-circle" ng-click="remove(postToUpdate.images, $index)"></span></div>
  112. </div>
  113. </form>
  114. </div>
  115.  
  116. <div class="modal-footer">
  117. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  118. <button type="button" class="btn btn-primary" ng-click="update()">Publish</button>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123.  
  124. <!-- Delete Modal popup -->
  125. <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
  126. <div class="modal-dialog">
  127. <div class="modal-content">
  128. <div class="modal-header" style="text-align:center;">
  129. <h4 class="modal-title" style="color:red;" id="deleteModalLabel">You are going to Delete this post forever !!</h4>
  130. </div>
  131.  
  132. <div class="modal-footer">
  133. <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  134. <button type="button" class="btn btn-primary" ng-click="deletePost()">Delete</button>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139.  
  140. </div>
  141.  
  142. 'use strict';
  143.  
  144. angular.module('myApp.home', [])
  145.  
  146.  
  147. .controller('HomeCtrl', ['$scope','CommonProp','$firebaseArray','$firebaseObject','$location', function($scope,CommonProp,$firebaseArray,$firebaseObject,$location) {
  148. $scope.username = CommonProp.getUser();
  149.  
  150. if(!$scope.username){
  151. $location.path('/main');
  152. }
  153.  
  154. var url = "https://hotelboard.firebaseio.com/Articles/";
  155. var fb = new Firebase(url);
  156. //var fbObj = fb.startAt($scope.username).endAt($scope.username);
  157.  
  158. $scope.articles = $firebaseArray(fb);
  159.  
  160.  
  161. $scope.editPost = function(id) {
  162. var fb = new Firebase(url + id);
  163.  
  164. $scope.postToUpdate = $firebaseObject(fb);
  165. $('#editModal').modal();
  166.  
  167. }
  168.  
  169. $scope.update = function() {
  170. var fb = new Firebase(url + $scope.postToUpdate.$id);
  171. if($scope.postToUpdate.images == undefined){
  172. $scope.postToUpdate.images = null;
  173. }
  174.  
  175. fb.update({
  176. title: $scope.postToUpdate.title,
  177. post: $scope.postToUpdate.post,
  178. emailId: $scope.postToUpdate.emailId,
  179. images: $scope.postToUpdate.images
  180. }, function(error) {
  181. if (error) {
  182. console.log('Error:', error);
  183. } else {
  184. $('#editModal').modal('hide');
  185. }
  186. });
  187. }
  188.  
  189. $scope.confirmDelete = function(id) {
  190. var fb = new Firebase(url + id);
  191. $scope.postToDelete = $firebaseObject(fb);
  192. $('#deleteModal').modal();
  193.  
  194. }
  195.  
  196. $scope.deletePost = function() {
  197. var fb = new Firebase(url + $scope.postToDelete.$id);
  198.  
  199. fb.remove(function(error) {
  200. if (error) {
  201. console.log('Error:', error);
  202. } else {
  203. $('#deleteModal').modal('hide');
  204. }
  205.  
  206. });
  207. }
  208.  
  209. $scope.remove = function(array, index){
  210. array.splice(index, 1);
  211. }
  212. }]);
  213.  
  214. Articles
  215. Events
  216. -K09Iy9pa6FEA0rmmEMH
  217. emailId:"said@gmail.com"
  218. images
  219. 0:"data:image/png;base64,iVBORw0KGgoAAAANSUhEU
  220. post: "This is event 1"
  221. title:"Event 1"
  222.  
  223. Facilities
  224. -K09Ibsqz5L82PUoCEjY
  225. emailId: "said@gmail.com"
  226. post: "this is fac 1"
  227. title:"Facility 1"
  228. Offers
  229. -K09IipPdR7We_D5Tzb9
  230. emailId:"said@gmail.com"
  231. post:"this is offer 1"
  232. title:"Offer 1"
  233.  
  234. var fbObj = fb.startAt($scope.username).endAt($scope.username);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement