Jump to content

Peter Falkenberg Brown

Members
  • Posts

    347
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Peter Falkenberg Brown

  1. Thank you, @kongondo, @bernhard, and @dotnetic! Yes, this is why the PW community ROCKS. I'll test these out soon. Thanks again! Peter
  2. Hi @kongondo, This is so cool. Thank you VERY much. It works perfectly. I'm wondering what the best way to load it under certain conditions would be. Right now, it places the cursor in the field whenever I go into edit mode, not just on the initial edit that comes right after adding a record. In my ready.php file I have this: $this->addHookBefore('AdminTheme::getExtraMarkup', function (HookEvent $event) { $config = $this->wire->config; $url = $config->urls->templates; $config->scripts->add($url . "scripts/admin.js"); }); $pages->addHook('added', function(HookEvent $event) { $page = $event->arguments(0); if ( $page->template == 'book_sales' ) { .... etc.... So, in the code that comes after the addHook('added') it only operates in the subsequent edit screen, but not when I go back to a record and click on edit. (At least I don't think so.) Is there a way to only initiate the cursor focus during that initial edit? Thank you again! Peter
  3. Thank you, @kongondo! It's a field called "list_price." It's a field of type float. It's in a template called "book_sales." See my ready.php code at the beginning of the thread for what I'm doing with adding values to fields, on a new add record routine. Thanks again for your help! Peter
  4. Yes, it should always get the focus when it goes from adding a new record to the edit page of the new record. At other times, it doesn't matter, either way. Any JS gurus want to demonstrate the code and where / how to put it? I'm not a JS person. :-) Thanks! Peter
  5. Thanks, @dotnetic and @MarkE... And thanks, @bernhard, in advance. :-) Peter
  6. Thanks, @kongondo... In the PW admin, when you click on "New" to add a record, the title field has focus, with the cursor in it. However, when you then hit save and get to the edit page, none of the fields have focus. These pages are part of the built in admin, so I'm wondering if they can be tweaked without editing the core files. Based on your description, it would seem that the New record page must have some type of focus mechanism, either with Javascript or HTML. What are your thoughts? Thanks! Peter
  7. Hi All, I'm using ready.php to add some values to new pages, so that after I type in the title of the page and hit save, when I get to the edit page of the full set of fields, certain fields have pre-filled values. The routine is working well, but I want to add one more item, to wit: - I want to set the field focus (i.e. the cursor is in that field) to a field called "list_price." Can that be done, in ready.php, and if so, what's the best method? Here's the code I have already: $pages->addHook('added', function(HookEvent $event) { $page = $event->arguments(0); if ( $page->template == 'book_sales' ) { #............................................. $parent = $page->parent(); $parent_path = $parent->path(); $last_item_number_selectors = "parent=$parent_path," . "sort=-item_number," . "$skiptrash," . "limit=1"; $last_item_number = wire("pages")->get("$last_item_number_selectors")->item_number; # the item_number has a 2 letter prefix, followed by 4 digits that have leading zeroes, # and the number has to be incremented, while retaining the leading zeroes. $part1 = substr($last_item_number,0,2); $part2 = substr($last_item_number,2); $part2inc = intval($part2) + 1; $part2new = sprintf('%04d', $part2inc); $new_item_number = $part1 . $part2new; $page->item_number = $new_item_number; #............................................. $admin_now = time(); $page->list_date = wire(datetime)->date($format='Y-m-d', $admin_now); $page->list_year = wire(datetime)->date($format='Y', $admin_now); #............................................. $page->of(false); $page->save(); $page->of(true); } }); Thanks! Peter
  8. Thanks, @BitPoet! That worked perfectly. It's always the little things. :-) Peter
  9. Thanks, @AndZyk, But adding the single quote marks didn't work. I still get this error message: Fatal Error: Uncaught Error: Call to a member function date() on null in site/ready.php:12 #0 wire/core/WireHooks.php (1050): ProcessWire->{closure}(Object(HookEvent)) #1 wire/core/Wire.php (485): WireHooks->runHooks(Object(Pages), 'saveReady', Array) #2 wire/core/PagesEditor.php (491): Wire->__call('saveReady', Array) #3 wire/core/PagesEditor.php (455): PagesEditor->savePageQuery(Object(Page), Array) #4 wire/core/Pages.php (799): PagesEditor->save(Object(Page), Array) #5 wire/core/Wire.php (420): Pages->___save(Object(Page), Array) #6 wire/core/WireHooks.php (951): Wire->_callMethod('___save', Array) #7 wire/core/Wire.php (485): WireHooks (line 12 of site/ready.php) Peter
  10. Hi All, Maybe because my brain is fried tonight, but I'm totally stuck on extracting the 4 digit year from a datetime field inside the ready.php file, on saving a page. Here's my code: $pages->addHook('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if ( $page->template == 'book_sales' ) { if ( $page->sold == 1 ) { $page->profit = ($page->sale_price - $page->buy_cost) - $page->transaction_fee; $page->sale_year = $datetime->date($format='Y', $page->getUnformatted(sale_date)); } } }); The line that tries to get the sale_year, i.e. $page->sale_year = $datetime->date($format='Y', $page->getUnformatted(sale_date)); breaks with a bunch of errors. Anyone have the right syntax? Thanks! Peter
  11. Hi @dotnetic, That is BEYOND COOL. One more reason why all of the other "CMS's" should bow down to ProcessWire! Thank you! I shall use it. Best regards, Peter
  12. Hi @dotnetic, (An aside: I created a spreadsheet that does all of this very quickly. Easy as pie. However, in some cases, a PW database might be better, thus my questions. On the other hand, maybe trying to fit PW with the functionality of spreadsheets is a waste of time. You know... the right tool for the job.) Yes, the PagesSum module is exactly what I need. Thank you! But... in the Admin section, with the standard tree of page types (i.e. templates), assuming that I have a branch of pages called "sales," then where and how could I display the sum of those sales pages (from a field called "sale_price") on the admin page? I haven't adequately dug into the task of modifying the admin page. In a custom app, all based on php template docs, I would simply display that total on the apps version of the "home" page, i.e. like the Admin tree page. But in the PW Admin page, I haven't yet learned how to add a routine to display something like that on the top level admin page. Is there a document somewhere in the PW knowledge base on how to do that? I've already made one small modification to the admin's core files in the wire directory, in a file called "AdminTheme.php." In that file, in the routine public function ___getExtraMarkup() I change this code: if($isLoggedin && $this->wire('config')->advanced) { # $parts['footer'] = "<p class='AdvancedMode'><i class='fa fa-flask'></i> " . $this->_('Advanced Mode') . "</p>"; $parts['footer'] = str_repeat('&nbsp;', 10) . "DB: " . wire('config')->dbName . "<br><br>"; } ... so that the admin page would display the name of the database in use (to avoid a dev version using the live db by mistake). ( @ryan Ryan, I think this would be a good addition to the core.) I realize that it's a Bad Idea to modify core files, so in terms of modifications to the admin home/tree page, with the Sum function display, I'm hoping that there's a hook method, or some other way to get that data displayed on the page, without messing with the core files. Thanks! Peter
  13. Hi All, I haven't found this answer in the docs or forums. I know how to program a template that would display multi-page field calculations like a spreadsheet, e.g. with 100 pages, each with a dollar value in a field, display the total dollar value of a subset of the 100 pages based on a "sold" data field value. I know how to put that template / url / page behind a password. What I'm not clear about is whether or not PW has an easier method than that. For example, in the standard admin, create a page/template that has the summary fields in it and pull the calculations from the "item" pages whenever the summary page is accessed or a button is pressed. Or something like that. So that the calculations can be viewed in the admin without having to build a password protected, programmed front-end page. Of course, a spreadsheet can do all this easily, but after thousands of records, it becomes rather unwieldy, in my opinion. What do people recommend? Thanks, Peter
  14. Hi Ryan, When I read about the combo field, it almost seems like a jury-rigged version of a standard MySQL data table with column definitions. When I first came to ProcessWire, I had to get used to its splitting of the fields into separate tables. I'm not an expert DBA kind of person on advanced MySQL queries and indexing and things like complex join SQL statements, but how would you compare the traditional SQL approach of complex queries to both the standard ProcessWire method and the new Combo fields? My question might be too broad; not sure. Peter
  15. Thanks, @jonatan... The solutions above worked perfectly. Because I already had ready.php code to set the name field to the ID, all I had to do was set the allowed template for children to "item" and then set the Name format for children to "Y-m-d-H-i-s." Voilà! Thanks again! Ain't ProcessWire Grand? Peter
  16. Thanks, @jonatan! If I put "id" in that field instead of title, will it automatically skip the name/title page and create the name based on the id? I should have specified more clearly: I want to skip that initial page completely and end up on the edit page, with the name field automatically filled in with the auto-increment ID. Thanks again, Peter
  17. Hi All, I thought I saw that a feature had been developed that allowed one to click "New" to add a new child page, and skip the name field page, and go directly to the edit page, with the name field already having the ID as the value. If that hasn't been developed, is there a way to do that? I've been scouring my posts and searching the forum because I know that I got advice from someone to set the name field to the ID using ready.php, using this code: $pages->addHookAfter('added', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'item') { $page->setAndSave([ 'name' => $page->id, ]); } }); ... but I can't find the darn post in the forum. (I'm using the code above.) My client wants to skip the step where he has to add a fake name value (like 'n') which then gets overwritten by the ID, using the code above. Thanks! Peter
  18. Hi Folks, I am stuck, after scouring the API docs, module code, and forum questions. I'm trying to write code that upon the initial pressing of a search button will set the page number to something other than 1. For example, the query might return 50 pages, but I want to start by showing page 7, with the pagination boxes appearing on both sides of the highlighted box 7. Here's my code (setPageNum will only be used if it's an initial search button press (which I'll check with a hidden form field)). $results = $pages->find("$select_limit"); $pager = $modules->get('MarkupPagerNav'); $pager->setNumPageLinks($numPageLinks); $pager->setPageNum(7); $pagination = $pager->render($results); The returned pagination all looks good EXCEPT that it always starts at page 1 instead of page 7, like this: Any help would be greatly appreciated. Peter
  19. Back in 2005/6, I built a SSG/CMS combination application, based on a Perl Framework that I had written. The magazines' editors input their stories via a CMS login, and then, when they were done, they clicked a button that sent a special secure command to the server to run a script that generated all of the pages as static HTML files. It generated thousands of pages blazingly quickly. Having done that, I think ProcessWire with ProCache accomplishes the same thing, since it also writes HTML files. But... ProcessWire is SO much better than my application ever was, for so many reasons. ProcessWire with ProCache gives us the best of both worlds. Peter
  20. You're very welcome, @szabesz! (and thank you!) This thread started with my how-to questions about image migration. Besides the modules that @adrian and @kongondo mentioned, I didn't find any clear documentation about how to deal with image migration with comprehensive detail (I might have missed finding it). Of course, I read a number of pages about image scripting, but I didn't see info that covered all the bases. Adrian expressed skepticism about the stability of the module Kongondo mentioned, and Adrian's module didn't fit my specific needs, so I didn't use either of those modules, and decided to proceed with my own script. But my script didn't deal with cropped images (because I didn't have any), unless they're automatically brought over by the copy command I ran to bring in any image variations. Thus, my script might have missed some important things with images. I'm not sure. I'd love to see a how-to on this very topic, i.e. a comprehensive write-up of how to migrate images and catch every detail. My efforts were a "roll-your-own" attempt to do it, and it worked for me. But I have no confidence that I covered all the details of image migration. If I did, I'd love to hear about it. ? Peter
  21. Hi All, I've added routines to the script to create a file of hrefs in the body field, and also a file of 301 redirects for an .htaccess file. There are so many edge cases with internal hrefs that I decided to edit them by hand, based on the list created. (For example, an href that links to a second internal PW page on the target domain that PW's url system on the source domain doesn't know about.) I also moved the chown command to include pages that didn't have images, because the file dir has to be owned by the domain and running the script as root ends up making the file dir owned by root. Again, I realize that this script may only serve a very small group of people who need to do exactly what I needed it for: to migrate many sections of pages from one PW domain to another PW domain that had a different section structure. I've successfully and quickly moved many sections and pages as of now, so I'm confident that the script is doing what I needed. If someone else finds it useful, that's grand. ? Here it is, below. Click the "reveal hidden contents" icon below to see it. Peter
  22. Hi @szabesz, Good idea... I deleted the 1st version of the script and put the second one in a spoiler. I couldn't figure out how to delete an empty spoiler or code block. Do you know how? Edit: I figured it out: just go below the empty box and hit the backspace key until it's gone. ? Thanks again, Peter
×
×
  • Create New...