         kd.warn err
 
       new KDNotificationView title: message, duration: 5000
+
+
+  createSection: (options = {}) ->
+
+    { name, title, description } = options
+
+    section = new KDCustomHTMLView
+      tagName  : 'section'
+      cssClass : kd.utils.curry 'AppModal-section', name
+
+    section.addSubView desc = new KDCustomHTMLView
+      tagName  : 'p'
+      cssClass : 'AppModal-sectionDescription'
+      partial  : description
+
+    return section
+
+
+  addInput: (form, options) ->
+
+    { name, label, description, itemClass, nextElement } = options
+
+    itemClass  or= KDInputView
+    form.inputs ?= {}
+
+    form.addSubView field = new KDCustomHTMLView tagName : 'fieldset'
+
+    if label
+      field.addSubView labelView = new KDCustomHTMLView
+        tagName : 'label'
+        for     : name
+        partial : label
+      options.label = labelView
+
+    field.addSubView form.inputs[name] = input = new itemClass options
+    field.addSubView new KDCustomHTMLView tagName : 'p', partial : description  if description
+
+    field.addSubView nextElement  if nextElement and nextElement instanceof KDView
+
+    return input

showError          = require 'app/util/showError'
Encoder            = require 'htmlencode'
geoPattern         = require 'geopattern'


createSection = (options = {}) ->

  { name, title, description } = options

  section = new KDCustomHTMLView
    tagName  : 'section'
    cssClass : kd.utils.curry 'AppModal-section', name

  section.addSubView desc = new KDCustomHTMLView
    tagName  : 'p'
    cssClass : 'AppModal-sectionDescription'
    partial  : description

  return section


addInput = (form, options) ->

  { name, label, description, itemClass, nextElement } = options

  itemClass  or= KDInputView
  form.inputs ?= {}

  form.addSubView field = new KDCustomHTMLView tagName : 'fieldset'

  if label
    field.addSubView labelView = new KDCustomHTMLView
      tagName : 'label'
      for     : name
      partial : label
    options.label = labelView

  field.addSubView form.inputs[name] = input = new itemClass options
  field.addSubView new KDCustomHTMLView tagName : 'p', partial : description  if description

  field.addSubView nextElement  if nextElement and nextElement instanceof KDView

  return input

addButton = (form, options) ->

  { title, callback } = options

  form.addSubView new KDButtonView {
    title
    callback
    type     : 'submit'
    cssClass : 'solid medium green'
  }


module.exports = class GroupGeneralSettingsView extends KDView

    group = @getData()
    url   = if group.slug is 'koding' then '' else "#{group.slug}."

    @addSubView section = @createSection name: 'general-settings'

    section.addSubView form = @generalSettingsForm = new KDFormView

    @addInput form,
      label        : 'Name'
      description  : 'Your team name is displayed in menus and emails. It usually is (or includes) the name of your company.'
      name         : 'title'
      defaultValue : Encoder.htmlDecode group.title ? ''
      placeholder  : 'Please enter a title here'

    @addInput form,
      label        : 'URL'
      description  : 'Changing your team URL is currently not supported, if, for any reason, you must change this please send us an email at support@koding.com.'
      name         : 'url'
