1 (function(){var e
=Backbone
.Form
,t
=e
.editors
.Base
,n
=e
.helpers
.createTemplate
,r
=e
.helpers
.triggerCancellableEvent
,i
={};i
["jqueryui.Date"]=t
.extend({className
:"bbf-jui-date",initialize:function(e
){t
.prototype.initialize
.call(this,e
),this.value
&&!_
.isDate(this.value
)&&(this.value
=new Date(this.value
));if(!this.value
){var n
=new Date
;n
.setSeconds(0),n
.setMilliseconds(0),this.value
=n
}},render:function(){var e
=this.$el
;e
.html("<input>");var t
=$("input",e
);return t
.datepicker({dateFormat
:"dd/mm/yy",showButtonPanel
:!0}),this._observeDatepickerEvents(),i
["jqueryui.Date"].prototype.setValue
.call(this,this.value
),this},getValue:function(){var e
=$("input",this.el
),t
=e
.datepicker("getDate");return t
},setValue:function(e
){$("input",this.el
).datepicker("setDate",e
)},focus:function(){if(this.hasFocus
)return;this.$("input").datepicker("show")},blur:function(){if(!this.hasFocus
)return;this.$("input").datepicker("hide")},_observeDatepickerEvents:function(){var e
=this;this.$("input").datepicker("option","onSelect",function(){e
.trigger("change",e
)}),this.$("input").datepicker("option","onClose",function(){if(!e
.hasFocus
)return;e
.trigger("blur",e
)}),this.$("input").datepicker("option","beforeShow",function(){return e
.hasFocus
?{}:(e
.trigger("focus",e
),{})})}}),i
["jqueryui.DateTime"]=i
["jqueryui.Date"].extend({className
:"bbf-jui-datetime",template
:n("<select>{{hours}}</select> : <select>{{mins}}</select>"),render:function(){function e(e
){return e
<10?"0"+e
:e
}i
["jqueryui.Date"].prototype.render
.call(this);var t
=_
.range(0,24),n
=[];_
.each(t
,function(t
){n
.push('<option value="'+t
+'">'+e(t
)+"</option>")});var r
=this.schema
.minsInterval
||15,s
=_
.range(0,60,r
),o
=[];return _
.each(s
,function(t
){o
.push('<option value="'+t
+'">'+e(t
)+"</option>")}),this.$el
.append(this.template({hours
:n
.join(),mins
:o
.join()})),this._observeDatepickerEvents(),this.$hours
=$("select:eq(0)",this.el
),this.$mins
=$("select:eq(1)",this.el
),this.setValue(this.value
),this},getValue:function(){var e
=$("input",this.el
),t
=e
.datepicker("getDate");return t
.setHours(this.$hours
.val()),t
.setMinutes(this.$mins
.val()),t
.setMilliseconds(0),t
},setValue:function(e
){i
["jqueryui.Date"].prototype.setValue
.call(this,e
),this.$hours
.val(e
.getHours()),this.$mins
.val(e
.getMinutes())}}),i
["jqueryui.List"]=t
.extend({className
:"bbf-jui-list",template
:n(' <ul></ul> <div><button class="bbf-list-add">Add</div> '),itemTemplate
:n(' <li rel="{{id}}"> <span class="bbf-list-text">{{text}}</span> <div class="bbf-list-actions"> <button class="bbf-list-edit">Edit</button> <button class="bbf-list-del">Delete</button> </div> </li> '),editorTemplate
:n(' <div class="bbf-field"> <div class="bbf-list-editor"></div> </div> '),events
:{"click .bbf-list-add":"addNewItem","click .bbf-list-edit":"editItem","click .bbf-list-del":"deleteItem"},initialize:function(e
){t
.prototype.initialize
.call(this,e
);if(!this.schema
)throw"Missing required option 'schema'";this.schema
.listType
=this.schema
.listType
||"Text";if(this.schema
.listType
==="NestedModel"&&!this.schema
.model
)throw"Missing required option 'schema.model'"},render:function(){var e
=this.$el
;e
.html(this.template());var t
=this,n
=this.value
||[],r
=this.schema
,i
=this.itemToString
,s
=this.itemTemplate
,o
=$("ul",e
);return _
.each(n
,function(e
){var n
=i
.call(t
,e
),r
=$(s({id
:e
.id
||"",text
:n
}));$.data(r
[0],"data",e
),o
.append(r
)}),r
.sortable
!==!1&&(o
.sortable({axis
:"y",cursor
:"move",containment
:"parent"}),e
.addClass("bbf-list-sortable")),$("button.bbf-list-add",e
).button({text
:!1,icons
:{primary
:"ui-icon-plus"}}),$("button.bbf-list-edit",e
).button({text
:!1,icons
:{primary
:"ui-icon-pencil"}}),$("button.bbf-list-del",e
).button({text
:!1,icons
:{primary
:"ui-icon-trash"}}),this.hasFocus
&&this.trigger("blur",this),this},itemToString:function(e
){if(!e
)return e
;var t
=this.schema
;if(t
.itemToString
)return t
.itemToString(e
);if(this.schema
.listType
==="NestedModel"){var n
=new this.schema
.model(e
);return n
.toString()}return e
},addNewItem:function(e
){e
&&e
.preventDefault();var t
=this;this.openEditor(null,function(e
,n
){r(t
,"addItem",[e
,n
],function(){var r
=t
.itemToString(e
),i
=$(t
.itemTemplate({id
:e
.id
||"",text
:r
}));$.data(i
[0],"data",e
),$("ul",t
.el
).append(i
),$("button.bbf-list-edit",this.el
).button({text
:!1,icons
:{primary
:"ui-icon-pencil"}}),$("button.bbf-list-del",this.el
).button({text
:!1,icons
:{primary
:"ui-icon-trash"}}),t
.trigger("add",t
,e
),t
.trigger("item:change",t
,n
),t
.trigger("change",t
)})})},editItem:function(e
){e
.preventDefault();var t
=this,n
=$(e
.target
).closest("li"),i
=$.data(n
[0],"data");this.openEditor(i
,function(e
,i
){r(t
,"editItem",[e
,i
],function(){$(".bbf-list-text",n
).html(t
.itemToString(e
)),$.data(n
[0],"data",e
),t
.trigger("item:change",t
,i
),t
.trigger("change",t
)})})},deleteItem:function(e
){function u(){r(t
,"removeItem",[i
],function(){n
.remove(),t
.trigger("remove",t
,i
),t
.trigger("change",t
)})}e
.preventDefault();var t
=this,n
=$(e
.target
).closest("li"),i
=$.data(n
[0],"data"),s
=this.schema
.confirmDelete
?this.schema
.confirmDelete
:!1,o
=this.schema
.confirmDeleteMsg
||"Are you sure?";this.schema
.confirmDelete
?confirm(o
)&&u():u()},openEditor:function(t
,n
){var r
=this,i
=this.schema
,s
=i
.listType
||"Text",o
=e
.helpers
.createEditor(s
,{key
:"",schema
:i
,value
:t
}).render(),u
=this.editorContainer
=$(this.editorTemplate());$(".bbf-list-editor",u
).html(o
.el
);var a=function(){var e
=o
.validate();if(e
)return;n(o
.getValue(),o
),u
.dialog("close")},f=function(e
){if(e
.keyCode
!==13)return;a()};$(u
).dialog({resizable
:!1,modal
:!0,width
:500,title
:t
?"Edit item":"New item",buttons
:{OK
:a
,Cancel:function(){u
.dialog("close")}},close:function(){r
.editorContainer
=null,$(document
).unbind("keydown",f
),o
.remove(),u
.remove(),r
.trigger("item:close",r
,o
),r
.trigger("item:blur",r
,o
),r
.trigger("blur",r
)}}),this.trigger("item:open",this,o
),this.trigger("item:focus",this,o
),this.trigger("focus",this),$(document
).bind("keydown",f
)},getValue:function(){var e
=[];return $("li",this.el
).each(function(t
,n
){e
.push($.data(n
,"data"))}),e
},setValue:function(e
){this.value
=e
,this.render()},focus:function(){if(this.hasFocus
)return;var e
=this.$("li .bbf-list-edit").first();e
.length
>0?e
.click():this.addNewItem()},blur:function(){if(!this.hasFocus
)return;this.editorContainer
&&this.editorContainer
.dialog("close")}}),_
.extend(e
.editors
,i
)})()