Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » New Stuff!

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 3289 Views
  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: New Stuff! Link to this post

    So seeing how you got this working made me look into a bit more and see a few possibilities. A while ago I asked you how I could add delete confirmation on the DOM and now it is relatively straightforward.

    In my project page class I added the following code

    $projectfield->removePermission("delete");

    to turn off the main delete button. I then added to the dataobject a delete function and a new DataObjectManagerAction

    public function confirmDelete()
    {
    if($this)
    $this->delete();
    else
    {
           }
    }

    new DataObjectManagerAction(
    'Delete Project',
    "http://synergysilverstripelatest/admin/EditForm/field/Projects/item/$this->ID/delete",
    "delete-confirm",
    "/assets/graphics/$deleteImage"
    ));


    notice I called 'delete-confirm' my new $behaviour javascript function which I placed in dataobject_manager.js

    $container.find('a.delete-link-synergy-test-edit').unbind('click').click(function(e) {
             alert('this works cause its wills test');
             var answer = confirm('Do you want to delete this?');
             if (answer){
             alert("You deleted it!");
             params = $('#SecurityID') ? {'forceajax' : '1', 'SecurityID' : $('#SecurityID').attr('value')} : {'forceajax' : '1'};
             $target = $(this);
             $.post(
                $target.attr('href'),
                params,
                function() {$($target).parents('li:first').fadeOut();$(".ajax-loader").fadeOut("fast");}
             );
             e.stopPropagation();
             return false;
             }
             else
             {
                alert("Thanks for sticking around!");
                return false;
             }
          });


    where I just copied your delete function and added a confirm function in there. At the moment I just edited the dataobject_manager.js which works but is obviously a bad way to do it as it will be deleted come upgrade time.

    I tried creating a new class called WillsDataObjectManagerAction.php which wasn't too big as it just had the DataObjectManagerAction in it but it had to call a new copy of dataobject_manager.js called willsdataobject_manager.js which worked too but I am wondering is this a bad way to do it cause it's a big js file and if I keep using my copy of it's current state it will gradually get more out of date. Is it better to do this or just edit the main js file every upgrade. How much is the js file likely to change I guess I'm asking as well. Thanks. Hope this helps someone.

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: New Stuff! Link to this post

    any thoughts on the best way to seperate my js so that it will still fit in with future versions of DOM?

  • UncleCheese
    Avatar
    4085 Posts

    Re: New Stuff! Link to this post

    I think I'm going to roll in the confirm delete feature. I just hate using javascript alert windows. I was hoping to come up with something a little more graceful.

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: New Stuff! Link to this post

    In dataobjectmanager when I hit any of the icons which refresh the page using AJAX, they are calling the frontend theme css. I couldn't understand it for a while but then I thought about it and realised the way you recommended to add a a new DataObjectManagerAction links to the ExamplePage_Controller where as it is an extension of Page_Controller the frontend CSS is called. While everything still works it makes my CMS look super ugly. I guess I could hack my frontend CSS a lot so it doesn't effect the CMS but this seems like a big job. Is there anyway of staying within the admin section so the front end CSS isn't called at all?

    Thanks

    Will

  • UncleCheese
    Avatar
    4085 Posts

    Re: New Stuff! Link to this post

    Nooooo... you should not be using a Page_Controller subclass. Just "Controller."

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: New Stuff! Link to this post

    Ummm you used ListingPage_Controller and you call "/ListingPage_Controller/approve/$this->ID" ?

    Can I have for my example

    class Project_Controller extends Controller to hold the new functions

    as well as the classes I already have to hold the data details and page functions

    class ProjectPage extends Page
    class ProjectPage_Controller extends Page_Controller

  • UncleCheese
    Avatar
    4085 Posts

    Re: New Stuff! Link to this post

    Whoops. You're right. That's a typo. That should read "Listing_Controller". You can put it in the same file as your DataObject class -- e.g. Listing.php contains Listing extends DataObject as well as Listing_Controller extends Controller.

    Hope that helps.

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: New Stuff! Link to this post

    Yes. awesome. thanks again.

    3289 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.