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