From fd68564b3f634485a73d508998941a979c82bf43 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 4 Nov 2013 19:59:28 -0500 Subject: [PATCH] Add a markdown input directive and convert both uses of the editor to the directive --- static/css/quay.css | 3 +- static/directives/markdown-input.html | 31 +++++++++++++++++ static/js/app.js | 48 +++++++++++++++++++++++++++ static/js/controllers.js | 36 ++------------------ static/partials/new-repo.html | 6 ++-- static/partials/view-repo.html | 33 ++---------------- 6 files changed, 86 insertions(+), 71 deletions(-) create mode 100644 static/directives/markdown-input.html diff --git a/static/css/quay.css b/static/css/quay.css index 663a25154..a5b115374 100644 --- a/static/css/quay.css +++ b/static/css/quay.css @@ -649,9 +649,8 @@ p.editable { display: inline-block; } -p.editable .content:empty:after { +p.editable .empty { display: inline-block; - content: "(Click to add)"; color: #aaa; } diff --git a/static/directives/markdown-input.html b/static/directives/markdown-input.html new file mode 100644 index 000000000..010c2f90a --- /dev/null +++ b/static/directives/markdown-input.html @@ -0,0 +1,31 @@ +
+

+ + (Click to set {{ fieldTitle }}) + +

+ + + +
diff --git a/static/js/app.js b/static/js/app.js index 333f0d047..ca32342a3 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -312,6 +312,54 @@ quayApp.directive('organizationHeader', function () { }); +quayApp.directive('markdownInput', function () { + var counter = 0; + + var directiveDefinitionObject = { + priority: 0, + templateUrl: '/static/directives/markdown-input.html', + replace: false, + transclude: false, + restrict: 'C', + scope: { + 'content': '=content', + 'canWrite': '=canWrite', + 'contentChanged': '=contentChanged', + 'fieldTitle': '=fieldTitle' + }, + controller: function($scope, $element) { + var elm = $element[0]; + + $scope.id = (counter++); + + $scope.editContent = function() { + if (!$scope.canWrite) { return; } + + if (!$scope.markdownDescriptionEditor) { + var converter = Markdown.getSanitizingConverter(); + var editor = new Markdown.Editor(converter, '-description-' + $scope.id); + editor.run(); + $scope.markdownDescriptionEditor = editor; + } + + $('#wmd-input-description-' + $scope.id)[0].value = $scope.content; + $(elm).find('.modal').modal({}); + }; + + $scope.saveContent = function() { + $scope.content = $('#wmd-input-description-' + $scope.id)[0].value; + $(elm).find('.modal').modal('hide'); + + if ($scope.contentChanged) { + $scope.contentChanged($scope.content); + } + }; + } + }; + return directiveDefinitionObject; +}); + + quayApp.directive('entitySearch', function () { var number = 0; var directiveDefinitionObject = { diff --git a/static/js/controllers.js b/static/js/controllers.js index 55d277f75..1faffb0ca 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -248,23 +248,8 @@ function RepoCtrl($scope, Restangular, $routeParams, $rootScope, $location, $tim $scope.setTag($location.search().tag, false); }); - $scope.editDescription = function() { - if (!$scope.repo.can_write) { return; } - - if (!$scope.markdownDescriptionEditor) { - var converter = Markdown.getSanitizingConverter(); - var editor = new Markdown.Editor(converter, '-description'); - editor.run(); - $scope.markdownDescriptionEditor = editor; - } - - $('#wmd-input-description')[0].value = $scope.repo.description; - $('#editModal').modal({}); - }; - - $scope.saveDescription = function() { - $('#editModal').modal('hide'); - $scope.repo.description = $('#wmd-input-description')[0].value; + $scope.updateForDescription = function(content) { + $scope.repo.description = content; $scope.repo.put(); }; @@ -1003,23 +988,6 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula }); }; - $scope.editDescription = function() { - if (!$scope.markdownDescriptionEditor) { - var converter = Markdown.getSanitizingConverter(); - var editor = new Markdown.Editor(converter, '-description'); - editor.run(); - $scope.markdownDescriptionEditor = editor; - } - - $('#wmd-input-description')[0].value = $scope.repo.description; - $('#editModal').modal({}); - }; - - $scope.saveDescription = function() { - $('#editModal').modal('hide'); - $scope.repo.description = $('#wmd-input-description')[0].value; - }; - $scope.createNewRepo = function() { $('#repoName').popover('hide'); diff --git a/static/partials/new-repo.html b/static/partials/new-repo.html index 70effd42a..a8ab2cba5 100644 --- a/static/partials/new-repo.html +++ b/static/partials/new-repo.html @@ -39,10 +39,8 @@
Description:
-

- - -

+
diff --git a/static/partials/view-repo.html b/static/partials/view-repo.html index bcbc789ab..84eb76919 100644 --- a/static/partials/view-repo.html +++ b/static/partials/view-repo.html @@ -52,12 +52,8 @@ -
-

- - -

-
+
@@ -183,29 +179,4 @@
- - - -