/ The ‘Edit Button’ dialog

It will only get shown when requested by a button
Expects a local variable `link` with a.. link.

.modal.fade.input-link#edit-link tabindex=“-1” role=“dialog” aria-labelledby=“input-link-label” aria-hidden=“true”

.modal-dialog
  .modal-content
    .modal-header
      button.close type="button" data-dismiss="modal" aria-hidden="true"
        | ×

      h4.modal-title.input-link-label
        | Edit link

      p.random-sentence
        | ...#{random_sentence}

    .modal-body
      / Form that creates a Link
        It's 'action' will get changed by the JavaScript
        to conform to the API like '/update/link/:id'
      form.form-horizontal role="form" action="/update/link" method="POST"

        .form-group
          label.col-sm-2.control-label for="input-link-url"
            | URL
          .col-sm-10
            input.form-control type="text" id="input-link-url"   name="url"   placeholder="URL"   required="true" autofocus="true"

        .form-group
          .col-sm-offset-2.col-sm-10
            button.btn.btn-primary type="submit"
              span.glyphicon.glyphicon-flash
              '
              | Edit link

        .form-group
          label.col-sm-2.control-label for="input-link-title"
            | Title
          .col-sm-10
            input.form-control type="text" id="input-link-title" name="title" placeholder="title"

        .form-group
          label.col-sm-2.control-label for="input-link-tags"
            | Tags
          .col-sm-10
            input.form-control.tagsinput type="text" id="input-link-tags" name="tags" placeholder="tag (comma-separated)"

        .form-group
          label.col-sm-2.control-label for="input-links-url"
            | Comments
          .col-sm-10
            textarea.form-control[
              type="textarea"
              id="input-link-comment"
              name="comment"
              placeholder="express yourself"
            ]

        .form-group
          label.col-sm-2.control-label for="input-link-category-one"
            | Category
          .col-sm-10
            select.form-control id="input-link-category-one" name="category" placeholder="Category"
              ruby:
                # This magic function shows all Categories in
                # hierarchical order. Just like:
                #
                # parent
                # - child
                # - other_child
                # - - other_other_child
                # other_parent
                # - another_child

                def select_options
                  $output = "<option value=''>(none)</option>"

                  def recursive_childs(count, category)
                    $output << "<option value='#{category.id}'>#{'- ' * count}#{category.name}</option>"

                    category.childs.each do |child|
                      recursive_childs(count + 1, child)
                    end
                  end

                  Sharkey::Category.orphans.each do |orphan|
                    recursive_childs(0, orphan)
                  end
                  return $output
                end

              == select_options

          .col-sm-offset-2.col-sm-10
            button.btn.btn-default.new-category
              span> class="glyphicon glyphicon-book"
              | New Category

      form.form-horizontal.new-category-form role="form" action="/category" method="POST"
        .form-group

          label.col-sm-2.control-label for="new-category-name"
            | Name
          .col-sm-10
            input.form-control.new-category-name type="text"  name="name" placeholder="New category name" required="true" autofocus="true"

          label.col-sm-2.control-label for="new-category-parent"
            | Parent
          .col-sm-10
            select.form-control.new-category-parent name="parent" placeholder="Parent"
              == select_options

            button.btn.btn-default.new-category-button type="submit"
              span> class="glyphicon glyphicon-book"
              | Create Category

/ If you ever want to add a footer some day,
  just uncomment these two lines
  .modal-footer