You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.2 KiB

  1. 'use strict';
  2. angular.module('app.write', ['ngRoute'])
  3. .config(['$routeProvider', function($routeProvider) {
  4. $routeProvider.when('/write', {
  5. templateUrl: 'views/write/write.html',
  6. controller: 'WriteCtrl'
  7. });
  8. }])
  9. .controller('WriteCtrl', function($scope, $rootScope, $http) {
  10. $scope.post = {
  11. title: "",
  12. content: "",
  13. summary: ""
  14. };
  15. var editor = new MediumEditor('.editable', {
  16. toolbar: {
  17. /* These are the default options for the toolbar,
  18. if nothing is passed this is what is used */
  19. allowMultiParagraphSelection: true,
  20. buttons: ['bold', 'italic', 'underline', 'anchor', 'h2', 'h3', 'quote'],
  21. diffLeft: 0,
  22. diffTop: -10,
  23. firstButtonClass: 'medium-editor-button-first',
  24. lastButtonClass: 'medium-editor-button-last',
  25. relativeContainer: null,
  26. standardizeSelectionStart: false,
  27. static: false,
  28. /* options which only apply when static is true */
  29. align: 'center',
  30. sticky: false,
  31. updateOnEmptySelection: false
  32. },
  33. autoLink: true,
  34. placeholder: {
  35. text: 'Start to writting your decentralized blog post...'
  36. }
  37. }).subscribe('editableInput', function (event, editable) {
  38. // Do some work
  39. $scope.post.content = editable.innerHTML;
  40. console.log($scope.post.content);
  41. });
  42. $scope.publicate = function() {
  43. console.log("post", $scope.post);
  44. $http({
  45. url: apiurl + 'post',
  46. method: "POST",
  47. headers: {
  48. "Content-Type": undefined
  49. },
  50. data: $scope.post
  51. })
  52. .then(function(data) {
  53. console.log("data: ");
  54. console.log(data.data);
  55. window.location = "#!/user/" + $scope.user.id;
  56. },
  57. function(data) {
  58. console.log(data);
  59. });
  60. };
  61. });