newItemModal.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. define(['plugins/dialog', 'knockout', 'knockout.validation'], function (dialog, ko, ko_validation) {
  2. ko.validation = ko_validation;
  3. var NewItemModal = function() {
  4. var self = this;
  5. self.input = ko.observable('').extend({
  6. required: true,
  7. pattern: {
  8. message : 'The name must not contain a \'/\'',
  9. params : '^[^/]+$'
  10. }
  11. });
  12. self.typeItem = ko.observable('file');
  13. self.form = ko.validatedObservable( {input: self.input} );
  14. self.isValid = ko.computed(function() {
  15. return self.form.isValid();
  16. });
  17. };
  18. NewItemModal.prototype.ok = function() {
  19. dialog.close(this, { name: this.input(), type: this.typeItem()});
  20. };
  21. NewItemModal.prototype.close = function() {
  22. dialog.close(this);
  23. };
  24. NewItemModal.show = function(defaultValue){
  25. return dialog.show(new NewItemModal(defaultValue));
  26. };
  27. return NewItemModal;
  28. });