One Editable Space - Not Unlimited

Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
I have made it so an editor controls the space on top of this page http://kenrich.me/sales

However, it is able to make unlimited additional "posts" for lack of a better term.

I would like it to operate like the profile index page where there is only one editable space not the ability to create endless ones that all become listed.

How can this be accomplished?


--

Ken Rich
indiegospel.net

updated by @ken-rich: 07/05/16 09:06:00PM
michael
@michael
8 years ago
7,717 posts
You're building modules now, need to get into the habit of explaining what you have done in order to get help going forward. ;)

We have no point of reference. How did you 'made and editor that controls a space'?
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Ah... Well I simply added an editor to the existing form that came default with the module created by Aparna.

Since the module I created was called Sales, I called the editor I added to the form sales_editor and in the item detail and list templates I added:

{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}

I stripped away everything else that seemed to be superfluous in those templates since things I didn't want were showing up by default.

Perhaps this issue is as simple as only having modify, not create, in the editor section of the form? But then how would the initial custom space be created? The profile owner can't modify what is not there?

Unless a default blank space can be created for them to modify? Then the create functionality could be deactivated on the form. Then like the profile editor, they would then only have a cogwheel for modify, not a plus button to make more entries that become listed.

I suspect the answer is along those lines, but how to implement so they have a default space to modify is what I don't know how to implement.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 03/27/16 06:27:23AM
michael
@michael
8 years ago
7,717 posts
perfect explanation up til "I stripped away everything else that seemed to be superfluous in those templates since things I didn't want were showing up by default."

after that its thinking to your self. Try :

EXPECTED:
When I viewed the form I expected to see ...............

ACTUAL:
But what I saw instead was .......................

So I can understand what the goal is. Then we can work together to try ideas to get to the goal. :) still not understanding the issue sorry.
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
OK - perhaps this will help. Refer to the attached screenshot.

I expected to see an editor output like that of the profile builder but instead got that.

So that's what I mean by displaying a bunch of things I didn't want.

So I stripped the item detail down to:

{jrCore_module_url module="xxSales" assign="murl"}             
                        <div class="container">  
                           {if strlen($item.sales_editor) > 0}     
{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
{/if}                    
                </div>

Moreover, I changed the item_list.tpl to this:

{jrCore_module_url module="xxSales" assign="murl"}
{if isset($_items)}
    {foreach from=$_items item="item"}
        <div class="item">
            <div class="block_config">
              {jrCore_item_list_buttons module="xxSales" item=$item}              
            </div>
{if strlen($item.sales_editor) > 0}     
{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
           {/if} 
            <br></div>
    {/foreach}
{/if}


In the item_index.tml I believe this section is responsible for the display:

   <div class="block_content">
{jrCore_list module="xxSales" profile_id=$_profile_id order_by="_created asc" pagebreak="4" page=$_post.p pager=true}

</div>

Now this is working out fine for me except that I only want one editable space on the top of the Sales page (like the profile_index functions), but this set-up creates unlimited editable spaces.

I am thinking that perhaps I need to shut off the create function in the sales_editor and just use modify. However, then I don't know how the initial space can be created.
sales.JPG.jpg
sales.JPG.jpg  •  37KB




--

Ken Rich
indiegospel.net

updated by @ken-rich: 03/27/16 12:24:30PM
michael
@michael
8 years ago
7,717 posts
Think you're meaning you want to show the $item.sales_editor for just the first item in the list.

If that's right then lets look at what's happening.

You have a {foreach} loop that displays that section for as many times as there are items in the array that you're looping over. You don't want that, you want to have a different layout for the first section.

What you can do is add a counter in there that gets counted for each iteration over the loop. Its a common technique.

A loop:
    {foreach from=$_items item="item"}
       // do stuff
    {/foreach}

A loop with an iterator:
{$i = 0}
    {foreach from=$_items item="item"}
       // do stuff
       {$i = $i+1}
    {/foreach}

Then you can use that iterator to only show some stuff for the first or X section.


{$i = 0}
    {foreach from=$_items item="item"}
       // do stuff
       {if $i == 0} 
           // do stuff just for the first time in the loop.
       {/if}
       {$i = $i+1}
    {/foreach}
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Hmmm... This is new to me - will have to study and experiment - thanks.

However, I am not exactly interested in DISPLAYING only one editor output (if multiple ones can be created , stored, or are available on detail pages).

I'm really interested in limiting the CREATION to just one, not in allowing the creation of many but the DISPLAY of just one.

I'm not sure if your loop solution addresses that.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 03/27/16 12:57:01PM
michael
@michael
8 years ago
7,717 posts
That's not 'my loop solution' its yours from your item_list.tpl
Quote:
Moreover, I changed the item_list.tpl to this:
{jrCore_module_url module="xxSales" assign="murl"}
{if isset($_items)}
    {foreach from=$_items item="item"}


              {jrCore_item_list_buttons module="xxSales" item=$item}              


{if strlen($item.sales_editor) > 0}     
{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
           {/if} 


    {/foreach}
{/if}

Have a feeling I'm still not understanding what you're trying to accomplish.
updated by @michael: 03/27/16 03:51:00PM
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Ah - I changed the inner part of that
{if strlen($item.sales_editor) > 0}     
{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
           {/if} 

The rest was already there and I don't know enough about code to change it. If that is causing my unwanted loop perhaps that is what needs to be changed.

What I am trying to accomplish is simple. I want the sales page to have an editable space on top just like the profile_index on the Ningja skin does.

I'm going to do an experiment with deactivating sales_editor for create and just have it for modify. Perhaps that's the problem.

I just checked and that seems to be how it is being done for the profile_index editor though I can't understand how the initial space is created.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 03/27/16 04:35:57PM
michael
@michael
8 years ago
7,717 posts
Ah, this is the part I was not understanding 'to have an editable space on top just like the profile_index on the Ningja'

You're wanting to have only a single item be able to be created.

There are a couple of ways to do it, I would probably go with adding that editor to add the top of the sales page content to the profile update screen rather than the module itself.

Then output that in the sales modules
/modules/xxSales/templates/item_index.tpl

the same way the /skins/jrNingja/profile_index.tpl does it:

        {* If the Profile creates a "SALES HEADER" it will show here *}
        {if strlen($profile_sales_header) > 1}
        <div class="row">
            <div class="col12 last">
                <div class="block">
                    <div class="block_content">
                        <div class="item" style="margin-top:0">
                            {$profile_sales_header|jrCore_format_string:$profile_quota_id}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {/if}


Then under that list the jrCore_list that you want to list. Your module will not need an item_detail.tpl as it doesnt allow for creation as far as I can understand. Wont need an item_list.tpl either for the same reason.
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
michael:
I would probably go with adding that editor to add the top of the sales page content to the profile update screen rather than the module itself.

Can you elaborate on that statement as I am not understanding.

1) I don't know what you mean by the "profile update screen". Do you mean in the form designer?

2) The editor is currently added to the form as sales_editor and active for both create and update. I'm thinking it should perhaps be active for update only.

3) I don't know where you are getting "$profile_sales_header". I gave the editor I added to the form designer the name "sales_editor", so shouldn't that be used? Is that what you are referring to by a different name?

3) I initially tried copying the Ningja profile_index in a similar manner as what you are suggesting but couldn't get it to work, probably because I was missing something. I think I tried it like this in item_index.tpl

{* If the member edits the page it will show here *}
        {if strlen($sales_editor) > 1}
               <div class="row" style="margin-top:0;important!">
            <div class="col12 last" style="margin-top:0;important!">
                <div class="block" style="margin-top:0;important!">
                    <div class="block_content" style="margin-top:0;important!">
                        <div class="item" style="margin-top:0;important!">
                            {$sales_editor|jrCore_format_string:$profile_quota_id}
              
                </div>
            </div>
        </div>
        {/if}
                </div>
            </div>



--

Ken Rich
indiegospel.net
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
OK - I tried that above again and still couldn't get it to work (nothing showed). Then I tried this in the item_index.tpl and it didn't work either.

{if strlen($item.sales_editor) > 0}     
{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
           {/if}

I also tried deactivating the create function but as I suspected I was then not able to make an initial entry.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 03/27/16 07:45:29PM
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
michael:
Ah, this is the part I was not understanding 'to have an editable space on top just like the profile_index on the Ningja'
You're wanting to have only a single item be able to be created.
There are a couple of ways to do it, I would probably go with adding that editor to add the top of the sales page content to the profile update screen rather than the module itself.

Can you please tell me where to find the profile update screen as I don't know what you are referring to.


--

Ken Rich
indiegospel.net
michael
@michael
8 years ago
7,717 posts
Sure, its at:
YOUR-SITE.com/profile/settings

You can get there via clicking on the gear icon on your profile. Then you can add an editor field to there via the Form Designer.

That will then be available on all pages in that profile, so you can use it ahead of the jrCore_list function call you have on your xxSales module.

Modules that have datastores expect multiple items to be able to be added, so if you only want it once per profile sales page, then the profile update form seams a good place to put it.
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Ah... I see... I didn't know that stuff was available to all parts of the profile - cool.

I think I can get that to work, the only downside is another potentially confusing editor on the main profile form (my free members don't even have Foxycart sales).

I think I've stumbled across another possible solution. I've discovered (by trial and error) that the create button is on the item_index.tpl page as:

{jrCore_item_index_buttons module="xxSales" profile_id=$_profile_id}

So I'm thinking if I can simply come up with an IF statement to show the button ONLY when there is no item already created in the datastore, then only one can be created. Unless the current one is deleted then the button should show again - allowing a new one to be created.

So I've done HOURS AND HOURS of experiments with statements like:

{if empty($_items)}
{jrCore_item_index_buttons module="xxSales" profile_id=$_profile_id}
{/if}

Some of my experimental statements break the page, some remove the create button on profiles that have an item created (but also on those which do not). Some don't remove it on either.

After literally dozens of attempts, I have been unable to find one that will only show the create button if the datastore is empty. I don't know if I should be trying ID, post, item or what - nothing seems to work.

What would you suggest? Can such a statement be crafted or am I "barking up the wrong tree"?


--

Ken Rich
indiegospel.net

updated by @ken-rich: 03/30/16 09:23:12AM