 
     $data.loadProject($scope)
 
+    loadAttachments = (page) ->
+        rs.getWikiPageAttachments(projectId, page.id).then (attachments) ->
+            $scope.attachments = attachments
+
+    saveNewAttachments = ->
+        if $scope.newAttachments.length == 0
+            return
+
+        promises = []
+        for attrachment in $scope.newAttachments
+            promise = rs.uploadWikiPageAttachment(projectId, $scope.page.id, attrachment)
+            promises.push(promise)
+
+        promise = Q.all(promises)
+        promise.then ->
+            $scope.newAttachments = []
+            loadAttachments($scope.page)
+
     promise = rs.getWikiPage(projectId, slug)
     promise.then (page) ->
         $scope.page = page

# See the License for the specific language governing permissions and
# limitations under the License.

WikiController = ($scope, $rootScope, $location, $routeParams, $data, rs, $confirm) ->
    $rootScope.pageSection = 'wiki'
    $rootScope.projectId = parseInt($routeParams.pid, 10)
    $rootScope.pageBreadcrumb = [



module = angular.module("greenmine.controllers.wiki", [])
module.controller("WikiController", ['$scope', '$rootScope', '$location', '$routeParams',
                                     '$data', 'resource', "$confirm", "$q", WikiController])
