/*
  backgrid-text-cell
  http://github.com/wyuenho/backgrid

  Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
  Licensed under the MIT @license.
*/
!function(a,b){"function"==typeof define&&define.amd?
// AMD. Register as an anonymous module.
define(["underscore","backgrid"],b):"object"==typeof exports?
// CommonJS
module.exports=b(require("underscore"),require("backgrid")):
// Browser globals
b(a._,a.Backgrid)}(this,function(a,b){/**
     Renders a form with a text area and a save button in a modal dialog.

     @class Backgrid.Extension.TextareaEditor
     @extends Backgrid.CellEditor
  */
var c=b.Extension.TextareaEditor=b.CellEditor.extend({/** @property */
tagName:"div",/** @property */
className:"modal fade",/** @property {function(Object, ?Object=): string} template */
template:function(a){return'<div class="modal-dialog"><div class="modal-content"><form><div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button><h3>'+a.column.get("label")+'</h3></div><div class="modal-body"><textarea cols="'+a.cols+'" rows="'+a.rows+'">'+a.content+'</textarea></div><div class="modal-footer"><input class="btn btn-primary" type="submit" value="Save"/></div></form></div></div>'},/** @property */
cols:80,/** @property */
rows:10,/** @property */
events:{"keydown textarea":"clearError",submit:"saveOrCancel","hide.bs.modal":"saveOrCancel","hidden.bs.modal":"close","shown.bs.modal":"focus"},/**
       @property {Object} modalOptions The options passed to Bootstrap's modal
       plugin.
    */
modalOptions:{backdrop:!1},/**
       Renders a modal form dialog with a textarea, submit button and a close button.
    */
render:function(){return this.$el.html($(this.template({column:this.column,cols:this.cols,rows:this.rows,content:this.formatter.fromRaw(this.model.get(this.column.get("name")))}))),this.delegateEvents(),this.$el.modal(this.modalOptions),this},/**
       Event handler. Saves the text in the text area to the model when
       submitting. When cancelling, if the text area is dirty, a confirmation
       dialog will pop up. If the user clicks confirm, the text will be saved to
       the model.

       Triggers a Backbone `backgrid:error` event from the model along with the
       model, column and the existing value as the parameters if the value
       cannot be converted.

       @param {Event} e
    */
saveOrCancel:function(b){b&&"submit"==b.type&&(b.preventDefault(),b.stopPropagation());var c=this.model,d=this.column,e=this.$el.find("textarea").val(),f=this.formatter.toRaw(e);a.isUndefined(f)?(c.trigger("backgrid:error",c,d,e),b&&(b.preventDefault(),b.stopPropagation())):!b||"submit"==b.type||"hide"==b.type&&f!==(this.model.get(this.column.get("name"))||"").replace(/\r/g,"")&&confirm("Would you like to save your changes?")?(c.set(d.get("name"),f),this.$el.modal("hide")):"hide"!=b.type&&this.$el.modal("hide")},/**
       Clears the error class on the parent cell.
     */
clearError:a.debounce(function(){a.isUndefined(this.formatter.toRaw(this.$el.find("textarea").val()))||this.$el.parent().removeClass("error")},150),/**
       Triggers a `backgrid:edited` event along with the cell editor as the
       parameter after the modal is hidden.

       @param {Event} e
    */
close:function(a){var c=this.model;c.trigger("backgrid:edited",c,this.column,new b.Command(a))},/**
       Focuses the textarea when the modal is shown.
    */
focus:function(){this.$el.find("textarea").focus()}});/**
     TextCell is a string cell type that renders a form with a text area in a
     modal dialog instead of an input box editor. It is best suited for entering
     a large body of text.

     @class Backgrid.Extension.TextCell
     @extends Backgrid.StringCell
  */
b.Extension.TextCell=b.StringCell.extend({/** @property */
className:"text-cell",/** @property  */
editor:c})});