Skip to content

Commit

Permalink
Working Save with Raptor Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
joewashear007 committed Jan 7, 2014
1 parent abd4ad1 commit 61e40fa
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 79 deletions.
32 changes: 19 additions & 13 deletions Controller/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,36 @@ class ArticlesController extends AppController {

public function edit($id = null) {
$this->layout = 'ajax';

Debugger::log("The ID: ".$id);
if (!$id) {
$this->set('success', "<strong>FAIL!</strong> The article you tried to save was invalid");
$this->set('success', false);
return;
//throw new NotFoundException(__('Invalid post'));
}

$Article = $this->Article->findById($id);

if (!$Article) {
$this->set('success', "<strong>FAIL!</strong> The article you tried to save was invalid");
Debugger::log("The Article Loaded: NOT ");
$this->set('success', false);
return;
//throw new NotFoundException(__('Invalid post'));
}

if ($this->request->is(array('post', 'put'))) {
Debugger::log("Request Type: ".$this->request->method());
//if ($this->request->is('post') or $this->request->is('put')) {
if (!$this->request->is('get')) {
Debugger::log("Request Type: POST OR PUT");
$this->Article->id = $id;
Debugger::log("Article ID: ".$id);
if ($this->Article->save($this->request->data)) {
$this->set('success', "<strong>SUCCES!</strong> All your changes are saved!");
$this->Session->setFlash(__('Your post has been updated.'));
Debugger::log("Save: Success");
$this->set('success', true);
return;
//return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Unable to update your post.'));
$this->set('success', "<strong>FAIL!</strong> Unable to save your article!");
}else{
Debugger::log("Save: FAIL!");
$this->set('success', false);
}
}else{
Debugger::log("Request Type: must be GET");
$this->set('success', false);
}
}
public function delete($id) {
Expand Down
3 changes: 2 additions & 1 deletion View/Articles/edit.ctp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php
echo $success;
//print_r( $this->getVars());
echo json_encode($success);
?>
10 changes: 6 additions & 4 deletions View/Elements/MainMenu.ctp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<div id="msgbox" class="navbar navbar-inverse">
<div id="msgbox-text" ></div>
<a id="msgbox-close" >X</a>
</div>


<?php
$sections = $this->requestAction('sections/index/');

Expand Down Expand Up @@ -35,10 +41,6 @@ $this->Js->get('#msgbox-close')->event('click', $event);

</div>

<div id="msgbox" class="navbar navbar-inverse">
<div id="msgbox-text" ></div>
<a id="msgbox-close" >X</a>
</div>



Expand Down
6 changes: 4 additions & 2 deletions View/Layouts/siteeng.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@

?>
<script type="text/javascript">
raptor(function($){
/* raptor(function($){
$('.editable').raptor({
plugins:{
dock:{docked:true},
classMenu:{classes:{'Blue background':'cms-blue-bg','Round corners':'cms-round-corners','Indent and center':'cms-indent-center'}},
snippetMenu:{snippets:{'Grey Box':'<div class="grey-box"><h1>Grey Box</h1><ul><li>This is a list</li></ul></div>'}}
}
});
});</script>
*/
//});
</script>
</head>
<body>

Expand Down
166 changes: 107 additions & 59 deletions webroot/js/siteeng.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,57 @@ raptor(function($){
$('.editable').raptor({
//preset : "full
unloadWarning: false,
autoEnable : true,
autoEnable : false,
disabledPlugins: [
"statistics","hrCreate","textBlockQuote","insertFile","embed","logo","languageMenu","specialCharacters","dockToElement",
"textStrike", "textSub","textSuper","tagMenu","guides", "save", "unsavedEditWarning"],
"textStrike", "textSub","textSuper","tagMenu","guides", ],
//"textStrike", "textSub","textSuper","tagMenu","guides", "save", "unsavedEditWarning" ],
plugins:{
dock:{docked:true},
classMenu:{classes:{'Blue background':'cms-blue-bg','Round corners':'cms-round-corners','Indent and center':'cms-indent-center'}},
snippetMenu:{snippets:{'Grey Box':'<div class="grey-box"><h1>Grey Box</h1><ul><li>This is a list</li></ul></div>'}}
classMenu:{
classes:{
'Blue background':'cms-blue-bg',
'Round corners':'cms-round-corners',
'Indent and center':'cms-indent-center'
}
},
snippetMenu:{
snippets:{
'Grey Box':'<div class="grey-box"><h1>Grey Box</h1><ul><li>This is a list</li></ul></div>'
}
},
save: {
// Specifies the UI to call the saveRest plugin to do the actual saving
plugin: 'saveRest'
},
saveRest: {
// The URI to send the content to
url: function(html){
var cid = this.raptor.element.context.id.split("-");
return SiteEng.ArticleEdit + "/" + cid[1];
},
// Returns an object containing the data to send to the server
data: function(html) {
return GetSaveData(this.raptor.element.context.id);
},
},
},
});
});

$(document).ready(function() {
$(".editable").focusout(function() {
Save($(this).attr(id));
})
});
// $(document).ready(function() {
// $(".editable").focusout(function() {
// Save($(this).attr("id"));
// })
// });

function Save(editableId){
function GetSaveData(editableId){
var idInfo = editableId.split("-");
var id = idInfo[1];
if(idInfo[0] == "section"){
var data = JSON.parse(SiteEng.SectionsFields);
var action = SiteEng.SectionEdit;
}else{
var data = JSON.parse(SiteEng.ArticleFields);
var action = SiteEng.ArticleEdit;
}
//Get The JSON object and replace the id with the id number
//Do JQuery text with the object id
Expand All @@ -42,55 +66,79 @@ function Save(editableId){
}
}
}
var request = jQuery.ajax({
url: action + "/" +id,
type: "post",
data: jQuery.param(data),
}).done(function(data) {
jQuery("#msgbox-text").html(data);
jQuery("#msgbox").removeClass().addClass("alert alert-success");
jQuery("#msgbox").slideDown();
}).fail(function(data) {
jQuery("#msgbox-text").html(data);
jQuery("#msgbox").removeClass().addClass("alert alert-danger");
jQuery("#msgbox").slideDown();
});
return data;
}
// function Save(editableId){
// var idInfo = editableId.split("-");
// var id = idInfo[1];
// if(idInfo[0] == "section"){
// var data = JSON.parse(SiteEng.SectionsFields);
// var action = SiteEng.SectionEdit;
// }else{
// var data = JSON.parse(SiteEng.ArticleFields);
// var action = SiteEng.ArticleEdit;
// }
// //Get The JSON object and replace the id with the id number
// //Do JQuery text with the object id
// for (var key in data) {
// if (data.hasOwnProperty(key)) {
// if(key == "id"){
// data[key] = id;
// }else{
// var idstr = data[key].replace("id", id);
// data[key] = jQuery("#" + idstr).html();
// }
// }
// }
// var request = jQuery.ajax({
// url: action + "/" +id,
// type: "post",
// data: jQuery.param(data),
// }).done(function(data) {
// jQuery("#msgbox-text").html(data);
// jQuery("#msgbox").removeClass().addClass("alert alert-success");
// jQuery("#msgbox").slideDown();
// }).fail(function(data) {
// jQuery("#msgbox-text").html(data);
// jQuery("#msgbox").removeClass().addClass("alert alert-danger");
// jQuery("#msgbox").slideDown();
// });
// }

jQuery(document).ready(function(){
jQuery(".delete").click( function() {
var data = jQuery(this).attr('id').split('-');
var request = jQuery.ajax({
url: window.app.articleDelete+ "/" + data[1],
type: "post",
}).done(function(data) {
jQuery(data[0]+"-"+data[1]).Remove();
jQuery("#msgbox-text").html(data);
jQuery("#msgbox").removeClass().addClass("alert alert-success");
jQuery("#msgbox").slideDown();
}).fail(function(data) {
jQuery("#msgbox-text").html(data);
jQuery("#msgbox").removeClass().addClass("alert alert-danger");
jQuery("#msgbox").slideDown();
});
});
jQuery(".add").click( function() {
var data = jQuery(this).attr('id').split('-');
var request = jQuery.ajax({
url: window.app.articleDelete+ "/" + data[1],
type: "post",
}).done(function(data) {
jQuery(data[0]+"-"+data[1]).Remove();
jQuery("#msgbox-text").html(data);
jQuery("#msgbox").removeClass().addClass("alert alert-success");
jQuery("#msgbox").slideDown();
}).fail(function(data) {
jQuery("#msgbox-text").html(data);
jQuery("#msgbox").removeClass().addClass("alert alert-danger");
jQuery("#msgbox").slideDown();
});
});
// jQuery(document).ready(function(){
// jQuery(".delete").click( function() {
// var data = jQuery(this).attr('id').split('-');
// var request = jQuery.ajax({
// url: window.app.articleDelete+ "/" + data[1],
// type: "post",
// }).done(function(data) {
// jQuery(data[0]+"-"+data[1]).Remove();
// jQuery("#msgbox-text").html(data);
// jQuery("#msgbox").removeClass().addClass("alert alert-success");
// jQuery("#msgbox").slideDown();
// }).fail(function(data) {
// jQuery("#msgbox-text").html(data);
// jQuery("#msgbox").removeClass().addClass("alert alert-danger");
// jQuery("#msgbox").slideDown();
// });
// });
// jQuery(".add").click( function() {
// var data = jQuery(this).attr('id').split('-');
// var request = jQuery.ajax({
// url: window.app.articleDelete+ "/" + data[1],
// type: "post",
// }).done(function(data) {
// jQuery(data[0]+"-"+data[1]).Remove();
// jQuery("#msgbox-text").html(data);
// jQuery("#msgbox").removeClass().addClass("alert alert-success");
// jQuery("#msgbox").slideDown();
// }).fail(function(data) {
// jQuery("#msgbox-text").html(data);
// jQuery("#msgbox").removeClass().addClass("alert alert-danger");
// jQuery("#msgbox").slideDown();
// });
// });


});
// });

0 comments on commit 61e40fa

Please sign in to comment.