Test Failed
Push — master ( 357bf5...71cdad )
by Russell
03:53
created

external-content/javascript/ExternalContent.jquery.js   A

Complexity

Total Complexity 10
Complexity/F 1.43

Size

Lines of Code 45
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 25
c 0
b 0
f 0
dl 0
loc 45
rs 10
mnd 3
bc 3
fnc 7
bpm 0.4285
cpm 1.4285
noi 4
1
2
/**
3
 * jQuery functionality used on the external content admin page
4
 */
5
6
;(function ($, pt) {
7
	$().ready(function () {
8
		$('#Form_EditForm').bind('PageSaved', function (e, b, d) {
9
			var pageID = $('#Form_EditForm_ID').val();
10
			pt('sitetree').getTreeNodeByIdx(pageID).ajaxExpansion();
11
		});
12
13
			// bind the migrate form so we can properly handle a migrate
14
			$('#Form_EditForm_Migrate').livequery(function () {
15
				$(this).click(function () {
16
					// we don't want this to be submitted via the edit form, as we want to do an ajax postback for this
17
					// and not tie up the response.
18
					var form = $(this).parents('form');
19
					// wrap it all up and post away!
20
					var params = form.serializeArray();
21
					var postParams = {};
22
					$.each(params, function (index) {
23
						postParams[this.name] = this.value;
24
					});
25
26
					postParams['action_migrate'] = true;
27
					statusMessage('Importing ...', 2);
28
29
					$.post(form.attr('action'), postParams, function (data) {
30
31
						if (data) {
32
							var response = $.parseJSON(data);
33
							if (response && response.status) {
34
								statusMessage(response.message, 'good');
35
							} else {
36
								statusMessage("There was a problem with the import");
37
							}
38
						}
39
						// reset the base form
40
						if (pt) {
41
							pt(form.attr('id')).resetElements();
42
						}
43
					});
44
					return false;
45
				});
46
47
			});
48
49
	});
50
})(jQuery, $);
51