00001 <?php
00002
00011 class TKSnapXmlEditor extends TKSnapEditor {
00021 protected function showEditor($cm, $failed) {
00022 if($failed)
00023 $content = $_REQUEST['editor'];
00024 else
00025 $content = $cm->getHTML();
00026 if(preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']))
00027 $whitespace = '';
00028 else
00029 $whitespace = 'whitespace: nowrap;';
00030
00031 $html = "
00032 <form action=\"$_SERVER[REQUEST_URI]\" method=\"post\">
00033 <div style=\"text-align: center\">
00034 <textarea name=\"editor\" style=\"${whitespace}overflow: auto;\" rows=\"10\" cols=\"80\">" . htmlentities($content) . "</textarea><br />
00035 <input type=\"submit\" name=\"snap2ed_save\" value=\"Save\" />
00036 <input type=\"submit\" name=\"snap2ed_saveAndExit\" value=\"Save and Exit\" />
00037 <input type=\"submit\" name=\"snap2ed_exit\" value=\"Exit without Saving\" />
00038 </div>
00039 </form>
00040 <br />";
00041 $this->addText($html);
00042
00043 $js = <<<END_JAVASCRIPT
00044 SWAT.use('Component');
00045 SWAT.use('ResourceBrowserCompact');
00046
00047 function initBrowserContainer() {
00048 var browserContainer = new Element('div', { style: 'position:fixed;top:60px;right:20px' });
00049 var bcInner = new Element('div', { className: 'rbSNAP2' });
00050
00051 var linkTag = new Element('input', { type: 'text', size: 30 });
00052
00053 var linkTag = new Element('input', { type: 'text', size: 30 });
00054 var rb = new CompactBrowser({
00055 project: 'Interactivate',
00056 categories: { 'Subject': 'Primary_Subject', 'Resource Type': 'Interactivate_Type' },
00057 order: [ 'Resource Type', 'Subject' ],
00058 selectHandler: function(id) { linkTag.writeAttribute('value', '<link metaid="' + id + '">'); }
00059 });
00060 bcInner.insert(rb);
00061
00062 var alLinkDiv = new Element('div', { style: 'border: 1px solid black; padding: 3px; background: #EFEFEF' });
00063 alLinkDiv.insert('<h3>Resource Browser</h3>');
00064 var alBut = new Element('button', { type: 'button' }).update('Show Browser');
00065 alLinkDiv.insert(alBut);
00066 alLinkDiv.insert(linkTag);
00067 alBut.observe('click', function() {
00068 if(bcInner.visible()) {
00069 bcInner.hide();
00070 alBut.update('Show Browser');
00071 }
00072 else {
00073 bcInner.show();
00074 alBut.update('Hide Browser');
00075 }
00076 });
00077 browserContainer.insert(alLinkDiv);
00078 browserContainer.insert(bcInner);
00079
00080 bcInner.hide();
00081
00082 $$('body')[0].insert(browserContainer);
00083 }
00084
00085 END_JAVASCRIPT;
00086
00087 global $prm;
00088 $prm->setOption('swatjs', true);
00089 $prm->loadJS($js);
00090 $prm->loadJS('initBrowserContainer()', 'OnLoad');
00091 }
00092
00101 protected function processSave($oldCM) {
00102 $content = $_REQUEST['editor'];
00103
00104 $cmNew = new SnapContentXml($this->version);
00105 if(is_array($errors = $cmNew->setXML($content))) {
00106 $html = "<p><b>Error:</b> Could not save document:</p>" . SXMLHelper::formatErrors($errors, true);
00107 $this->addText($html);
00108 return false;
00109 }
00110
00111 return $cmNew;
00112 }
00113 }
00114
00115 ?>