Files
dss/static/js/libs/backgrid/extensions/text-cell/backgrid-text-cell.min.js
2013-06-19 19:24:50 +01:00

8 lines
1.9 KiB
JavaScript
Executable File

/*
backgrid-text-cell
http://github.com/wyuenho/backgrid
Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
Licensed under the MIT @license.
*/
(function(e,t,o,a,s){var i=s.Extension.TextareaEditor=s.CellEditor.extend({tagName:"div",className:"modal hide fade",template:o.template('<form><div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button><h3><%- column.get("label") %></h3></div><div class="modal-body"><textarea cols="<%= cols %>" rows="<%= rows %>"><%- content %></textarea></div><div class="modal-footer"><input class="btn" type="submit" value="Save"/></div></form>'),cols:80,rows:10,events:{"keydown textarea":"clearError",submit:"saveOrCancel",hide:"saveOrCancel",hidden:"close",shown:"focus"},modalOptions:{backdrop:!1},render:function(){return this.$el.html(t(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},saveOrCancel:function(t){t&&t.type=="submit"&&(t.preventDefault(),t.stopPropagation());var a=this.model,s=this.column,i=this.$el.find("textarea").val(),l=this.formatter.toRaw(i);o.isUndefined(l)?(a.trigger("backgrid:error",a,s,i),t&&(t.preventDefault(),t.stopPropagation())):!t||t.type=="submit"||t.type=="hide"&&l!==(this.model.get(this.column.get("name"))||"").replace(/\r/g,"")&&e.confirm("Would you like to save your changes?")?(a.set(s.get("name"),l),this.$el.modal("hide")):t.type!="hide"&&this.$el.modal("hide")},clearError:o.debounce(function(){o.isUndefined(this.formatter.toRaw(this.$el.find("textarea").val()))||this.$el.parent().removeClass("error")},150),close:function(e){var t=this.model;t.trigger("backgrid:edited",t,this.column,new s.Command(e))},focus:function(){this.$el.find("textarea").focus()}});s.Extension.TextCell=s.StringCell.extend({className:"text-cell",editor:i})})(window,jQuery,_,Backbone,Backgrid);