public
Description: This project, written by Nic Hubbard, is a jQuery Plugin for MySource Matrix, allowing for quick and easy implementation of Simple Edit tools using ajax, triggers, and asset processors.
Homepage: http://www.zedsaid.com/projects
Clone URL: git://github.com/nnhubbard/matrix-jquery-tools.git
Click here to lend your support to: matrix-jquery-tools and make a donation at www.pledgie.com !
matrix-jquery-tools / jquery.matrixMap.js
100644 212 lines (163 sloc) 5.872 kb
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
/**
* MySource Matrix Simple Edit Tools (jquery.matrixMap.js)
* version: 0.1 (MAY-05-2009)
* Copyright (C) 2009 Nicholas Hubbard
* @requires jQuery v1.3 or later
*
* 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 ($) {
 
 
/**
* Plugin that allows you to browse the MySource Matrix asset tree structure.
* This is beneficial sometimes as you can bypass the java asset map.
* It sends XML to Matrix, then receives an XML response.
* Demo: http://www.puc.edu/dev/jquery-matrix-test-suite/matrix-map
*
* @version $Revision: 0.1
*/
$.fn.matrixMap = function (options) {
var defaults = {
root: 1,
showChildren: false
};
 
var options = $.extend(defaults, options);
 
var obj = $(this);
 
// We need to grab our parent first
var parent = true;
 
// Find out what site we are at
var proto = location.protocol;
var site = location.host;
var host_url = proto + '//' + site + '?SQ_ACTION=asset_map_request';
 
// Construct our XML to send
var xml_get = '<command action="get assets"><asset assetid="' + defaults.root + '" start="0" limit="150" linkid="10" /></command>';
 
// Create our element
obj.append('<ul id="map_root"></ul>');
 
// Create a dummy var
var current_asset;
 
// Get our children
get_children(host_url, xml_get, parent, current_asset);
 
// Lets click our parents to show their children
$('#map_root li a').live('dblclick', function(){
 
// Get our current asset
var current_asset = $(this);
var sub_root = $(this).attr('id').replace('a', '');
 
// Build our tree
parent = false;
get_children(host_url, xml_get, parent, current_asset, sub_root);
 
return false;
 
});// End live dblclick
 
$('#map_root li a.asset_name').live('click', function(){
 
// Set our color when clicked
var attr_stat = $(this).attr('status');
 
if (attr_stat === '16') {
//$(this).addClass('live');
} else if (attr_stat === '2') {
//$(this).addClass('construction');
}
 
});// End live click
 
};// End matrixMap
 
})(jQuery);
 
 
function expand(current_asset, sub_root) {
 
// Check to see if we already have a class
if (current_asset.hasClass('children')) {
current_asset.removeClass('children');
// Hide our tree
current_asset.parent().next('ul').hide();
 
} else {
 
// This must meen that we can expand, so add a class
current_asset.addClass('children');
// Let it know that we have expanded so we don't have to load again
current_asset.parent('li').addClass('cache');
 
}// End else
 
}// End build_tree
 
 
function get_children(host_url, xml_get, parent, current_asset, sub_root) {
 
if (!parent) {
// Create a new list
current_asset.parent().after('<ul></ul>');
 
// What do we add it to?
var target = current_asset.parent().next();
 
// Construct our XML to send
xml_get = '<command action="get assets"><asset assetid="' + sub_root + '" start="0" limit="150" linkid="10" /></command>';
 
// Check if we need to even get kids
expand(current_asset, sub_root);
 
// If we have already expanded the children we don't want to load the tree again
if (current_asset.hasClass('cache')) {
//return;
}
 
} else {
 
// What do we add it to?
var target = '#map_root';
}
 
// Set somes image vars
var type_2_path = '/__lib/web/images/icons/asset_map/not_visible.png';
var type_2_image = '<img class="type_2" src="' + type_2_path + '" />';
 
// Create our ajax to send the XML
$.ajax({
url: host_url,
type: 'POST',
processData: false,
data: xml_get,
contentType: "text/xml",
dataType: 'xml',
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log(XMLHttpRequest + textStatus + errorThrown);
},
beforeSend: function () {
if (!parent) {
current_asset.parent().after('<ul class="loading"><li>Loading...</li></ul>');
}
},
success: function(xml) {
// Remove loading
$('.loading').remove();
// Check each asset that we find
$(xml).find('asset').each(function() {
// Only include asset tags with attributes
if ($(this).attr('assetid') > 0) {
// Set some of our vars that will populate our asset map
var asset_id = unescape($(this).attr('assetid'));
var asset_status = $(this).attr('status');
var asset_link_type = parseInt($(this).attr('link_type'));
var asset_type_code = $(this).attr('type_code');
var asset_num_kids = parseInt($(this).attr('num_kids'));
var asset_name = unescape($(this).attr('name')).replace(/\+/g, ' ');
// See what kind of link type we have
if (asset_link_type === 2) {
// Type 2 link
var asset_image = '<img class="asset_image" src="/__data/asset_types/' + asset_type_code + '/icon.png" />';
asset_image = type_2_image + asset_image;
} else {
// Type 1 link
var asset_image = '<img src="/__data/asset_types/' + asset_type_code + '/icon.png" />';
}
 
// See if we have kids
if (asset_num_kids > 0) {
var indicate_kids = 'kids_closed';
} else {
var indicate_kids = '';
}
$('<li></li>').html('<a href="#" class="icon_hold">' + asset_image + '</a><a id="a' + asset_id + '" href="#" >' + asset_name + '</a>')
.appendTo(target)
.addClass(indicate_kids)
.children('a:last')
.attr({
id: asset_id,
status: asset_status,
link_type: asset_link_type,
type_code: asset_type_code,
num_kids: asset_num_kids,
name: asset_name
})
.addClass('asset_name');
 
}// End if
 
});// End each
 
// Set our first/last class
$('ul li:first').addClass('first');
$('ul li:last').addClass('last');
 
}// End success
 
});// End ajax
 
}// End get_children