var MENU_WIDTH = 371; // Array Remove - By John Resig (MIT Licensed) Array.prototype.remove = function(from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); }; function initialiseWidgets(newRecord) { hideModelPanel(); initialiseHTMLFields(); initialiseMultipleSelectFields(); initialiseEmbeddedFields(); addClearLinks(); if(newRecord) setDateTimeFieldsToNow(); } var blankRecords = {}; function initialiseEmbeddedFields() { blankRecords = {}; $('.field-type-many_embedded .blank-record').each(function(index, record) { var blankRecord = $(record); blankRecord.hide(); blankRecord.removeClass('blank-record'); blankRecords[$(record).closest('.contains-field-type-many_embedded').attr('data-field-name')] = blankRecord.detach(); }); } function setDateTimeFieldsToNow() { // TODO: should check that each field is blank first before setting; a default value may have been set var now = new Date(); $('#record_form select[name*="[day]"]').val(now.getDate()); $('#record_form select[name*="[month]"]').val(now.getMonth() + 1); $('#record_form select[name*="[year]"]').val(now.getFullYear()); $('#record_form select[name*="[hour]"]').val(now.getHours()); $('#record_form select[name*="[min]"]').val(now.getMinutes()); } function initialiseHTMLFields() { if($('.list').length) { var width = '320px'; var row1 = 'bold,italic,underline,strikethrough,sub,sup,charmap,|,justifyleft,justifycenter,justifyright,justifyfull'; var row2 = 'formatselect,fontsizeselect,|,bullist,numlist,outdent,indent,blockquote'; var row3 = 'link,unlink,|,code'; } else { var width = '100%'; var row1 = 'bold,italic,underline,strikethrough,sub,sup,charmap,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontsizeselect,|,bullist,numlist,outdent,indent,blockquote,|,link,unlink,|,code'; var row2 = ''; var row3 = ''; } $('textarea.html').each(function(index, field) { $(field).tinymce({ script_url : '/admin/tiny_mce/tiny_mce.js', theme : "advanced", plugins : "safari,inlinepopups,paste", width: width, height: '200', theme_advanced_blockformats: 'p,h1,h2,h3', theme_advanced_buttons1 : row1, theme_advanced_buttons2 : row2, theme_advanced_buttons3 : row3, theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "none", theme_advanced_resizing : false }); }); } function initialiseMultipleSelectFields() { $('select[multiple=multiple]').chosen(); } function addClearLinks() { $('#record_form .field-type-attachment p, #record_form .field-type-image p').each(function(index, p) { var clear = $('clear'); $(p).append(clear); if($(p).find('span').html() == 'none') clear.hide(); }); } $('#admin_save button').click(function(event) { $('#admin_save_spinner').fadeIn().delay(1000).fadeOut(); $('#admin_save_success').delay(1500).fadeIn().delay(2000).fadeOut(); }); var menus = {}; function showMenu(parentName, recordID, initialLoad) { if(menus[recordID]) { pushNavigationPanel(parentName, menus[recordID]); } else { jQuery.getJSON(jsonURL + '?id=' + recordID, function(data) { menus[recordID] = data; pushNavigationPanel(parentName, data, initialLoad); highlightSelectedRow(recordID); }); } } var NEW_ROW = '

New

'; function constructRecordListItem(tree) { // add the icon, name, slide and delete icons var list = '
  • '; // the h1 contains the content elements for each record if(tree.menu_root) list += '

    '; else list += '

    '; // add space for any children underneath this record var canHaveChildren = (types[tree.type].validChildren.length > 0 && !tree.menu_root); var hasChildren = (tree.children && tree.children.length > 0); if(!tree.root) { list += '
    '; } // add the slider, delete and drag handle icons if necessary list += '

    ' + tree.name + '

    '; if(tree.menu_root) list += '
    '; if(!tree.root) list += '
    '; if(canHaveChildren) { list += '
    '; } list += '

    '; // generate a tree for child elements of this record var child_lists = []; for(var i = 0, c = tree.children.length; i < c; i++) child_lists.push(constructRecordListItem(tree.children[i])); if(canHaveChildren) child_lists.push('
  • ' + NEW_ROW); if(!tree.root) list += '