-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding edit name and value of environment parameters
- Loading branch information
Showing
7 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(function($) { | ||
$.PMX.EditParameter = function($el, options) { | ||
var base = this; | ||
|
||
base.$el = $el; | ||
base.xhr = null; | ||
|
||
base.defaultOptions = { | ||
fieldSelector: 'dt.variable-name label', | ||
editSelector: 'dt.variable-name a.edit-action', | ||
formSelector: 'dd.actions', | ||
inputKey: 'input[data-index=name_%]', | ||
submitButton: '.service-details form input[type=submit]' | ||
}; | ||
|
||
base.init = function () { | ||
base.options = $.extend({}, base.defaultOptions, options); | ||
base.bindEvents(); | ||
}; | ||
|
||
base.bindEvents = function () { | ||
base.$el.on('click', base.options.editSelector, base.handleEdit); | ||
}; | ||
|
||
base.handleEdit = function(e) { | ||
var $target = $(e.currentTarget), | ||
$parent = $target.parent(); | ||
|
||
e.preventDefault(); | ||
$parent.css('display', 'none'); | ||
|
||
(new $.PMX.ContentEditable(base.$el.find(base.options.fieldSelector), | ||
{ | ||
identifier: $parent.val(), | ||
onRevert: base.handleRevert, | ||
editorPromise: base.completeEdit | ||
})).init(); | ||
}; | ||
|
||
base.handleRevert = function(e) { | ||
(base.$el.find(base.options.editSelector).parent())[0].style.cssText = ''; | ||
}; | ||
|
||
base.completeEdit = function(data) { | ||
var transaction = $.Deferred(), | ||
index = base.$el.find(base.options.fieldSelector).attr('data-index'), | ||
field = base.$el.find(base.options.formSelector).find(base.options.inputKey.replace('%', index)).first(); | ||
|
||
field.val(data.text); | ||
$(base.options.submitButton).removeAttr('disabled'); | ||
|
||
transaction.resolve(); | ||
|
||
return transaction.promise(); | ||
}; | ||
|
||
}; | ||
|
||
$.fn.editParameter = function(options){ | ||
return this.each(function(){ | ||
(new $.PMX.EditParameter($(this), options)).init(); | ||
}); | ||
}; | ||
|
||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.service-details | ||
%dl.entries | ||
%dt.variable-name | ||
%label{ data: { index: '0' } } | ||
Variable | ||
.actions | ||
%a{ class: 'edit-action' } | ||
%dd.actions | ||
%input{ type: 'hidden', value: 'test', data: { index: 'name_0' } } | ||
%form | ||
%input{ type: 'submit', disabled: true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
describe('$.fn.editParameter', function() { | ||
var subject, element; | ||
|
||
beforeEach(function() { | ||
fixture.load('edit-parameter.html'); | ||
element = $('dl.entries'); | ||
subject = new $.PMX.EditParameter(element); | ||
subject.init(); | ||
}); | ||
|
||
describe('on click', function() { | ||
it('prevents default', function() { | ||
var edit_button = $('.edit-action'), | ||
clickEvent = $.Event('click'); | ||
|
||
edit_button.trigger(clickEvent); | ||
expect(clickEvent.isDefaultPrevented()).toBeTruthy(); | ||
}); | ||
|
||
it('initializes content editable', function() { | ||
var clickEvent = $.Event('click'); | ||
|
||
$('.edit-action').trigger(clickEvent); | ||
expect($('.content-editable').length).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe('on edit', function() { | ||
it('sets edited value on hidden field', function() { | ||
subject.completeEdit({text: 'New Value'}); | ||
|
||
expect($('input[data-index=name_0]').val()).toBe('New Value') | ||
}); | ||
|
||
it('enabled the submit button', function() { | ||
$('form input').attr('disabled', true); | ||
subject.completeEdit({text: 'New Value'}); | ||
|
||
expect($('form input').attr('disabled')).toBeUndefined() | ||
}) | ||
}); | ||
}); |