-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.matrix.js
executable file
·1080 lines (837 loc) · 29.6 KB
/
jquery.matrix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* MySource Matrix Simple Edit Tools (jquery.matrix.js)
* version: 0.3.4 (OCT-18-2009)
* Copyright (C) 2009 Nicholas Hubbard
* @requires jQuery v1.3 or later
* @requires Trigger or Asset configuration in MySource Matrix
*
* Examples and documentation at: http://www.zedsaid.com/projects/simple-edit-tools
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
* Function that overrides page_on_load in limbo_outputter.inc.
* This is nessessary to allow Matrix to open a frame as a stand alone.
*
* @version $Revision: 0.1 $
*/
function page_on_load() {
SQ_DOCUMENT_LOADED = true;
};
(function ($) {
/**
* Plugin that allows Asset Builders to be submitted using Ajax.
* This is nessessary to allow Matrix to open a from as a stand alone.
*
* @version $Revision: 0.2.8
*/
$.fn.matrixForm = function (options) {
var defaults = {
findCreated: '',
findTarget: '',
loading: '',
errorArray: false,
errorSource: '',
errorMessage: 'Please correct the following errors:',
noFade: false,
onComplete: function () {}
};
var options = $.extend(defaults, options);
return this.each(function () {
var obj = $(this);
var itemHref = obj.attr('action');
obj.removeAttr('onsubmit');
// Check to see if we are using an asset builder or custom form
var form_type = $('#sq_commit_button', obj).length === 0;
// Find our submit button for custom forms
var form_submit = $("input[type='submit']", obj);
var form_submit_name = form_submit.attr('name');
var form_submit_val = form_submit.attr('value');
var form_submit_class = form_submit.attr('class');
// Check to see if we are uploading a file
if (obj.find('input:file')) {
$('#sq_commit_button').removeAttr('onclick');
// Choose if we should set click for asset builder or custom form
if (form_type) {
var set_click = 'ajax_submit';
// Hide the submit button
form_submit.hide();
// Add a new button
form_submit.after('<input id="ajax_submit" type="button" class="' + form_submit_class +'" name="' + form_submit_name +'" value="' + form_submit_val +'" />');
form_submit.remove();
// Creat our own submit string, since serialize won't grab it
var ajax_query = '&' + form_submit_name + '=' + form_submit_val;
} else {
var set_click = 'sq_commit_button';
}// End else
// Set our click function for commit button
$('#' + set_click).click(function () {
$('textarea[name^="news_item"], textarea[name^="calendar_event"]').each(function () {
var textId = $(this).attr('id');
$(this).val(eval('editor_' + textId + '.getHTML();'));
});
// Serialize all form data
var serializeForm = obj.serialize();
// Submit using Ajax
$.ajax({
type: 'POST',
url: itemHref,
data: serializeForm + ajax_query,
beforeSend: function () {
if (defaults.findTarget !== '') {
$(defaults.findTarget).show();
}
if (defaults.loading !== '') {
$('#' + set_click).after('<img id="loadingImage" src="' + defaults.loading + '" alt="Loading" />');
}
},
success: function (data) {
$('#loadingImage').remove();
if (defaults.findCreated !== '' && defaults.findTarget !== '') {
$(defaults.findTarget).html($(data).find(defaults.findCreated));
if (!defaults.noFade) {
setTimeout(function () {
$(defaults.findTarget).fadeOut('slow',
function () {
$(this).html('');
});
},5000
);// End timout
}// End if
}// End if
if (defaults.errorArray) {
// We don't want to create multiples
if ($('#errorsHiddenHold').length < 1) {
// Create a hidden div to hold our errors
$('body').append('<div id="errorsHiddenHold" style="display:none;"></div>');
}
// Add our content
$('#errorsHiddenHold').html($(data).find(defaults.errorSource));
// Create an array of our error messages
var arr_errors = new Array();
$('#errorsHiddenHold li').each(function() {
arr_errors.push($(this).text());
});
// Is array empty?
if (arr_errors.length < 1) {
var arry_empyty = true;
} else {
var arry_empyty = false;
}// End if
// Display alert if array is not empty
if (!arry_empyty) {
alert(defaults.errorMessage + '\n\n' + arr_errors.join('\n'));
} else {
// Since our array is empyty, our form must have been submitted correcty
defaults.onComplete.apply(obj, []);
}// End else
}// End if
}// End success
});// End Ajax
});// End Click
} else {
// We are using an asset builder for file uploads
// Use iframe if form is uploading a file
$('body').append('<iframe id="assetBuilderFrame" name="assetBuilderFrame" style="position:absolute; top:-1000px; left:-1000px;"></iframe>');
$('#assetBuilderFrame').attr('src', 'javascript:false;document.write("")');
obj.attr('target', 'assetBuilderFrame');
$('#sq_commit_button').click(function () {
obj.submit();
});// End click
}// End else
});// End each
};// End matirixForm
/**
* This Plugin filters a list of matched elements. Great when used with Asset Listings.
* Filter searching is similar to iTunes search.
*
* @version $Revision: 0.2
*/
$.fn.matrixFilter = function (options) {
var defaults = {
target: 'body',
count: true
};
var options = $.extend(defaults, options);
// Add our input field and counter
$(defaults.target).append('<input id="filter" type="text" /> <span id="count"></span>');
var obj = $(this);
var total = obj.length;
if (defaults.count) {
$('#count').text(total + ' of ' + total);
}// End if
$('#filter').keyup(function () {
var filter = $('#filter').val(),
count = 0;
obj.each(function () {
if ($(this).text().search(new RegExp(filter, 'i')) < 0) {
$(this).hide();
} else {
$(this).show();
count++;
}// End else
});// End each
if (defaults.count) {
$('#count').text(count + ' of ' + total);
}// End if
}); // End keyup
};// End matrixFilter
/**
* This Plugin is used to stay within the same page while opening Simple Edit pages.
* It creates an iframe, then opens URLs within the iframe.
*
* @version $Revision: 0.2
*/
$.fn.matrixFrame = function (options) {
var defaults = {
urlSuffix: '',
target: 'body'
};
var options = $.extend(defaults, options);
// Add our iFrame
$(defaults.target).append('<iframe name="assetEditFrame" id="assetEditFrame" scrolling="no" frameborder="0"></iframe>');
return this.each(function () {
var obj = $(this);
var itemHref = obj.attr('href');
obj.attr('target', 'assetEditFrame');
obj.attr('href', itemHref + defaults.urlSuffix);
});// End each
};// End matrixFrame
/**
* This Plugin will delete single or multiple assets using Ajax.
* Plugin requires the configuration of a Trigger to delete assets.
*
* @version $Revision: 0.3
*/
$.fn.matrixDelete = function (options) {
var defaults = {
multiple: false,
trigger: true,
checkboxClass: 'delete',
checkboxAfter: true,
urlSuffix: '?action=delete',
target: 'body',
simpleEdit: false,
ajaxStatus: false,
beforeComplete: function () {},
onComplete: function () {}
};
var options = $.extend(defaults, options);
if (defaults.multiple) {
$(defaults.target).append('<input id="massDelete" type="button" value="Delete Multiple" />');
}// End if
return this.each(function () {
var obj = $(this);
// Grab asset info
var itemDesc = obj.attr('rel');
var item_id = obj.attr('id');
// What screen should we load?
var item_screen = 'linking';
var ajax_status = defaults.ajaxStatus;
var complete = defaults.onComplete;
var asset_status = null;
// Remove simple edit url addition for links
if (!defaults.simpleEdit) {
var itemHref = obj.attr('href');
} else {
var itemHref = obj.attr('href').replace('/_edit', '');
obj.attr('href', itemHref);
}// End if
// Add our multiple delete checkbox
if (defaults.multiple) {
var deleteCheckbox = '<input id="multi_' + item_id +'" class="' + defaults.checkboxClass + '" type="checkbox" value="' + itemHref + '" />';
if (defaults.checkboxAfter) {
obj.after(deleteCheckbox);
} else {
obj.before(deleteCheckbox);
}// End else
}// End if
obj.click(function () {
// Be nice with our wording
if (!itemDesc === '') {
var question = confirm('Are you sure you want to delete "' + itemDesc + '"?');
} else {
var question = confirm('Are you sure you want to delete this?');
}// End else
if (question) {
// Run our custom callback
defaults.beforeComplete.apply(obj, []);
if (defaults.trigger) {
$.ajax({
type: 'POST',
url: itemHref + defaults.urlSuffix
});// End ajax
// Run our custom callback
defaults.onComplete.apply(obj, []);
} else {
// Looks like we are going to run this straight through the server, no triggers! Hooray!
get_locks(item_id, item_screen, ajax_status, asset_status, complete, obj);
}// End else
}// End if
return false;
});// End click
// Check to see if the user wants to delete multiples
if (defaults.multiple) {
$('#massDelete').unbind('click');
$('#massDelete').click(function () {
// Lets count how many items we are going to delete
var deleteCount = $('.' + defaults.checkboxClass + ':checked').length;
// Lets be kind with our wording
if (deleteCount <= 1) {
var deleteWord = 'item';
} else {
var deleteWord = 'items';
}// End if
if (deleteCount === 0) {
alert('Please select one or more assets to delete.');
return;
}
var answerDelete = confirm('You are about to delete ' + deleteCount + ' ' + deleteWord + ', are you sure you want to do this?');
// If the user confirms, continue
if (answerDelete) {
$('input:checked').each(function () {
// Run our custom callback
defaults.beforeComplete.apply($(this), []);
if (defaults.trigger) {
// Loop through each match and run a POST for that URL
$.ajax({
type: 'POST',
url: this.value + defaults.urlSuffix
});// End ajax
// Run our custom callback
defaults.onComplete.apply($(this), []);
} else {
// Set our correct object
obj = $(this);
// Looks like we are going to run this straight through the server, no triggers! Hooray!
get_locks($(this).attr('id'), item_screen, ajax_status, asset_status, complete, obj);
}// End else
});// End each
}// End if (answerDelete)
});// End click function
}// End if (defaults.multiple)
});// End each
};// End matrixDelete
/**
* This Plugin will clone the current asset and link to the same parent.
* Plugin requires the configuration of a Trigger to clone assets.
*
* @version $Revision: 0.2.8.1
*/
$.fn.matrixClone = function (options) {
var defaults = {
limit: 10,
urlSuffix: '?action=duplicate',
target: 'body',
beforeComplete: function () {},
onComplete: function () {},
onSelect: function () {}
};
var options = $.extend(defaults, options);
// Add our duplicate field and button
$(defaults.target).append('<input id="duplicateInput" type="text" value="" /> <input id="duplicateConfirm" type="button" value="Duplicate" />');
return this.each(function () {
var obj = $(this);
obj.click(function () {
var itemHref = obj.attr('href');
var itemDesc = obj.attr('rel');
$('#duplicateConfirm').unbind('click');
// Add our select callback
defaults.onSelect.apply(obj, []);
$('#duplicateConfirm').click(function () {
var duplicateVal = $('#duplicateInput').val();
// Check if it is a number
if (isNaN(duplicateVal)) {
alert('You have entered a value that is not a number. Please enter a number.');
$('#duplicateInput').val('');
return false;
}// End if
var dulicateCheck = parseInt(duplicateVal);
// Check our duplication limit
if (dulicateCheck <= defaults.limit) {
if (!itemDesc === '') {
var cloneAnswer = confirm('Are you sure you want duplicate "' + itemDesc + '" ' + dulicateCheck + ' times?');
} else {
var cloneAnswer = confirm('Are you sure you want duplicate this ' + dulicateCheck + ' times?');
}// End if
if (cloneAnswer) {
// Run our custom callback
defaults.beforeComplete.apply(obj, []);
for (var i = 1; i <= dulicateCheck; i++) {
$.ajax({
type: 'POST',
url: itemHref + defaults.urlSuffix
});// End ajax
}// End for loop
// Run our custom callback
defaults.onComplete.apply(obj, []);
}// End if
} else {
alert('You are limited to ' + defaults.limit + ' duplicates or less, please adjust your value.');
$('#duplicateInput').val('');
}// End else
}); // End DuplicateConfirm
return false;
}); // End obj.click
});// End each
};// End matrixClone
/**
* This Plugin will change the status of an asset.
* Plugin requires the configuration of a Trigger to clone assets.
*
* @version $Revision: 0.3
*/
$.fn.matrixStatus = function (options) {
var defaults = {
urlSuffix: '?action=live',
assetStatus: 'Live',
trigger: true,
ajaxStatus: false,
beforeComplete: function () {},
onComplete: function () {}
};
var options = $.extend(defaults, options);
// What screen should we load?
var item_screen = 'details';
return this.each(function () {
var obj = $(this);
var itemDesc = obj.attr('rel');
var itemHref = obj.attr('href');
var item_id = obj.attr('id');
var ajax_status = defaults.ajaxStatus;
var asset_status = defaults.assetStatus;
var complete = defaults.onComplete;
obj.click(function () {
// Make sure we want to change status
if (!itemDesc === '') {
var question = confirm('Are you sure you want to change the status of "'+itemDesc+'"?');
} else {
var question = confirm('Are you sure you want to change the status?');
}// End if
if (question) {
// Run our custom callback
defaults.beforeComplete.apply(obj, []);
if (defaults.trigger) {
$.ajax({
type: 'POST',
url: itemHref + defaults.urlSuffix
});// End ajax
// Run our custom callback
defaults.onComplete.apply(obj, []);
} else {
// No triggers! Heck yes!
get_locks(item_id, item_screen, ajax_status, asset_status, complete, obj);
}// End else
}// End if
return false;
});// End click
});// End each
};// End matrixStatus
/**
* This Plugin is VERY experimental and hardly even functional.
* It is used to edit text inline and POST back using ajax.
* Current page URL, %asset_url% must be passed to function
* Work in progress!!
* Plugin requires the configuration of a Trigger to work.
*
* @version $Revision: 0.1
*/
$.fn.matrixEdit = function (options) {
var defaults = {
//None yet
};
var options = $.extend(defaults, options);
return this.each(function () {
var obj = $(this);
obj.click(function () {
obj.attr('contentEditable', 'true').css('background-color', '#ccc');
});// End click
obj.blur(function () {
obj.attr('contentEditable', 'false').css('background-color', '#fff');
});// End blur
$('#save').click(function () {
var saveContent = obj.html();
var currentHref = defaults.currentPage;
$.ajax({
type: 'POST',
url: location.href,
data: '?action=change&details=' + saveContent
});// End ajax
});// End click
});// End each
};// End matrixEdit
})(jQuery);
/**
* Function that cleans the input leaving just the asset id
*
* @param string item_id The id of the asset we are getting locks for
*
* @access public
*/
function clean_id(item_id) {
return item_id.replace(/[^0-9]/g, '');
}// End clean_id
/**
* Function to check for any errors with the asset id
*
* @param string item_id The id of the asset we are getting locks for
*
* @access public
*/
function check_errors(item_id) {
// Everything depends on the ID, so we need to check that we have it
var item_id = clean_id(item_id);
if (isNaN(item_id) || item_id === '' || item_id === undefined) {
alert('The asset ID that was passed does not appear to be a number, please check the ID you are passing.'+
'\n\n See documentation for the correct usage: www.zedsaid.com/jquery-matrix');
return true;
}
}// End check_errors
/**
* Function that returns an ajax error
*
* @param string xhr The response code that we get back
* @param string ajaxOptions Extra options
* @param string errorThrown The error the is thrown
*
* @access public
*/
function ajax_error(xhr, ajaxOptions, errorThrown) {
if (xhr.status === 302) {
alert('You do not have permissions to this asset. Please log into MySource Matrix');
} else {
alert('You must be logged into MySource Matrix in order to complete this action.');
}
console.log(errorThrown);
}// End ajax_error
/**
* Function to check the progress of a hippo job
*
* @param string item_id The id of the asset we are getting locks for
* @param string percent_done The percentage of progress for our hippo
* @param string submitted_hippo_url The url of our hippo job
* @param boolean ajax_status True or False if we want to show the status
* @param function complete The functin that we use for our callback
* @param object obj The jQuery object that we pass to our callback
*
* @access public
*/
function progress(item_id, percent_done, submitted_hippo_url, ajax_status, complete, obj) {
debug('progress', 1);
if (percent_done >= 100 || isNaN(percent_done)) {
// Remove ajax_status one we are finished with the hippo
$('#' + item_id).next('.ajax_status').remove();
// Run our onComplete callback
complete.apply(obj, []);
return;
} else {
$.ajax({
url: submitted_hippo_url,
type: 'POST'
});// End ajax
// Call our function again until we find 100
submit_hippo(item_id, submitted_hippo_url, ajax_status, complete, obj);
}// End else
}// End progress
/**
* Function to submit a hippo job using the hippo url that is passed
*
* @param string item_id The id of the asset we are getting locks for
* @param string submitted_hippo_url The url of our hippo job
* @param boolean ajax_status True or False if we want to show the status
* @param function complete The functin that we use for our callback
* @param object obj The jQuery object that we pass to our callback
*
* @access public
*/
function submit_hippo(item_id, submitted_hippo_url, ajax_status, complete, obj) {
debug('submit_hippo function', 1);
$.ajax({
url: submitted_hippo_url,
type: 'GET',
success: function(data){
var percent_done = parseInt($('.sq-hipo-header-progress-bar-percent', data).text().replace(/[^0-9]/g, ''));
var status_message = 'Hippo is at ' + percent_done +'%';
status(item_id, status_message, ajax_status);
// Run our function that checks the hippo progress
progress(item_id, percent_done, submitted_hippo_url, ajax_status, complete, obj);
}// End success
});// End ajax
}// End submit_hippo
function process_hippo(item_id, screen_url, main_form, hippo_url, ajax_status, complete, obj, linking_data) {
debug('process_hippo function', 1);
var status_message = 'Building data';
status(item_id, status_message, ajax_status);
var form_action = main_form.attr('action');
$.ajax({
url: form_action,
data: linking_data,
type: 'POST',
error: ajax_error,
beforeSend: function() {
var status_message = 'Submitting hippo job';
status(item_id, status_message, ajax_status);
},
success: function(hippo) {
// What screen are we using
var current_screen = screen_url.split('asset_ei_screen=');
current_scrren = current_screen[1];
if (current_scrren === 'details') {
var status_message = 'Status changed successfully';
status(item_id, status_message, ajax_status);
// Run our onComplete callback
complete.apply(obj, []);
return;
}// End if
hippo = '<div>' + hippo + '</div>';
var submitted_hippo = $(hippo).html();
// Find our hippo URL
var submitted_hippo = submitted_hippo.split('?SQ_ACTION=hipo');
// Check to see if we actually have a hippo
if (submitted_hippo[1] === undefined) {
var status = 'There has been a hippo error, please check the hippo herder.';
debug(status, 4);
var status_message = 'Hippo Error';
status(item_id, status_message, ajax_status);
alert(status);
return;
}// End if
var submitted_hippo = submitted_hippo[1].split('&SQ_BACKEND_PAGE');
var submitted_hippo_url = hippo_url + submitted_hippo[0];
$.ajax({
url: submitted_hippo_url,
type: 'POST',
error: ajax_error,
success: function () {
// Run our function to submit the hippo
submit_hippo(item_id, submitted_hippo_url, ajax_status, complete, obj);
}// End success
});// End ajax
}// End success
});// End ajax
}// End process_hippo
/**
* Function will update the status when each ajax call is run
*
* @param string item_id The id of the asset we are getting locks for
* @param string status_message The status message that we are sending
* @param boolean ajax_status True or False if we want to show the status
*
* @access public
*/
function status(item_id, status_message, ajax_status) {
debug('status function', 1);
if (ajax_status) {
// We need to set where out status will be
$('#' + item_id).next('.ajax_status').remove();
$('#' + item_id).after('<span class="ajax_status">' + status_message + '</span>');
}// End if
}// End details_screen
/**
* Function that gets data and posts to the linking screen of an asset
*
* @param string item_id The id of the asset we are getting locks for
* @param string screen_url The url of the screen we are getting
* @param object main_form jQuery selector of our main form
* @param string hippo_url The url of the current hippo job
* @param boolean ajax_status True or False if we want to show the status
* @param function complete The functin that we use for our callback
* @param object obj The jQuery object that we pass to our callback
* @param string asset_status The status that we are to set the asset to
*
* @access public
*/
function details_screen(item_id, screen_url, main_form, hippo_url, ajax_status, complete, obj, asset_status) {
debug('details_screen function', 1);
// Lets see what status means in numerical values
if (asset_status === 'Live') {
var status_code = 16;
} else if (asset_status === 'Safe Edit') {
var status_code = 64;
} else if (asset_status === 'Under Construction') {
var status_code = 2;
} else {
var status = 'The status you are trying to set it not supported!';
debug(status, 4);
alert(status);
}
$.ajax({
url: screen_url,
type: 'GET',
error: ajax_error,
beforeSend: function() {
var status_message = 'Getting details screen info';
status(item_id, status_message, ajax_status);
},
success: function(response){
response = '<div>' + response + '</div>';
var main_form_hippo = $('#main_form', response);
// Submit the hippo
var arr_screen = new Array();
main_form_hippo.find('input, select').each(function() {
if ($(this).attr('id').indexOf('_change_status') !== -1 && this.tagName === 'SELECT') {
arr_screen.push($(this).attr('name') + '=' + status_code);
} else {
arr_screen.push($(this).attr('name') + '=' + $(this).val());
}// End else
});// End each
// Serialize this crazy stuff
var linking_data = arr_screen.join('&');
// Start to process our hippo job
process_hippo(item_id, screen_url, main_form, hippo_url, ajax_status, complete, obj, linking_data);
}// End success
});// End ajax
}// End details_screen
/**
* Function that gets data and posts to the linking screen of an asset
*
* @param string item_id The id of the asset we are getting locks for
* @param string screen_url The url of the screen we are getting
* @param object main_form jQuery selector of our main form
* @param string hippo_url The url of the current hippo job
* @param boolean ajax_status True or False if we want to show the status
* @param function complete The functin that we use for our callback
* @param object obj The jQuery object that we pass to our callback
*
* @access public
*/
function linking_screen(item_id, screen_url, main_form, hippo_url, ajax_status, complete, obj) {
debug('linking_screen function', 1);
$.ajax({
url: screen_url,
type: 'GET',
error: ajax_error,
beforeSend: function() {
var status_message = 'Getting linking screen info';
status(item_id, status_message, ajax_status);
},
success: function(response){
response = '<div>' + response + '</div>';
var main_form_hippo = $('#main_form', response);
// Submit the hippo
var arr_screen = new Array();
main_form_hippo.find('input, select').each(function() {
if ($(this).attr('id').indexOf('delete_linkid') !== -1) {
arr_screen.push($(this).attr('name') + '=SQ_CRON_JOB_FUTURE_LINEAGE_DELETE_ALL_LINKS');
} else {
arr_screen.push($(this).attr('name') + '=' + $(this).val());
}// End else
});// End each
// Serialize this crazy stuff
var linking_data = arr_screen.join('&');
// Start to process our hippo job
process_hippo(item_id, screen_url, main_form, hippo_url, ajax_status, complete, obj, linking_data);
}// End success
});// End ajax
}// End linking_screen
/**
* Function to get the locks on an asset screen
*
* @param string item_id The id of the asset we are getting locks for
* @param string item_screen The screen that we are to get from the backend
* @param boolean ajax_status True or False if we want to show the status
* @param function complete The functin that we use for our callback
* @param object obj The jQuery object that we pass to our callback
*
* @access public
*/
function get_locks(item_id, item_screen, ajax_status, asset_status, complete, obj) {
debug('get_locks function', 1);
// Everything depends on the ID, so we need to check that we have it
if (check_errors(item_id)) {
debug('Not a valid asset ID', 4);
return;
}// End if
// Find out what site we are at
var site_url = location.protocol + '//' + location.host;
var hippo_url = site_url + '?SQ_ACTION=hipo';
var screen_url = site_url + '/_admin/?SQ_BACKEND_PAGE=main&backend_section=am&am_section=edit_asset&assetid=' + clean_id(item_id) + '&asset_ei_screen=' + item_screen;
// Find current asset path and stuff
$.ajax({
url: screen_url,
type: 'GET',
error: ajax_error,
beforeSend: function() {
var status_message = 'Checking to see if we need locks';
status(item_id, status_message, ajax_status);
},
success: function(html){
// jQuery bug, lets wrap the entire html in a div
html = '<div>' + html + '</div>';
// Get our form infoa
var main_form = $('#main_form', html);
var form_action = main_form.attr('action');
// What is our current asset status
var current_status = $(".sq-backend-data img", html).next('i:first').text();
if (current_status === asset_status) {
debug('You are tying to set the same status that the asset is', 4);
// Remove status from DOM and alert the user
$('#' + item_id).next('.ajax_status').remove();
alert('Asset ID:' + clean_id(item_id) + ' currently has the status of ' + current_status + '. You are tring set this same status.');
return;
}
// We should check if we already have the locks
if (main_form.find("input[value='Acquire Lock(s)']")) {