Created
August 17, 2010 12:20
-
-
Save andreyvit/529665 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Exports a CSV list of Drupal fields. | |
// Run from any Drupal admin page, from JavaScript console in Safari or Chrome. | |
// Public domain. | |
function get_content_types(root){ | |
var r = []; | |
$('table.sticky-table tr', root).each(function() { | |
var label = $(this).find('td:nth-child(1)').text().replace(/^\s+|\s+$/, ''); | |
var name = $(this).find('td:nth-child(2)').text().replace(/^\s+|\s+$/, ''); | |
if (name != '') { | |
r.push({name: name, label:label}); | |
} | |
}); | |
return r; | |
}; | |
function get_fields(root){ | |
var r = []; | |
$('#content-field-overview tr', root).each(function() { | |
var label = $(this).find('td:nth-child(1) .thmr_call').text().replace(/^\s+|\s+$/, ''); | |
var name = $(this).find('td:nth-child(3) .thmr_call').text().replace(/^\s+|\s+$/, ''); | |
if (!$(this).find("td:nth-child(1) input").size() | |
&& !$(this).find('td:nth-child(3)').attr('colspan') && name != '') { | |
r.push({name: name, label:label}); | |
} | |
}); | |
return r; | |
}; | |
function format_result(ctype,fields) { | |
var s = ''; | |
fields.forEach(function(f) { s += ctype.name + "," + ctype.label + "," + f.name + "," + f.label + "\n"; }); | |
return s; | |
} | |
function load_iframe(ctype, callback) { | |
console.log("Loading " + ctype.name + "..."); | |
$("<iframe>").attr('src', '/admin/content/node-type/'+ctype.name+'/fields').appendTo($('body')).load(function() { | |
var s = format_result(ctype,get_fields($(this)[0].contentDocument)); | |
console.log(s); | |
$(this).remove(); | |
callback(s); | |
}); | |
} | |
console.log("Loading content types..."); | |
$("<iframe>").attr('src', '/admin/content/types').appendTo($('body')). load(function() { | |
var ctypes = get_content_types($(this)[0].contentDocument); | |
console.log("Content types: " + ctypes.map(function(ct) { return ct.name; }).join(", ")); | |
var total = ctypes.length, done = 0; | |
var grandS = ''; | |
ctypes.forEach(function(ctype) { | |
load_iframe(ctype, function(s) { | |
++done; | |
console.log(s); | |
console.log("" + done + " of " + total + " done."); | |
grandS += s; | |
if (done == total) { | |
console.log(""); | |
console.log(grandS); | |
} | |
}); | |
}); | |
$(this).remove(); | |
}); | |
undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment